Skip to content

Commit

Permalink
Qwack.Excel.Next (initial cut)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Mar 30, 2023
1 parent d6d6fae commit 3a88bf8
Show file tree
Hide file tree
Showing 49 changed files with 49,939 additions and 913 deletions.
19 changes: 17 additions & 2 deletions Qwack.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.87
# Visual Studio Version 17
VisualStudioVersion = 17.5.33424.131
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{754E413D-24A5-4779-8B70-FC66F040D042}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -98,6 +98,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Qwack.CLI", "clients\Qwack.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Qwack.Transport.Tests", "test\Qwack.Transport.Tests\Qwack.Transport.Tests.csproj", "{395E9B68-21B2-42CB-AE13-868726760EC3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Qwack.Excel.Next", "clients\Qwack.Excel.Next\Qwack.Excel.Next.csproj", "{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -432,6 +434,18 @@ Global
{395E9B68-21B2-42CB-AE13-868726760EC3}.Release|x64.Build.0 = Release|Any CPU
{395E9B68-21B2-42CB-AE13-868726760EC3}.Release|x86.ActiveCfg = Release|Any CPU
{395E9B68-21B2-42CB-AE13-868726760EC3}.Release|x86.Build.0 = Release|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Debug|x64.ActiveCfg = Debug|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Debug|x64.Build.0 = Debug|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Debug|x86.ActiveCfg = Debug|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Debug|x86.Build.0 = Debug|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Release|Any CPU.Build.0 = Release|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Release|x64.ActiveCfg = Release|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Release|x64.Build.0 = Release|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Release|x86.ActiveCfg = Release|Any CPU
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -465,6 +479,7 @@ Global
{B67D5804-1141-43CB-9068-F75C31621C63} = {58641E8B-8AB1-4D21-89DA-B8887907E082}
{A38D741C-56D9-40D9-AD3E-C045F4D79637} = {58641E8B-8AB1-4D21-89DA-B8887907E082}
{395E9B68-21B2-42CB-AE13-868726760EC3} = {9550BFAC-7055-4B8B-B391-BC93D2588A16}
{BAB9BC4F-3452-4A25-9F26-69C73D58AFDF} = {58641E8B-8AB1-4D21-89DA-B8887907E082}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {54AAD5D1-3F1A-43DC-80BB-2C61D8945F25}
Expand Down
1,168 changes: 1,168 additions & 0 deletions clients/Qwack.Excel.Next/Calendars.json

Large diffs are not rendered by default.

462 changes: 462 additions & 0 deletions clients/Qwack.Excel.Next/Capital/CapitalFunctions.cs

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions clients/Qwack.Excel.Next/CategoryNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Qwack.Excel
{
internal static class CategoryNames
{
internal const string Dates = "QDates";
internal const string Options = "QOpt";
internal const string Volatility = "QVol";
internal const string Interpolation = "QInterp";
internal const string Curves = "QCurves";
internal const string Instruments = "QIns";
internal const string Cubes = "QCube";
internal const string Math = "QMath";
internal const string Models = "QModels";
internal const string Risk = "QRisk";
internal const string Capital = "QCap";
}
}
122 changes: 122 additions & 0 deletions clients/Qwack.Excel.Next/ContainerStores.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Qwack.Core.Basic;
using Qwack.Dates;
using Qwack.Excel.Utils;
using Qwack.Futures;
using Qwack.Models.Models;
using Qwack.Providers.Json;
using Qwack.Utils;

namespace Qwack.Excel
{
public static class ContainerStores
{
private const string _calendarJSONFile = "Calendars.json";
private const string _futureSettingsFile = "futuresettings.json";
private const string _currenciesFile = "currencies.json";

private static object _lock = new object();
private static object _sessionLock = new object();

static ContainerStores()
{
try
{
GlobalContainer = ((IServiceCollection)new ServiceCollection())
.AddQwackLogging()
.AddCalendarsFromJson(GetCalendarFilename())
.AddFutureSettingsFromJson(GetFutureSettingsFile())
.AddCurrenciesFromJson(GetCurrenciesFilename())
.AddSingleton(typeof(IObjectStore<>), typeof(ExcelObjectStore<>))
.BuildServiceProvider();

SessionContainer = GlobalContainer.CreateScope().ServiceProvider;

SessionContainer.GetRequiredService<IFutureSettingsProvider>();

PnLAttributor = new PnLAttributor();
}
catch (Exception ex)
{
if (Directory.Exists(@"C:\Temp"))
{
File.WriteAllText($@"C:\Temp\QwackInitializationError_{DateTime.Now:yyyyMMdd_HHmmss}.txt", ex.ToString());
}
}
}

public static IServiceProvider GlobalContainer { get; internal set; }

private static IServiceProvider _sessionContainer;
public static IServiceProvider SessionContainer
{
get
{
lock (_sessionLock)
{ return _sessionContainer; }
}
set
{
lock (_sessionLock)
{
_sessionContainer = value;
}
}
}
public static ICurrencyProvider CurrencyProvider => GlobalContainer.GetRequiredService<ICurrencyProvider>();
public static ICalendarProvider CalendarProvider => GlobalContainer.GetRequiredService<ICalendarProvider>();
public static IFutureSettingsProvider FuturesProvider => GlobalContainer.GetRequiredService<IFutureSettingsProvider>();
public static ILogger GetLogger<T>() => GlobalContainer.GetRequiredService<ILoggerFactory>().CreateLogger<T>();

private static ConcurrentDictionary<Type, IFlushable> _registeredTypes = new ConcurrentDictionary<Type, IFlushable>();

public static IPnLAttributor PnLAttributor { get; set; }

private static string GetFutureSettingsFile() => Path.Combine(GetRunningDirectory(), _futureSettingsFile);

private static string GetRunningDirectory()
{
var codeBaseUrl = new Uri(Assembly.GetExecutingAssembly().CodeBase);
var codeBasePath = Uri.UnescapeDataString(codeBaseUrl.AbsolutePath);
var dirPath = Path.GetDirectoryName(codeBasePath);
return dirPath;
}

private static string GetCalendarFilename() => Path.Combine(GetRunningDirectory(), _calendarJSONFile);
private static string GetCurrenciesFilename() => Path.Combine(GetRunningDirectory(), _currenciesFile);

public static IObjectStore<T> GetObjectCache<T>()
{
lock (_lock)
{
var os = SessionContainer.GetService<IObjectStore<T>>();
_registeredTypes.AddOrUpdate(typeof(T), os, (x, y) => os);
return os;
}
}
public static T GetObjectFromCache<T>(string name)
{
lock (_lock)
{
return SessionContainer.GetService<IObjectStore<T>>().GetObject(name).Value;
}
}
public static void PutObjectToCache<T>(string name, T obj) => GetObjectCache<T>().PutObject(name, new SessionItem<T> { Name = name, Value = obj, Version = 1 });

public static void FlushCache<T>() => SessionContainer.GetService<IObjectStore<T>>().Clear();
public static void FlushAllCaches()
{
foreach (var t in _registeredTypes.Values.ToArray())
{
t.Clear();
}
}
}
}
Loading

0 comments on commit 3a88bf8

Please sign in to comment.