public async Task SaveSetting <T>(T value) { var name = GetSettingNameAttribute(typeof(T)); var settingValue = _settingsSerializer.Serialize(value); using (var connection = new ConScope(_dataService)) using (var transaction = await connection.BeginTransaction()) { var setting = await connection.Connection.SingleAsync(connection.Connection.From <SettingV1>().Where(x => x.Name == name)); if (setting == null) { setting = new SettingV1 { Name = name, Settings = settingValue }; await connection.Connection.SaveAsync(setting); } else { setting.Settings = settingValue; await connection.Connection.UpdateAsync(setting); } transaction.Commit(); } }
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]); } }
/// <summary> /// 設定を保存する。 /// </summary> void Save() { // ファイルを空にする try { stream_.SetLength(0); } catch (Exception ex) { throw new Exception("ファイルの初期化に失敗しました。", ex); } // 設定をシリアラズしてファイルに保存 try { serializer_.Serialize(stream_, Settings); } catch (Exception ex) { throw new Exception("設定のシリアライズに失敗しました。", ex); } // 一時ファイルから本来のファイルにコピーする try { File.Copy(SettingsTempFile, SettingsFile, true); } catch (Exception ex) { throw new Exception("設定の上書きに失敗しました。", ex); } // 変更フラグを折る lock (saveLock_) { isSettingsChanged_ = false; } }
public void Save() { if (!Directory.Exists(BasePath)) { Directory.CreateDirectory(BasePath); } File.WriteAllText(SettingsFilePath, _serializer.Serialize(RootElement)); }
public void TestSerialize() { ISettingsSerializer json = SettingsSerializerFactory.Get("JSON"); SettingsElement root = createTestElement(); string output = json.Serialize(root); Assert.IsTrue(output.Contains("FontFamily")); }
public void Save() { try { var xml = Serializer.Serialize(this); Keeper.Save(xml); } catch (Exception ex) { _Logger.Log(ex.Message, ex); } }
private void HandleSettingsChanged(object sender, EventArgs e) { ValidationResult validationResult = _settingsSerializer.Serialize(_view.CurrentSettings); if (validationResult.IsValid) { _view.HideView(); FireEvent(SettingsChanged, _view.CurrentSettings); } else { _view.ShowValidationResult(validationResult); } }
void settings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var settings = sender as SettingsImpl; if (settings != null) { var tag = GetTaggedKey(settings.Tag, true); string str = null; using (var ms = new MemoryStream()){ childSettingsSerializer_.Serialize(ms, settings); ms.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(ms)) { str = reader.ReadToEnd(); } } // 設定保存 Set(tag, str); } }
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); }
public void Serialize_FolderAndFileDontExist_FolderAndFileCreated() { Settings settings = new Settings { SupportedNavigators = new List <Navigators>() }; ValidationResult result = _settingsSerializer.Serialize(settings); Assert.That(File.Exists(SettingsFilePath), Is.True); Assert.That(result.IsValid, Is.True); }
private void HandleSettingsChanged(object sender, EventArgs e) { _settingsSerializer.Serialize(_view.CurrentSettings); FireEvent(SettingsChanged, _view.CurrentSettings); }