public WithBackupSettingsFileExpoter( string targetFilePath, ISettingsContainer container, ISettingsSerializer serializer) : this(targetFilePath, targetFilePath + ".bak", container, serializer) { }
public void SetUp() { _registryService = new FakeRegistryService(); _settingsSerializer = new SettingsSerializer(_registryService, SettingsFilePath); DirectoryUtility.EnsureClearFolder(TempFolder); }
public WithBackupSettingsFileExpoter( string targetFilePath, string tempFilePath, ISettingsContainer container, ISettingsSerializer serializer) { if (targetFilePath == null) { throw new ArgumentNullException(nameof(targetFilePath)); } if (tempFilePath == null) { throw new ArgumentNullException(nameof(tempFilePath)); } if (container == null) { throw new ArgumentNullException(nameof(container)); } if (serializer == null) { throw new ArgumentNullException(nameof(serializer)); } TargetFilePath = targetFilePath; TempFilePath = tempFilePath; Container = container; Serializer = serializer; }
//------------------------------------------------------------------------------ public static KeyValuePair <ISettingsSerializer, bool> GetCustomSerializer(object context, Type customSerializerType, ref Dictionary <Type /*serializer type*/, KeyValuePair <ISettingsSerializer, bool /*skip external serializer*/> > serializersCache) { ISettingsSerializer serializer = null; KeyValuePair <ISettingsSerializer, bool> pair; bool isExist = serializersCache.TryGetValue(customSerializerType, out pair); if (!isExist) { serializer = (ISettingsSerializer)Activator.CreateInstance(customSerializerType); ISettingsSerializerParams serializerParams = serializer as ISettingsSerializerParams; if (serializerParams != null) { serializerParams.SetSerializerParams(context); } pair = new KeyValuePair <ISettingsSerializer, bool>(serializer, false); serializersCache[customSerializerType] = pair; } return(pair); }
//------------------------------------------------------------------------------ void SaveDynamicSettingsCustomOrder(ISettingsSerializer serializer, Type settingsType, ref SettingsHelperData settingsHelperData) { var settingsCustomOrderSettingName = SettingNameFormatInfo.GetFullDynamicSettingsCustomOrderSettingName(serializer as ISettingsSerializerWishes, settingsType); var simpleSettingsNames = GetSimpleSettingsNamesWithCustomOrder(); SaveDynamicSettingsOrderImpl(settingsCustomOrderSettingName, simpleSettingsNames, serializer, settingsType, ref settingsHelperData); }
public void DeserializeTest(DistributedPropertySet data, ISettingsSerializer serializer) { IDistributedPropertySet result = null; var config = TestStartup.Configuration; try { result = serializer.Deserialize(serializer.Serialize(data)); } catch (Exception e) { _output.WriteLine(e.ToString()); e.Data.Keys.Cast <string>().ToList().ForEach(key => _output.WriteLine(e.Data[key].ToString())); throw; } Assert.NotNull(result); foreach (var key in data.Keys) { Assert.True(result.ContainsKey(key)); _output.WriteLine($"{key}: {data[key]} {(data[key].Equals(result[key]) ? "==" : "!=")} {result[key]}"); Assert.Equal(data[key], result[key]); } }
public NavigationPresenter(INavigationView view, ISettingsSerializer settingsSerializer, IKeyboardListener keyboardListener, IMatchModelMapper matchModelMapper, IPresentationService presentationService, INavigationServiceBuilder navigationServiceBuilder) { _view = view; _settingsSerializer = settingsSerializer; _keyboardListener = keyboardListener; _matchModelMapper = matchModelMapper; _navigationServiceBuilder = navigationServiceBuilder; _presentationService = presentationService; Settings settings = _settingsSerializer.Deserialize(); _keyboardListener.KeyCombinationPressed += GlobalKeyCombinationPressed; _keyboardListener.StartListening(settings.GlobalKeyCombination); _view.CurrentSettings = settings; _view.ShowMatches(new List <MatchModel> { new MatchModel(_matchModelMapper, Resources.InitialMatchesMessage) }); _view.ShowInitializingScreen = true; //Initialize navigation service asynchronously, as it may require a long operation (file system parsing). //Clone settings to avoid any coupling Settings settingsCopy = settings.Clone() as Settings; InitializeDelegate initialize = Initialize; initialize.BeginInvoke(settingsCopy, EndInitialize, initialize); }
//------------------------------------------------------------------------------ static public bool Delete(ISettingsSerializer serializer, SettingBaseAttribute attr, string settingName, bool secure, FunctionalityHook functionalityHook) { try { serializer.Delete(settingName, secure, attr); } catch (ExceptionForUser exc) { InternalConfiguration.PlatformHelper.Log(LogLevel.Error, String.Format("Delete exception for setting '{0}'", settingName), exc.InnerException); throw exc.InnerException; } catch (Exception exc) { InternalConfiguration.PlatformHelper.Log(LogLevel.Error, String.Format("Delete exception for setting '{0}'", settingName), exc); return(false); } return(true); }
//------------------------------------------------------------------------------ void IPluginContext.DeleteSettings(ISettingsSerializer pluginForegroundSerializer, SettingsBasePlugin sourcePlugin) { try { SetForegroundSerializer(pluginForegroundSerializer); var sink = pluginForegroundSerializer as IForegroundSerializerNotificationSink; if (sink != null) { sink.OnStartStaticSettingsSerialization(this); } DeleteObjectSettings(); if (sink != null) { sink.OnEndStaticSettingsSerialization(); } ProcessDynamicSettingsFromContext(sourcePlugin, sink, (IDynamicSettingsPlugin plugin) => { plugin.DeleteSettings(); }); } finally { SetForegroundSerializer(null); } }
public NavigationPresenter(INavigationView view, ISettingsSerializer settingsSerializer, IKeyboardListener keyboardListener, IMatchModelMapper matchModelMapper, IPresentationService presentationService, INavigationServiceBuilder navigationServiceBuilder) { _view = view; _settingsSerializer = settingsSerializer; _keyboardListener = keyboardListener; _matchModelMapper = matchModelMapper; _navigationServiceBuilder = navigationServiceBuilder; _presentationService = presentationService; Settings settings = _settingsSerializer.Deserialize(); _keyboardListener.KeyCombinationPressed += GlobalKeyCombinationPressed; _keyboardListener.StartListening(settings.GlobalKeyCombination); _view.CurrentSettings = settings; _view.ShowMatches(new List<MatchModel> {new MatchModel(_matchModelMapper, Resources.InitialMatchesMessage)}); _view.ShowInitializingScreen = true; //Initialize navigation service asynchronously, as it may require a long operation (file system parsing). //Clone settings to avoid any coupling Settings settingsCopy = settings.Clone() as Settings; InitializeDelegate initialize = Initialize; initialize.BeginInvoke(settingsCopy, EndInitialize, initialize); }
/// <summary> /// 監視を停止する。 /// </summary> public void EndMonitoring() { try { Settings.PropertyChanged -= Settings_PropertyChanged; if (saveTimer != null) { saveTimer.Dispose(); saveTimer = null; } // タイマ止めた後に変更されていれば保存 try { lock (saveLock_) { if (isSettingsChanged_) { Save(); } } } finally { serializer_ = null; if (stream_ != null) { stream_.Dispose(); stream_ = null; } } } finally { IsMonitoring = false; } }
public SettingsPresenter(ISettingsView view, ISettingsSerializer settingsSerializer) { _settingsSerializer = settingsSerializer; _view = view; _view.CurrentSettings = _settingsSerializer.Deserialize(); _view.SettingsChanged += HandleSettingsChanged; }
public SettingsManager(ISettingsSerializer settingsSerializer) { this.settingsSerializer = settingsSerializer; handleMusicChange(settingsSerializer.RetrieveMusicVolume()); handleSFXChange(settingsSerializer.RetrieveSFXVolume()); onMusicChange += handleMusicChange; onSFXChange += handleSFXChange; }
public SettingsPresenter(ISettingsView view, ISettingsSerializer settingsSerializer) { _settingsSerializer = settingsSerializer; _view = view; _view.CurrentSettings = _settingsSerializer.Deserialize(); _view.SettingsChanged += HandleSettingsChanged; }
public ProjectLoader(IEditorLogger logger, IObjectDumper objectDumper, ISettingsSerializer settingsSerializer) { Check.IfIsNull(logger).Throw<ArgumentNullException>(() => logger); Check.IfIsNull(objectDumper).Throw<ArgumentNullException>(() => objectDumper); this.logger = logger; this.objectDumper = objectDumper; this.settingsSerializer = settingsSerializer; }
public void TestSerialize() { ISettingsSerializer json = SettingsSerializerFactory.Get("JSON"); SettingsElement root = createTestElement(); string output = json.Serialize(root); Assert.IsTrue(output.Contains("FontFamily")); }
public void BuildTests(DistributedPropertySet dataSet, ISettingsSerializer serializer) { Startup = TestStartup.Build(fileType: serializer switch { BinarySettingsSerializer binary => FileTypes.Binary, XmlSettingsSerializer xml => FileTypes.XML, YamlSettingsSerializer yaml => FileTypes.Other, _ => FileTypes.JSON });
//------------------------------------------------------------------------------ IEnumerable <string> GetDynamicSettingsNamesForType(ISettingsSerializer serializer, Type settingsType, bool respectOrder) { IEnumerable <string> result = null; var dynamicSettingsInfo = (IDynamicSettingsInfo)serializer; var delimeter = SettingNameFormatInfo.GetSettingNameDelimeter(serializer as ISettingsSerializerWishes); var settingsTypeInfo = SettingNameFormatInfo.GetSettingsTypeInfo(settingsType, serializer as ISettingsSerializerWishes); var settingsNames = dynamicSettingsInfo.GetDynamicSettingsNames(); var filteredSettingsNames = new List <string>(); foreach (var rawSettingName in settingsNames) { string formatVersion; string typeInfo; string name; bool parseResult = SettingNameFormatInfo.Parse(rawSettingName, delimeter, out formatVersion, out typeInfo, out name, SettingNameMode.Dynamic); if (parseResult) { if (settingsTypeInfo == typeInfo) { filteredSettingsNames.Add(rawSettingName); } } } result = filteredSettingsNames; if (respectOrder) { var settingsOrder = LoadDynamicSettingsDefaultOrder(serializer, settingsType); if (settingsOrder != null) { var fullSettingsNamesCustomOrder = new List <string>(); foreach (var simpleSettingName in settingsOrder) { var fullSettingName = SettingNameFormatInfo.GetFullSettingName(simpleSettingName, serializer as ISettingsSerializerWishes, settingsType, SettingNameMode.Dynamic); fullSettingsNamesCustomOrder.Add(fullSettingName); } // берём только то, что есть в каждой коллекции result = fullSettingsNamesCustomOrder.Intersect(result); } } return(result); }
public void TestDeserialize() { ISettingsSerializer json = SettingsSerializerFactory.Get("JSON"); SettingsElement root = createTestElement(); SettingsElement deserialized = json.Deserialize(Expected); Assert.IsTrue(deserialized.FontFamily == root.FontFamily); Assert.IsTrue(deserialized.ScrollbackLines == root.ScrollbackLines); Assert.IsTrue(deserialized.DefaultProfile.FullName == root.DefaultProfile.FullName); Assert.IsTrue(deserialized.Networks.First().UserProfile.FullName == root.Networks.First().UserProfile.FullName); }
public StartupWindowViewModel(ISettingsSerializer settingsSerializer, IProjectLoader projectLoader, IFileOpener<IProject> projectOpener) { Check.IfIsNull(settingsSerializer).Throw<ArgumentNullException>(() => settingsSerializer); Check.IfIsNull(projectLoader).Throw<ArgumentNullException>(() => projectLoader); Check.IfIsNull(projectOpener).Throw<ArgumentNullException>(() => projectOpener); this.projectLoader = projectLoader; this.projectOpener = projectOpener; var settings = settingsSerializer.Read(); recentProjects = settings.RecentProjects; }
public TrayIconPresenter(ITrayView view, ISettingsSerializer settingsSerializer) { _settingsSerializer = settingsSerializer; _view = view; _view.CurrentSettings = _settingsSerializer.Deserialize(); _view.ExitClicked += HandleExitClicked; _view.SettingsChanged += HandleSettingsChanged; _view.ShowMainClicked += HandleShowMainClicked; _view.ShowSettingsClicked += HandleShowSettingsClicked; //Show tray icon at once _view.ShowView(); }
public TrayIconPresenter(ITrayView view, ISettingsSerializer settingsSerializer) { _settingsSerializer = settingsSerializer; _view = view; _view.CurrentSettings = _settingsSerializer.Deserialize(); _view.ExitClicked += HandleExitClicked; _view.SettingsChanged += HandleSettingsChanged; _view.ShowMainClicked += HandleShowMainClicked; _view.ShowSettingsClicked +=HandleShowSettingsClicked; //Show tray icon at once _view.ShowView(); }
public StartupWindowViewModel Setup(ISettingsSerializer settingsSerializer = null, IProjectLoader projectLoader = null, IFileOpener<IProject> fileOpener = null) { projectLoader = projectLoader ?? new StubIProjectLoader(); fileOpener = fileOpener ?? new StubIFileOpener<IProject>(); settingsSerializer = settingsSerializer ?? new StubISettingsSerializer { Read = () => new StubIEditorSettings { RecentProjectsGet = () => recentProjects } }; return new StartupWindowViewModel(settingsSerializer, projectLoader, fileOpener); ; }
//------------------------------------------------------------------------------ static void DoSerializerInitialization(ISettingsSerializer serializer) { var initializer = serializer as ISettingsSerializerInitializer; if (initializer == null) { return; } var serializerType = serializer.GetType(); var contains = s_InitializedSerializers.Contains(serializerType); if (contains == false) { initializer.Initialize(); s_InitializedSerializers.Add(serializerType); } }
public SettingsAutoExpoter( string filePath, string tempFilePath, SettingsContainer settings, ISettingsSerializer serializer, TimeSpan throttlingInterval) { if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } if (tempFilePath == null) { throw new ArgumentNullException(nameof(tempFilePath)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } this.Serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); // ファイルを開く this.Stream = new FileStream(tempFilePath, FileMode.Create, FileAccess.Write, FileShare.Read); this.Disposables.Add(this.Stream); // 設定変更を監視 var subscription = Observable.FromEventPattern <SettingChangeEventArgs>(settings, "SettingChanged") .Throttle(throttlingInterval) .Subscribe(args => { try { this.Export(filePath, tempFilePath, settings); this.Exported?.Invoke(this, new EventArgs()); } catch (Exception ex) { this.Error?.Invoke(this, new ErrorEventArgs(ex)); } }); this.Disposables.Add(subscription); }
public void SerializeTest(IDistributedPropertySet data, ISettingsSerializer serializer) { byte[] result = null; try { result = serializer.Serialize(data); _output.WriteLine(Encoding.UTF8.GetString(result)); } catch (Exception e) { _output.WriteLine(e.ToString()); e.Data.Keys.Cast <string>().ToList().ForEach(key => _output.WriteLine(e.Data[key].ToString())); throw; } Assert.NotNull(result); Assert.NotEmpty(result); }
/// <summary> /// 監視を開始する。 /// </summary> public void StartMonitoring() { if (IsMonitoring) { throw new InvalidOperationException("既に監視中です。"); } try { // シリアライザを作成 try { serializer_ = new DataContractSettingsSerializer(Logger); } catch (Exception ex) { throw new Exception("シリアライザの作成に失敗しました。", ex); } // 保存用ファイルのストリームを開く try { // stream_.SetLength(0)のために必ず FileAccess.ReadWrite を指定! stream_ = new FileStream(SettingsTempFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read); } catch (Exception ex) { serializer_ = null; throw new Exception("設定書き出し用ファイルの作成に失敗しました。", ex); } // 設定変更の監視を開始 Settings.PropertyChanged += Settings_PropertyChanged; saveTimer = new Timer(SaveDelay); saveTimer.AutoReset = false; saveTimer.Elapsed += saveTiemr__Elapsed; IsMonitoring = true; } catch (Exception ex) { IsMonitoring = false; throw ex; } }
//------------------------------------------------------------------------------ static void DoSerializerEndAction(ISettingsSerializer serializer, SettingsEnumerationMode mode) { var generalNotificationSink = serializer as ISerializerNotificationSink; if (generalNotificationSink != null) { switch (mode) { case SettingsEnumerationMode.Load: generalNotificationSink.OnEndLoadSettings(); break; case SettingsEnumerationMode.Save: generalNotificationSink.OnEndSaveSettings(); break; case SettingsEnumerationMode.Delete: generalNotificationSink.OnEndDeleteSettings(); break; } generalNotificationSink.OnEndSerializerAction(); } }
//------------------------------------------------------------------------------ internal static void SetForegroundSerializer(ISettingsSerializer serializer) { s_foregroundSerializer = serializer; }
public Settings(ISettingsSerializer serializer, string settingsFileName = "settings") { this.RootElement = new SettingsElement(); _serializer = serializer; _settingsFileName = settingsFileName; }
public SettingsAutoSaverService(SettingsContainer settingsContainer, ISettingsSerializer settingsSerializer, TimeSpan throttlingInterval) { this.SettingsContainer = settingsContainer ?? throw new ArgumentNullException(nameof(settingsContainer)); this.SettingsSerializer = settingsSerializer ?? throw new ArgumentNullException(nameof(settingsSerializer)); this.ThrottlingInterval = throttlingInterval; }
//------------------------------------------------------------------------------ IEnumerable <string> LoadDynamicSettingsCustomOrder(ISettingsSerializer serializer, Type settingsClassType) { var settingsCustomOrderFullName = SettingNameFormatInfo.GetFullDynamicSettingsCustomOrderSettingName(serializer as ISettingsSerializerWishes, settingsClassType); return(LoadDynamicSettingsOrderImpl(settingsCustomOrderFullName, serializer, settingsClassType)); }
//------------------------------------------------------------------------------ void SaveDynamicSettingsOrderImpl(string settingsOrderSettingName, IEnumerable <string> settingsNames, ISettingsSerializer serializer, Type settingsType, ref SettingsHelperData settingsHelperData) { if (settingsNames != null && settingsNames.Count() > 0) { var simpleSettingsNamesCount = settingsNames.Count(); StringBuilder builder = new StringBuilder(); foreach (var settingName in settingsNames) { builder.Append(settingName); simpleSettingsNamesCount--; if (simpleSettingsNamesCount != 0) { builder.Append(","); } } string settingsOrderValue = builder.ToString(); var inSettingInfo = new SettingInfo() { SettingName = settingsOrderSettingName, SettingValue = settingsOrderValue, SettingValueType = settingsOrderValue.GetType(), }; ProcessArbitraryDynamicSetting(inSettingInfo, SettingsEnumerationMode.Save, ref settingsHelperData); return; } bool contains = false; try { contains = serializer.Contains(settingsOrderSettingName, false, null); } catch (NotSupportedException) { } if (contains) { var inSettingInfo = new SettingInfo() { SettingName = settingsOrderSettingName, }; ProcessArbitraryDynamicSetting(inSettingInfo, SettingsEnumerationMode.Delete, ref settingsHelperData); } }
public DefaultJsonSettingsDatabase(ISettingsSerializer settingsSerializer, IJsonSettingsSerializer jsonSettingsSerializer) { this.SettingsSerializer = settingsSerializer; this.JsonSettingsSerializer = jsonSettingsSerializer; }
// Constructor. public TestSettings(int version, ISettingsSerializer serializer) : base(serializer) { this.Version = version; }
public TestSettings(TestSettings template, ISettingsSerializer serializer) : base(template, serializer) { this.Version = template.Version; }
public CachingJsonSettingsDatabase(IJsonSettingsSerializer jsonSettingsSerializer, ISettingsSerializer settingsSerializer) : base(jsonSettingsSerializer, settingsSerializer) { }
public void SetUp() { _registryService = new FakeRegistryService(); _settingsSerializer = new SettingsSerializer(_registryService, SettingsFilePath); DirectoryUtility.EnsureClearFolder(TempFolder); }