private static ToolWindowStateSolutionData ParseOldJsonFormat(JObject obj, VisualStudioHelper vsHelper)
        {
            var result = new ToolWindowStateSolutionData();

            foreach (var prop in obj.Properties())
            {
                var projectState = ToolWindowProjectDataSerializer.ParseOldJsonFormat(prop.Value);

                var projectName  = prop.Name;
                var projectGuid  = vsHelper.ProjectGuidForProjetName(projectName);
                var enabledItems = from item in projectState.Items
                                   where item.Enabled
                                   select item.Id;

                result.ProjectArguments.Add(projectGuid, projectState);
                result.CheckedArguments.AddRange(enabledItems);
            }

            return(result);
        }
Ejemplo n.º 2
0
        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 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);
        }