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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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> >();
        }
예제 #5
0
        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();
        }
예제 #6
0
 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);
 }
예제 #7
0
        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();
            }
        }
예제 #8
0
        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();
            }
        }
예제 #9
0
        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();
        }
예제 #10
0
 private void DefaultsButton_Click(object sender, RoutedEventArgs e)
 {
     _set     = new GlobalSettings();
     Settings = ObservableSettings.CreateFromGlobalSettings(_set);
 }
예제 #11
0
 public FolderRepository(ObservableSettings settings, RiZhi log)
 {
     _settings = settings ?? throw new ArgumentNullException(nameof(settings));
     _log      = log ?? throw new ArgumentNullException(nameof(log));
 }