public static void Init() { try { Logger.Log.Info("RestoreTabs Init"); UserSettingsService.RegPlugin(PluginName, CreateUserSettings, CheckUserSettings); UserSettingsService.ChangeSettings += UserSettingsService_ChangeSettings; // Добавление кнопки в статус бар StatusBarEx.AddPane(string.Empty, "Откытие чертежей", (p, e) => Restore(), icon: Resources.restoreFiles16); var isOn = UserSettingsService.GetPluginValue <bool>(PluginName, ParamRestoreIsOn); if (isOn) { Logger.Log.Info("RestoreTabs включен."); Subscribe(); var tabsData = LoadData(); if (tabsData.Data?.Sessions?.Any(s => s?.Drawings?.Count > 0) == true) { Restore(); } } else { Logger.Log.Info("RestoreTabs отключен."); } } catch (Exception ex) { Logger.Log.Error(ex, "RestoreTabs.Init"); } }
private async Task <LibraryInfo> FindLibrary(Version appVers = null, Version libVers = null) { var libData = await new HttpClient().GetStringAsync(m_LibInfoUrl); var libs = new UserSettingsService().ReadSettings <LibraryCollection>(new StringReader(libData)); if (libs == null) { throw new ArgumentNullException(); } LibraryInfo lib; if (libVers != null) { lib = libs.Versions.FirstOrDefault(l => l.Version == libVers); if (lib == null) { throw new UserMessageException($"Specified version {libVers} of the library is not available"); } } else { lib = libs.Versions.OrderBy(l => l.Version).LastOrDefault( l => appVers == null || ((l.MinimumAppVersion == null || l.MinimumAppVersion <= appVers) && (l.MaximumAppVersion == null || l.MaximumAppVersion >= appVers))); if (lib == null) { throw new UserMessageException($"Failed to find the version of the library which is supported by {appVers} version of the application"); } } return(lib); }
public async Task LoadTest() { // Arrange var mock = new Mock <IFileSystemRepository>(); mock.Setup(r => r.RetrieveJsonFromFile(It.IsAny <string>())).Returns(@"{""FactionName"":""Alliance Rapid-reaction Corps"",""OffLimits"":[""Biria"",""Bruthanvan"",""CD-45 7854""]}"); var userSettingsService = new UserSettingsService(mock.Object); var expected = new UserSettings(); expected.FactionName = "Alliance Rapid-reaction Corps"; expected.OffLimits = new List <string> { "Biria", "Bruthanvan", "CD-45 7854" }; //Act var task = userSettingsService.Load(); var actual = await task; //Assert Assert.True(task.Status != TaskStatus.Faulted, "FileSystemRepository.Save failed to run: " + task.Exception); Assert.Equal(expected.FactionName, actual.FactionName); Assert.Equal(expected.OffLimits, actual.OffLimits); }
public void TestLimitDisabled() { var xmlSettings = new UserSettingsService(); xmlSettings.Initialize(); var logger = new Mock <ILogger>(); var mediator = new Mock <Mediator>(); var shutdownService = new Mock <IShutdownService>(); var limitHandler = new LimitHandler(mediator.Object, xmlSettings, logger.Object, shutdownService.Object); var app = new Aplication() { WinName = "test app" }; var limit = new AppLimit() { LimitReachedAction = LimitReachedAction.Warn, Application = app, ID = 1 }; xmlSettings.LimitsSettings.DontShowLimits.Add(limit.ID); limitHandler.Handle(limit); mediator.Verify(m => m.NotifyColleagues(MediatorMessages.APP_LIMIT_REACHED, limit), Times.Never()); }
public void CustomConverterDerivedTypeTest() { var srv = new UserSettingsService(); var setts = new SettsMock4() { Obj = new ObjectType2() { Value = "XYZ" } }; var res1 = new StringBuilder(); var ser = new BaseValueSerializer <IObjectType>(x => x.Value, x => new ObjectType2() { Value = x }); srv.StoreSettings(setts, new StringWriter(res1), ser); var res2 = srv.ReadSettings <SettsMock4>(new StringReader("{\"Obj\":\"ABC\"}"), ser); Assert.AreEqual("{\"Obj\":\"XYZ\"}", res1.ToString()); Assert.AreEqual("ABC", res2.Obj.Value); }
/// <summary> /// Checks and updates the digital object directory and writes changes to the toc and signature strings. /// Checks and updates concern the directory name and the names of media and access structure files (f. e. playlist files) /// </summary> /// <param name="itemId"> /// Id of the RQItem record of the digital object. /// </param> /// <param name="tocString"> /// The toc string (normally stored in the RQItem record of the digital object). /// </param> /// <param name="signatureStr"> /// The signature string (normally stored in the RQItem record of the digital object).</param> /// <param name="itemDescriptors"> /// A string dictionary of field names (keys) and field contents (values) of the RQItem record of the digital object. /// </param> /// <returns> /// True if update was successful. /// Updated values in tocString and signatureStr. /// </returns> public static bool UpdateDigitalObjectDirectory(string itemId, ref string tocString, ref string signatureStr, StringDictionary itemDescriptors) { bool result = false; string toc = tocString.ToLower(); if (toc.Contains("$$toc$$=")) { ImportOptions directories = new UserSettingsService().GetImportOptions(); string objectName = GetObjectName(tocString); if (toc.Contains("arcmusicmp3") || toc.Contains("arcaudiomp3")) { return(new Mp3Album(directories.AudioProjectDirectory + "\\" + objectName.Replace("XXXXX_", ""), toc.Contains("arcmusicmp3") ? "ArcMusicMP3" : "ArcAudioMP3").BindTo(itemId, ref tocString, ref signatureStr, itemDescriptors)); } if (toc.Contains("myvideo")) { return(new M4vAlbum(directories.VideoProjectDirectory + "\\" + objectName).BindTo(itemId, ref tocString, ref signatureStr, itemDescriptors)); } if (toc.Contains("mydocs")) { return(new PdfCollection(directories.DocumentProjectDirectory + "\\" + objectName).BindTo(itemId, ref tocString, ref signatureStr, itemDescriptors)); } } return(result); }
public async Task SaveAsyncTest_NG() { appSettings.AppDataPath = Path.Combine(appSettings.AppDataPath, "baddirectory"); var target = new UserSettingsService(appSettings); target.UserSettings.MergeUnknownJsonProperty = true; target.UserSettings.ConvertGoogleDriveUri = false; target.UserSettings.PresetInfos = new ObservableCollection <PresetInfo>(new[] { new PresetInfo() { Id = "1", Name = "Preset1", FileName = "Preset1_1.json", }, new PresetInfo() { Id = "2", Name = "Preset2", FileName = "Preset2_2.json", }, new PresetInfo() { Id = "3", Name = "Preset3", FileName = "Preset3_3.json", }, }); await target.SaveAsync(); }
public void WriteSettingsTest() { var srv = new UserSettingsService(m_ServHelper.WorkingDir, new UserSettingsAttribute("SettsStorage", true)); var setts1 = new SettsMock1() { Field1 = "AAA", Field2 = 10 }; var setts2 = new SettsMock2() { Field1 = "BBB", Field3 = 12.5, Field4 = true }; var settsFile1 = Path.Combine(m_ServHelper.WorkingDir, "SettsStorage", "mock1.setts"); var settsFile2 = Path.Combine(m_ServHelper.WorkingDir, "SettsStorage", "mock2.setts"); srv.StoreSettings(setts1, "mock1"); srv.StoreSettings(setts2, "mock2"); Assert.IsTrue(File.Exists(settsFile1)); Assert.IsTrue(File.Exists(settsFile2)); Assert.AreEqual("{\"Field1\":\"AAA\",\"Field2\":10.0,\"__version\":\"0.0\"}", File.ReadAllText(settsFile1)); Assert.AreEqual("{\"Field1\":\"BBB\",\"Field3\":12.5,\"Field4\":true,\"__version\":\"2.1.0\"}", File.ReadAllText(settsFile2)); }
public void WriteSettingsTest() { var srv = new UserSettingsService(); var setts1 = new SettsMock1() { Field1 = "AAA", Field2 = 10 }; var setts2 = new SettsMock2() { Field1 = "BBB", Field3 = 12.5, Field4 = true }; var res1 = new StringBuilder(); var res2 = new StringBuilder(); srv.StoreSettings(setts1, new StringWriter(res1)); srv.StoreSettings(setts2, new StringWriter(res2)); Assert.AreEqual("{\"Field1\":\"AAA\",\"Field2\":10.0}", res1.ToString()); Assert.AreEqual("{\"Field1\":\"BBB\",\"Field3\":12.5,\"Field4\":true,\"__version\":\"2.1.0\"}", res2.ToString()); }
public void ReadSettingsTest() { var srv = new UserSettingsService(); var mock1 = "{\"Field1\":\"AAA\",\"Field2\":10.0,\"__version\":\"0.0\"}"; var mock2 = "{\"Field1\":\"BBB\",\"Field3\":12.5,\"Field4\":true,\"__version\":\"2.1.0\"}"; var setts1 = srv.ReadSettings <SettsMock1>(new StringReader(mock1)); var setts2 = srv.ReadSettings <SettsMock1>(new StringReader(mock2)); var setts3 = srv.ReadSettings <SettsMock2>(new StringReader(mock2)); var setts4 = srv.ReadSettings <SettsMock1>(new StringReader(mock1)); var setts5 = srv.ReadSettings <SettsMock1>(new StringReader(mock2)); var setts6 = srv.ReadSettings <SettsMock2>(new StringReader(mock1)); var setts7 = srv.ReadSettings <SettsMock2>(new StringReader(mock2)); Assert.AreEqual("AAA", setts1.Field1); Assert.AreEqual(10, setts1.Field2); Assert.AreEqual("BBB", setts2.Field1); Assert.AreEqual(default(double), setts2.Field2); Assert.AreEqual("BBB", setts3.Field1); Assert.AreEqual(12.5, setts3.Field3); Assert.AreEqual(true, setts3.Field4); Assert.AreEqual("AAA", setts4.Field1); Assert.AreEqual(10, setts4.Field2); Assert.AreEqual("BBB", setts5.Field1); Assert.AreEqual(default(double), setts5.Field2); Assert.AreEqual("AAA", setts6.Field1); Assert.AreEqual(10, setts6.Field3); Assert.AreEqual(default(bool), setts6.Field4); Assert.AreEqual("BBB", setts7.Field1); Assert.AreEqual(12.5, setts7.Field3); Assert.AreEqual(true, setts7.Field4); }
private bool ShowLogin() { //Startup Login LoginWindow loginWindow = new LoginWindow(); DomainManager domainManager = new DomainManager(); ManufacturingContext context = new ManufacturingContext(this.optionsBuilder.Options); IUserSettingsService userSettingsService = new UserSettingsService(this._logger, context); IAuthenticationUseCase auth = new AuthenticationService(context, domainManager, this._logger, userSettingsService); var loginVM = new LoginViewModel(auth, userSettingsService); loginVM.LoginCompleted += (sender, args) => { if (loginVM.LoginResponce.Success) { this.userService = loginVM.LoginResponce.Service; DXSplashScreen.Show <SETSplashScreen>(); } loginWindow.Close(); }; loginWindow.DataContext = loginVM; if (DXSplashScreen.IsActive) { DXSplashScreen.Close(); } loginWindow.ShowDialog(); return(this.userService.IsValid()); }
public TestListViewModel() { _testSessionContextLoader = new TestSessionContextLoader(this); _settingsService = new UserSettingsService(); _testRunner = new TestCaseRunner(); InitializeTestListCommand = new AsyncDelegateCommand(InitializeTestList); ExecuteAllTestsCommand = new AsyncDelegateCommand(ExecuteAllTests); ExecuteSelectedTestsCommand = new AsyncDelegateCommand(ExecuteSelectedTests); ExecuteSelectedTestsInParallelCommand = new AsyncDelegateCommand(ExecuteSelectedTestsInParallel); TestGroups = new ObservableCollection<TestGroupViewModel>(); TestCategories = new ObservableCollection<TestCategoryViewModel>(); TestResultFilters = new ObservableCollection<TestResultFilterViewModel>(); InitializeTestResultFilters(); ConfigFilePath = _settingsService.LastConfigFilePath; _testSessionContextLoader.ProgressChanged += OnTestSessionContextLoaderProgressChanged; _testRunner.TestCaseFinished += OnTestCaseFinished; _testRunner.TestCaseStarting += OnTestCaseStarting; IsProgressIndeterminate = true; EventAggregator.TestViewModelSelected += OnTestViewModelSelected; }
public async Task ConstructorTest_例外() { var input = @" { ""PresetInfos"": [ { ""Id"": ""1"", ""Name"": ""Preset1"", ""FileName"": ""Preset1_1.json"" }, { ""Id"": ""2"", ""Name"": ""Preset2"", ""FileName"": ""Preset2_2.json"" }, } ], ""ConvertGoogleDriveUri"": false, ""MergeUnknownJsonProperty"": false }".RemoveSpace(); await TestUtility.CreateTestDataFileAsync(settingPath, input); var target = new UserSettingsService(appSettings); Assert.IsTrue(target.UserSettings.ConvertGoogleDriveUri); Assert.IsTrue(target.UserSettings.MergeUnknownJsonProperty); Assert.IsNotNull(target.UserSettings.PresetInfos); Assert.IsFalse(target.UserSettings.PresetInfos.Any()); }
public UserSettingsServiceTests() { _options = new DbContextOptionsBuilder <StockNotificationContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; _dbContext = new StockNotificationContext(_options); _userSettingsService = new UserSettingsService(_dbContext); }
private async Task ExportSettings() { FileSavePicker filePicker = new FileSavePicker(); filePicker.FileTypeChoices.Add("Zip File", new[] { ".zip" }); filePicker.SuggestedFileName = $"Files_{App.AppVersion}"; StorageFile file = await filePicker.PickSaveFileAsync(); if (file != null) { try { var zipFolder = await ZipStorageFolder.FromStorageFileAsync(file); if (zipFolder == null) { return; } var localFolderPath = ApplicationData.Current.LocalFolder.Path; // Export user settings var userSettings = await zipFolder.CreateFileAsync(Constants.LocalSettings.UserSettingsFileName, CreationCollisionOption.ReplaceExisting); string exportSettings = (string)UserSettingsService.ExportSettings(); await userSettings.WriteTextAsync(exportSettings); // Export bundles var bundles = await zipFolder.CreateFileAsync(Constants.LocalSettings.BundlesSettingsFileName, CreationCollisionOption.ReplaceExisting); string exportBundles = (string)BundlesSettingsService.ExportSettings(); await bundles.WriteTextAsync(exportBundles); // Export pinned items var pinnedItems = await BaseStorageFile.GetFileFromPathAsync(Path.Combine(localFolderPath, Constants.LocalSettings.SettingsFolderName, App.SidebarPinnedController.JsonFileName)); await pinnedItems.CopyAsync(zipFolder, pinnedItems.Name, NameCollisionOption.ReplaceExisting); // Export terminals config var terminals = await BaseStorageFile.GetFileFromPathAsync(Path.Combine(localFolderPath, Constants.LocalSettings.SettingsFolderName, App.TerminalController.JsonFileName)); await terminals.CopyAsync(zipFolder, terminals.Name, NameCollisionOption.ReplaceExisting); // Export file tags list and DB var fileTagsList = await zipFolder.CreateFileAsync(Constants.LocalSettings.FileTagSettingsFileName, CreationCollisionOption.ReplaceExisting); string exportTags = (string)FileTagsSettingsService.ExportSettings(); await fileTagsList.WriteTextAsync(exportTags); var fileTagsDB = await zipFolder.CreateFileAsync(Path.GetFileName(FileTagsHelper.FileTagsDbPath), CreationCollisionOption.ReplaceExisting); string exportTagsDB = FileTagsHelper.DbInstance.Export(); await fileTagsDB.WriteTextAsync(exportTagsDB); } catch (Exception ex) { App.Logger.Warn(ex, "Error exporting settings"); } } }
public void PIK_UserSettings() { CommandStart.Start(doc => { UserSettingsService.Show(); UserInfo.ShowUserProfileRegister(); }); }
public void SaveJobToFile(BatchJob job, string filePath) { var svc = new UserSettingsService(); svc.StoreSettings(job, filePath); AppendRecentFiles(filePath); }
internal static BatchJob FromFile(string filePath) { var svc = new UserSettingsService(); var batchJob = svc.ReadSettings <BatchJob>(filePath); return(batchJob); }
public void ConstructorTest_ファイル無し() { var target = new UserSettingsService(appSettings); Assert.IsTrue(target.UserSettings.ConvertGoogleDriveUri); Assert.IsTrue(target.UserSettings.MergeUnknownJsonProperty); Assert.IsNotNull(target.UserSettings.PresetInfos); Assert.IsFalse(target.UserSettings.PresetInfos.Any()); }
public UserSettingsServiceTests() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; this.db = new ApplicationDbContext(options); this.repo = new EfRepository <ApplicationUser>(db); this.service = new UserSettingsService(this.repo); }
/// <summary> /// Constructor /// </summary> private LayoutViewModel() { using (var db = new DataService()) { Categories = db.GetGateoriesCounters(); Archives = db.GetArchives(); User = UserService.Get(db); UserSettings = UserSettingsService.Get(); } }
public static void ReadSettings() { //--- read var svc = new UserSettingsService(); var userSetts = svc.ReadSettings <UserSettings>( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "my-app-settings.json")); //--- }
public JsonResult SetDyslexicFont() { // Get current settings var settings = UserSettingsService.Get(); // Set new value settings.UseDyslexicFont = true; // Save settings UserSettingsService.Set(settings); return(Json(settings.LayoutContentUrl)); }
protected override void OnStartup(StartupEventArgs e) { try { UserSettingsService.UsersEditor(); } catch (Exception ex) { Log.Error(ex); } }
public ActionResult CookiesConcentClosed() { // Get current settings var settings = UserSettingsService.Get(); // Set new value settings.CookiesConcentClosed = true; // Save settings UserSettingsService.Set(settings); return(Json("true")); }
private static AccessibilitySettings GetAccessibilityModel() { // Get current settings var settings = UserSettingsService.Get(); AccessibilitySettings model = new AccessibilitySettings { UseDyslexicFont = settings.UseDyslexicFont }; return(model); }
//--- public static void StoreSettings() { //--- store var svc = new UserSettingsService(); var userSetts = new UserSettings(); svc.StoreSettings(userSetts, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "my-app-settings.json")); //--- }
private static void UserSettingsService_ChangeSettings(object sender, EventArgs e) { var isOn = UserSettingsService.GetPluginValue <bool>(PluginName, ParamRestoreIsOn); if (isOn) { Subscribe(); } else { Unsubscribe(); } }
public void TestInitialize() { var settingsService = new UserSettingsService(); settingsService.Initialize(); Assert.IsNotNull(settingsService.AppSettings); Assert.IsNotNull(settingsService.DaysViewSettings); Assert.IsNotNull(settingsService.LimitsSettings); Assert.IsNotNull(settingsService.LogsViewSettings); Assert.IsNotNull(settingsService.MainWindowSettings); Assert.IsNotNull(settingsService.ScreenshotsViewSettings); }
/// <summary> /// Builds the actual query. /// </summary> /// <param name="queryString"> /// queryString == null | "" : Rebuilds actual query from stored query state parameters or returns the default query. /// queryString != null : Builds a new query from queryString and stores it in query state parameters. /// </param> /// <param name="stateType"> /// stateType == ListViewState : (Re)builds actual query for ListView. /// stateType == BrowseViewState : (Re)builds actual query for BrowseView. /// stateType == ItemViewState : (Re)builds actual query for SingleItemView. /// </param> /// <returns> /// Actual query. /// </returns> public static RQquery GetQueryFromState(string queryString, UserState.States stateType) { RQquery query = null; state = (ViewState)UserState.Get(stateType); if (state == null) { if (string.IsNullOrEmpty(queryString)) { query = new RQquery("$recent$recent additions", "recent"); } else { query = new RQquery(queryString); } state = new ViewState(stateType); //, queryString); state.query = query; //state.Save(); } else { string querytest; UserSettingsService us = new UserSettingsService(); query = (RQquery)state.query; if (!string.IsNullOrEmpty(queryString) && queryString.StartsWith("$") && queryString.LastIndexOf("$") > 1) { querytest = queryString.Substring(0, queryString.LastIndexOf("$") + 1) + query.QueryString; } else { querytest = query.QueryString; } //if ( (! string.IsNullOrEmpty(queryString) && querytest != queryString) // || (query.QueryExternal == "" && us.GetIncludeExternal() == true) // || (query.QueryExternal != "" && us.GetIncludeExternal() == false) ) //{ // query = new RQquery(! string.IsNullOrEmpty(queryString) ? queryString : query.QueryString); // query.QueryExternal = us.GetIncludeExternal() == true ? "003" : ""; // state.query = query; // //state.Save(); //} if (!string.IsNullOrEmpty(queryString) && querytest != queryString) { query = new RQquery(!string.IsNullOrEmpty(queryString) ? queryString : query.QueryString); } query.QueryExternal = us.GetIncludeExternal() == true ? "003" : ""; state.query = query; } return(query); }
private async Task ExportSettings() { FileSavePicker filePicker = new FileSavePicker(); filePicker.FileTypeChoices.Add("Json File", Path.GetExtension(Constants.LocalSettings.UserSettingsFileName).CreateList()); StorageFile file = await filePicker.PickSaveFileAsync(); if (file != null) { string export = (string)UserSettingsService.ExportSettings(); await FileIO.WriteTextAsync(file, export); } }