-
Notifications
You must be signed in to change notification settings - Fork 4
/
Program.cs
176 lines (157 loc) · 7.24 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using fiskaltrust.ifPOS.v1.at;
using fiskaltrust.ifPOS.v1.de;
using fiskaltrust.ifPOS.v1.it;
using fiskaltrust.ifPOS.v1.me;
using fiskaltrust.Middleware.Abstractions;
using fiskaltrust.Middleware.Queue.Test.Launcher.Helpers;
using fiskaltrust.storage.serialization.V0;
using fiskaltrust.storage.V0;
using fiskaltrust.storage.V0.MasterData;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
namespace fiskaltrust.Middleware.Queue.Test.Launcher
{
public static class Program
{
private static readonly string _cashBoxId = "";
private static readonly string _accessToken = "";
private static readonly string _localization = "DE";
public static void Main(string configurationFilePath = "", string serviceFolder = @"C:\ProgramData\fiskaltrust\service")
{
ftCashBoxConfiguration cashBoxConfiguration = null;
if (!string.IsNullOrEmpty(configurationFilePath))
{
cashBoxConfiguration = JsonConvert.DeserializeObject<ftCashBoxConfiguration>(File.ReadAllText(configurationFilePath));
}
else
{
cashBoxConfiguration = HelipadHelper.GetConfigurationAsync(_cashBoxId, _accessToken).Result;
}
if (string.IsNullOrEmpty(serviceFolder))
{
serviceFolder = Directory.GetCurrentDirectory();
}
var config = cashBoxConfiguration.ftQueues[0];
config.Configuration.Add("cashboxid", cashBoxConfiguration.ftCashBoxId);
config.Configuration.Add("accesstoken", _accessToken);
config.Configuration.Add("useoffline", true);
config.Configuration.Add("sandbox", true);
config.Configuration.Add("servicefolder", serviceFolder);
config.Configuration.Add("configuration", JsonConvert.SerializeObject(cashBoxConfiguration));
config.Configuration.Add("ClosingTARExportTimeoutMin", 1);
config.Configuration.Add("ClosingTARExportPollingDurationMs", 6000);
//config.Configuration.Add("DisableClosingTARExport", true);
var serviceCollection = new ServiceCollection();
serviceCollection.AddStandardLoggers(LogLevel.Debug);
if (_localization == "ME")
{
serviceCollection.AddScoped<IClientFactory<IMESSCD>, MESSCDClientFactory>();
OverrideMasterdata(_localization, config);
}
else if (_localization == "IT")
{
serviceCollection.AddScoped<IClientFactory<IITSSCD>, ITSSCDClientFactory>();
}
else if (_localization == "AT")
{
serviceCollection.AddScoped<IClientFactory<IATSSCD>, ATSSCDClientFactory>();
}
else if (_localization == "DE")
{
serviceCollection.AddScoped<IClientFactory<IDESSCD>, DESSCDClientFactory>();
}
if (config.Package == "fiskaltrust.Middleware.Queue.SQLite" || config.Package == "fiskaltrust.service.sqlite")
{
ConfigureSQLite(config, serviceCollection);
}
else if (config.Package == "fiskaltrust.Middleware.Queue.EF")
{
ConfigureEF(config, serviceCollection);
}
else if (config.Package == "fiskaltrust.Middleware.Queue.MySQL")
{
ConfigureMySQL(config, serviceCollection);
}
else if (config.Package == "fiskaltrust.Middleware.Queue.AzureTableStorage" || config.Package == "fiskaltrust.service.azure")
{
ConfigureAzureTableStorage(config, serviceCollection);
}
else
{
throw new NotSupportedException($"The given package {config.Package} is not supported.");
}
var provider = serviceCollection.BuildServiceProvider();
var pos = provider.GetRequiredService<ifPOS.v1.IPOS>();
HostingHelper.SetupServiceForObject(config, pos, provider.GetRequiredService<ILoggerFactory>());
Console.WriteLine("Press key to end program");
Console.ReadLine();
}
private static void OverrideMasterdata(string localization, PackageConfiguration config)
{
var key = "init_ftQueue";
if (config.Configuration.ContainsKey(key))
{
var queues = JsonConvert.DeserializeObject<List<ftQueue>>(config.Configuration[key].ToString());
queues.FirstOrDefault().CountryCode = localization;
config.Configuration[key] = JsonConvert.SerializeObject(queues);
}
var temp = config.Configuration["init_ftQueueDE"];
config.Configuration["init_ftQueue" + localization] = temp.ToString().Replace("DE", localization);
temp = config.Configuration["init_ftSignaturCreationUnitDE"];
config.Configuration["init_ftSignaturCreationUnit" + localization] = temp.ToString().Replace("DE", localization);
var masterDataConfiguration = new MasterDataConfiguration
{
Account = new AccountMasterData { TaxId = "03102955" },
Outlet = new OutletMasterData { LocationId = "pg000qi813" },
PosSystems = new List<PosSystemMasterData>
{
new() { Brand = "xl522hw351", Model = "wv720nq953" }
}
};
config.Configuration["init_masterData"] = JsonConvert.SerializeObject(masterDataConfiguration);
}
private static void ConfigureSQLite(PackageConfiguration queue, ServiceCollection serviceCollection)
{
var bootStrapper = new SQLite.PosBootstrapper
{
Id = queue.Id,
Configuration = queue.Configuration
};
bootStrapper.ConfigureServices(serviceCollection);
}
private static void ConfigureMySQL(PackageConfiguration queue, ServiceCollection serviceCollection)
{
var bootStrapper = new MySQL.PosBootstrapper
{
Id = queue.Id,
Configuration = queue.Configuration
};
bootStrapper.ConfigureServices(serviceCollection);
}
private static void ConfigureAzureTableStorage(PackageConfiguration queue, ServiceCollection serviceCollection)
{
queue.Url = new string[] { "rest://localhost:5000" };
var bootStrapper = new AzureTableStorage.PosBootstrapper
{
Id = queue.Id,
Configuration = queue.Configuration
};
bootStrapper.ConfigureServices(serviceCollection);
}
private static void ConfigureEF(PackageConfiguration queue, ServiceCollection serviceCollection)
{
var bootStrapper = new EF.PosBootstrapper
{
Id = queue.Id,
Configuration = queue.Configuration
};
bootStrapper.ConfigureServices(serviceCollection);
}
}
}