public static void Serialize(ListViewModel vm, Stream stream) { if (vm == null) { throw new ArgumentNullException(nameof(vm)); } if (stream == null) { throw new ArgumentNullException(nameof(stream)); } var data = new ToolWindowStateProjectData(); foreach (var item in vm.DataCollection) { data.DataCollection.Add(new ToolWindowStateProjectData.ListEntryData() { Id = item.Id, Command = item.Command, //Project = item.Project, // deprecated //Enabled = item.Enabled }); } string jsonStr = JsonConvert.SerializeObject(data, Formatting.Indented); StreamWriter sw = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); sw.Write(jsonStr); sw.Flush(); }
public static ToolWindowStateSolutionData Serialize(ToolWindowViewModel vm, Stream stream) { if (vm == null) { throw new ArgumentNullException(nameof(vm)); } if (stream == null) { throw new ArgumentNullException(nameof(stream)); } var data = new ToolWindowStateSolutionData(); foreach (var kvp in vm.SolutionArguments) { var list = new ToolWindowStateProjectData(); data.Add(kvp.Key, list); foreach (var item in kvp.Value.DataCollection) { list.DataCollection.Add(new ToolWindowStateProjectData.ListEntryData() { Id = item.Id, Command = item.Command, //Project = item.Project, // deprecated Enabled = item.Enabled }); } } string jsonStr = JsonConvert.SerializeObject(data); StreamWriter sw = new StreamWriter(stream); sw.Write(jsonStr); sw.Flush(); return(data); }
public static ToolWindowStateProjectData ParseOldJsonFormat(JToken root) { var result = new ToolWindowStateProjectData(); if (root is JObject) { foreach (var item in root["DataCollection"]) { var listItem = new ListEntryData(); result.Items.Add(listItem); listItem.Command = (string)item["Command"]; listItem.Enabled = ((bool?)item["Enabled"]).GetValueOrDefault(); if (Guid.TryParse((string)item["Id"], out Guid parsedID)) { listItem.Id = parsedID; } } } return(result); }
public static ToolWindowStateSolutionData Serialize(ToolWindowViewModel vm, Stream stream) { if (vm == null) { throw new ArgumentNullException(nameof(vm)); } if (stream == null) { throw new ArgumentNullException(nameof(stream)); } var data = new ToolWindowStateSolutionData(); data.ShowAllProjects = vm.TreeViewModel.ShowAllProjects; data.CheckedArguments = new HashSet <Guid>(vm.TreeViewModel.Projects.Values.SelectMany(p => p.CheckedArguments).Select(arg => arg.Id)); data.ExpandedContainer = new HashSet <Guid>(vm.TreeViewModel.Projects.Values.SelectMany(p => p.ExpandedContainer).Select(con => con.Id) .Concat(vm.TreeViewModel.Projects.Values.Where(p => p.IsExpanded).Select(p => p.Id))); foreach (var kvPair in vm.TreeViewModel.Projects) { var list = new ToolWindowStateProjectData { Id = kvPair.Value.Id, Items = TransformCmdList(kvPair.Value.Items) }; data.ProjectArguments.Add(kvPair.Key, list); } string jsonStr = JsonConvert.SerializeObject(data); StreamWriter sw = new StreamWriter(stream); sw.Write(jsonStr); sw.Flush(); return(data); }
public static void Serialize(CmdProject prj, Stream stream) { if (prj == null) { throw new ArgumentNullException(nameof(prj)); } if (stream == null) { throw new ArgumentNullException(nameof(stream)); } var data = new ToolWindowStateProjectData { Id = prj.Id, Items = TransformCmdList(prj.Items) }; string jsonStr = JsonConvert.SerializeObject(data, Formatting.Indented); StreamWriter sw = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); sw.Write(jsonStr); sw.Flush(); }