public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue) { var(settings, loadSettingsErrMsg) = Settings.LoadSettingsAsync().GetAwaiter().GetResult(); if (loadSettingsErrMsg is not null) { snackbarMessageQueue.Enqueue(loadSettingsErrMsg); } _settings = settings; _observableSettings = new(settings); _snackbarMessageQueue = snackbarMessageQueue; // Configure logging. var queuedTextBoxsink = new QueuedTextBoxSink(_observableSettings); var logger = new LoggerConfiguration() .WriteTo.Sink(queuedTextBoxsink) .CreateLogger(); Locator.CurrentMutable.UseSerilogFullLogger(logger); BackendService = new(_observableSettings); PresetDialogVM = new(ControlDialog); HomeVM = new(_observableSettings, BackendService, queuedTextBoxsink, PresetDialogVM, snackbarMessageQueue); SettingsVM = new(_observableSettings, BackendService, snackbarMessageQueue); Tabs = new object[] { HomeVM, SettingsVM, }; SaveSettingsAsyncCommand = ReactiveCommand.CreateFromTask <CancelEventArgs?, bool>(SaveSettingsAsync); }
public ObservableSettings LoadConfigFile(string configPath) { SettingsModel rawSettings; using (StreamReader file = File.OpenText(configPath)) { var serializer = JsonSerializer.Create(); rawSettings = serializer.Deserialize(file, typeof(SettingsModel)) as SettingsModel; } // Validate that nothing is null if (rawSettings == null) { throw new Exception("Parsed config file is null"); } var nullSubObjectCount = typeof(SettingsModel).GetProperties() .Select(prop => prop.GetValue(rawSettings)) .Where(value => value == null) .Count(); if (nullSubObjectCount > 0) { throw new Exception("Parsed config file contained null subobject"); } var nullGeneralSettingsCount = typeof(GeneralSettings).GetProperties() .Select(prop => prop.GetValue(rawSettings.GeneralSettings)) .Where(value => value == null) .Count(); if (nullGeneralSettingsCount > 0) { throw new Exception("Parsed config file general settings contains null"); } var nullReplaySettingsCount = typeof(ReplaySettings).GetProperties() .Select(prop => prop.GetValue(rawSettings.ReplaySettings)) .Where(value => value == null) .Count(); if (nullGeneralSettingsCount > 0) { throw new Exception("Parsed config file replay settings contains null"); } var nullRequestSettingsCount = typeof(RequestSettings).GetProperties() .Select(prop => prop.GetValue(rawSettings.RequestSettings)) .Where(value => value == null) .Count(); if (nullRequestSettingsCount > 0) { throw new Exception("Parsed config file request settings contains null"); } Settings = new ObservableSettings(rawSettings); return(Settings); }
public FileManager(ObservableSettings settings, RiZhi log) { _log = log ?? throw new ArgumentNullException(nameof(log)); _fileSystem = new FolderRepository(settings, log); _db = new DatabaseRepository(log); _reader = new ReplayReader(log); }
public RequestManager(ObservableSettings settings, RiZhi log) { _settings = settings; _log = log ?? throw new ArgumentNullException(nameof(log)); _downloadClient = new DownloadClient(_cachePath, _settings, _log); _cacheClient = new CacheClient(_cachePath, _log); _inProgressTasks = new ConcurrentDictionary <string, Task <ResponseBase> >(); }
public DownloadClient(string downloadPath, ObservableSettings settings, RiZhi log) { if (string.IsNullOrEmpty(downloadPath)) { throw new ArgumentNullException(nameof(downloadPath)); } _settings = settings; _log = log; _downloadRootFolder = downloadPath; _httpClient = new HttpClient(); }
private void ReloadButton_Click(object sender, RoutedEventArgs e) { _set = GlobalSettings.Load(""); if (null == _set) { _set = GlobalSettings.Load(""); } if (null == _set) { throw new Exception("There was an error attempting to build default config files - may be a file permissions issue! Cannot proceed."); } Settings = ObservableSettings.CreateFromGlobalSettings(_set); }
public SettingsManager(RiZhi log) { Executables = new ExecutableManager(log); _log = log; string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"); if (File.Exists(configPath)) { LoadConfigFile(configPath); } else { _log.Information("No config file found, creating new defaults"); Settings = new ObservableSettings(); } }
public DatabaseRepository(ObservableSettings settings, RiZhi log) { _settings = settings; _log = log; try { InitializeDatabase(); } catch (Exception ex) { _log.Warning($"Database file is invalid, deleting and trying again... exception:{ex}"); File.Delete(_filePath); InitializeDatabase(); } }
public SettingsManager(RiZhi log) { _log = log ?? throw new ArgumentNullException(nameof(log)); Executables = new ExecutableManager(log); if (File.Exists(_configPath)) { LoadConfigFile(); } else { _log.Information("No config file found, creating new defaults"); Settings = new ObservableSettings(); } LoadTemporaryValues(); }
private void DefaultsButton_Click(object sender, RoutedEventArgs e) { _set = new GlobalSettings(); Settings = ObservableSettings.CreateFromGlobalSettings(_set); }
public FolderRepository(ObservableSettings settings, RiZhi log) { _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _log = log ?? throw new ArgumentNullException(nameof(log)); }