private async Task RunImplementationAsync() { JsonDefaultSettings.Initialize(); Log.Initialize(new Logger(), VersionHelper.GetEntryAssemblyVersion()); // read configuration try { _configuration = JsonConvert.DeserializeObject <KioskAutoUpdaterConfiguration>(File.ReadAllText(ConfigurationFilePath, Encoding.UTF8)); } catch (Exception ex) { Log.Error(LogContextEnum.KioskAutoUpdater, "Configuration read failed.", ex); return; } // read serial key try { _kioskSerialKey = File.ReadAllText(KioskSerialKeyFilePath, Encoding.UTF8); } catch (Exception ex) { Log.Error(LogContextEnum.KioskAutoUpdater, $"'{KioskFileNames.Key}' read failed.", ex); return; } ServerApiProxy.Current.Initialize(_configuration.ServerUri, _kioskSerialKey); Log.Info(LogContextEnum.KioskAutoUpdater, $"'{nameof(KioskAutoUpdater)}' started."); await RunUpdateCheckWorkerAsync(); }
public void UwpApplication_OnLaunched(LaunchActivatedEventArgs e) { if (!_isLoggingInitialized) { // logging initialization JsonDefaultSettings.Initialize(); Log.Initialize(new Logger(), VersionHelper.AppVersionString); _isLoggingInitialized = true; } var currentView = CoreApplication.GetCurrentView(); Log.Info(LogContextEnum.Application, "Launched.", new { Kind = e.Kind.ToString(), PreviousExecutionState = e.PreviousExecutionState.ToString(), ViewCount = CoreApplication.Views.Count, IsCurrentViewMain = currentView.IsMain, }); if (!_isUwpApplicationInitialized) { #if DEBUG // enter fullscreen (dev mode only) ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen; var applicationView = ApplicationView.GetForCurrentView(); applicationView.TryEnterFullScreenMode(); #endif // helper initialization ThreadHelper.Initialize(currentView.Dispatcher); #pragma warning disable 4014 StartKioskApplicationAsync(); #pragma warning restore 4014 _isUwpApplicationInitialized = true; } else { Log.Error(LogContextEnum.Application, "Application is initialized already."); } Window.Current.Activate(); }
private static void Main(string[] args) { JsonDefaultSettings.Initialize(); var manufacturerIds = JsonConvert.DeserializeObject <Dictionary <string, int> >( File.ReadAllText("ManufacturerIds.json", Encoding.UTF8)); var records = new List <ModelRecord>(); records.AddRange(ReadModelRecords("MappingCars.csv", TecDocTypeEnum.P)); records.AddRange(ReadModelRecords("MappingTrucks.csv", TecDocTypeEnum.O)); var carGroups = records .GroupBy(x => x.CarType) .Select(x => new EkCarGroup() { CarType = x.Key, Manufacturers = GetManufacturers(x.Key, x.ToArray(), manufacturerIds), }) .ToArray(); var json = JsonConvert.SerializeObject(carGroups); }
public void ConfigureServices(IServiceCollection services) { JsonDefaultSettings.Initialize(); }
public static void AddKioskBrainsApplication( this IServiceCollection services, WafHostEnum wafHost, IConfiguration configuration) { Assure.ArgumentNotNull(configuration, nameof(configuration)); JsonDefaultSettings.Initialize(); // Settings services.Configure <EkSearchSettings>(configuration.GetSection("EkSearchSettings")); // Memory Cache services.AddMemoryCache(); // Persistent Cache services.AddScoped <IPersistentCache, DbPersistentCache>(); // DB Context services.AddDbContextPool <KioskBrainsContext>(options => options .UseSqlServer(configuration.GetConnectionString("KioskBrainsContext")) .ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning))); if (wafHost == WafHostEnum.Web) { // Authentication services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = JwtAuthOptions.Issuer, ValidateAudience = true, ValidAudience = JwtAuthOptions.Audience, ValidateLifetime = true, ValidateIssuerSigningKey = true, IssuerSigningKey = JwtAuthOptions.GetSymmetricSecurityKey(), }; }); // Add CurrentUser services.AddCurrentUser(); } // WAF services.AddWaf( wafHost, appActionAssemblyNames: AppActionAssemblyNames, appManagerAssemblyNames: AppActionAssemblyNames); // Integration Log services.AddTransient <IIntegrationLogManager, IntegrationLogManager>(); // Notifications services.Configure <NotificationManagerSettings>(configuration.GetSection("NotificationManagerSettings")); services.AddScoped <INotificationManager, NotificationManagerStub>(); //Repo and services services.AddScoped <ITranslateService, TranslateService>(); services.AddScoped <IReadOnlyRepository, ReadOnlyRepository <KioskBrainsContext> >(); services.AddScoped <IWriteOnlyRepository, WriteOnlyRepository <KioskBrainsContext> >(); // Common Clients services.Configure <KioskProxyClientSettings>(configuration.GetSection("KioskProxyClientSettings")); services.AddScoped <KioskProxyClient>(); services.Configure <AzureStorageSettings>(configuration.GetSection("AzureStorageSettings")); services.AddScoped <AzureStorageClient>(); }
private static void Main(string[] args) { JsonDefaultSettings.Initialize(); using (var reader = new StreamReader("Categories.csv", Encoding.UTF8)) { using (var csvReader = new CsvReader(reader)) { var records = csvReader.GetRecords <CsvRecord>() .ToArray(); var parsedRecords = records .Select(x => new { Record = x, NameParts = x.Name .Split('>') .Select(p => p .Trim() .Replace(" , ", ", ")) .ToArray(), }) .ToArray(); var maxDepth = parsedRecords.Max(x => x.NameParts.Length); var categories = new Dictionary <string, EkProductCategory>(); var rootCategories = new List <EkProductCategory>(); for (var depth = 1; depth <= maxDepth; depth++) { var depthCategoryRecords = parsedRecords .Where(x => x.NameParts.Length == depth) .ToArray(); foreach (var parsedRecord in depthCategoryRecords) { var fullName = string.Join(">", parsedRecord.NameParts); var category = new EkProductCategory() { CategoryId = parsedRecord.Record.Id, Name = new MultiLanguageString() { [Languages.RussianCode] = parsedRecord.NameParts.Last(), }, }; if (categories.ContainsKey(fullName)) { throw new InvalidOperationException("Duplicate!"); } categories[fullName] = category; if (depth != 1) { var parentFullName = string.Join(">", parsedRecord.NameParts.Take(parsedRecord.NameParts.Length - 1)); var parentCategory = categories[parentFullName]; if (parentCategory.Children == null) { parentCategory.Children = new EkProductCategory[] { category, }; } else { var newChildren = new List <EkProductCategory>(parentCategory.Children) { category }; parentCategory.Children = newChildren.ToArray(); } } else { // root category rootCategories.Add(category); } } } // order children by name foreach (var category in categories.Values .Where(x => x.Children?.Length > 0)) { category.Children = category.Children .OrderBy(x => x.Name.GetValue(Languages.RussianCode)) .ToArray(); } // rename auto-parts var autoPartsCategory = rootCategories .Where(x => x.Name[Languages.RussianCode] == "Автозапчасти") .First(); autoPartsCategory.Name[Languages.RussianCode] = "Запчасти легковые и грузовые"; var json = JsonConvert.SerializeObject(rootCategories); } } Console.WriteLine("Hello World!"); }