/// <summary> /// Load snapshot debug setting from stream /// </summary> public bool LoadConfigSettings(Stream stream) { Assumes.ThrowIfNull(stream, nameof(stream)); BinaryFormatter formatter = new BinaryFormatter(); try { if (stream.Length > 0) { SnapshotDebugUserSettings userSettings = formatter.Deserialize(stream) as SnapshotDebugUserSettings; if (SnapshotDebugUserSettings.VersionMatch(userSettings?.Version)) { if (userSettings.DebugConfigs?.Count() > 0) { _mruDictionary = userSettings.DebugConfigs.ToDictionary(p => p.Key, p => new MRUList <SnapshotDebugConfig>(p.Value.ToList())); // Guid.empty means all MRU lists are changed ConfigListChanged?.Invoke(this, _mruDictionary.Select(p => p.Key)); } return(true); } } } catch (SerializationException e) { Assumes.Fail(e.ToString()); } return(false); }
/// <summary> /// Save snapshot debug setting into stream /// </summary> public bool SaveConfigSettings(Stream stream) { Assumes.ThrowIfNull(stream, nameof(stream)); Dictionary <Guid, IEnumerable <SnapshotDebugConfig> > configs = _mruDictionary. ToDictionary(p => p.Key, p => p.Value.GetItems() as IEnumerable <SnapshotDebugConfig>); SnapshotDebugUserSettings userSetting = new SnapshotDebugUserSettings(configs); if (userSetting.DebugConfigs.Count() == 0) { return(false); } BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(stream, userSetting); } catch (SerializationException e) { Assumes.Fail(e.ToString()); return(false); } return(true); }