public bool DoSettingsNeedToBeUpdated(string newFileVersion) { if (FileVersion.Equals(newFileVersion, StringComparison.InvariantCultureIgnoreCase) && StoredSettingsVersion == 2) { return(!remoteSettingsStorage.CollectionExists(CurrentCollectionPath)); } return(true); }
public static async Task CheckCompatibilityAsync(this IBackupReader reader) { var current = await reader.ReadVersionAsync(); if (!Expected.Equals(current)) { throw new BackupRestoreException("Backup file is not compatible with this version."); } }
private void SetupSerializer() { ser.Formatting = Formatting.None; ser.TypeNameHandling = TypeNameHandling.Auto; if (FileVersion.Equals("1")) { ser.Converters.Add(new GestureIntentConverter_V1()); } else //if (FileVersion.Equals("2")) { ser.Converters.Add(new GestureIntentConverter()); } }
private void Deserialize(Stream stream, bool closeStream) { if (stream == null || !stream.CanRead) { throw new ArgumentException("stream"); } try { using (var txtReader = new StreamReader(stream)) using (var jsonReader = new JsonTextReader(txtReader)) { var ser = new JsonSerializer(); ser.Formatting = Formatting.None; ser.TypeNameHandling = TypeNameHandling.Auto; if (FileVersion.Equals("1")) { ser.Converters.Add(new GestureIntentConverter_V1()); } else if (FileVersion.Equals("2")) { ser.Converters.Add(new GestureIntentConverter()); } var result = ser.Deserialize <SerializeWrapper>(jsonReader); FileVersion = result.FileVersion; GlobalApp = result.Global; //Apps = result.Apps; Apps = new Dictionary <string, ExeApp>(); //to lower foreach (var a in result.Apps.Values) { a.ExecutablePath = a.ExecutablePath.ToLower(); Apps.Add(a.ExecutablePath, a); } HotCornerCommands = result.HotCornerCommands; } } finally { if (closeStream) { stream.Dispose(); } } //todo: 完全在独立domain中加载json.net? /*var deserializeDomain = AppDomain.CreateDomain("jsonDeserialize"); * deserializeDomain.UnhandledException += (sender, args) => { throw new IOException(args.ExceptionObject.ToString()); }; * deserializeDomain.DomainUnload += (sender, args) => * { * Console.WriteLine("deserializeDomain Unloaded"); * }; * var wrapperRef = (ISerializeWrapper)deserializeDomain.CreateInstanceAndUnwrap("SerializeWrapper", "SerializeWrapper.SerializeWrapper"); * * wrapperRef.DeserializeFromStream(stream, FileVersion, closeStream); * * GlobalApp = wrapperRef.Global; * Apps = wrapperRef.Apps; * * wrapperRef = null; * * GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); * GC.WaitForPendingFinalizers(); * * AppDomain.Unload(deserializeDomain); * deserializeDomain = null; * * GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); * GC.WaitForPendingFinalizers();*/ }