Exemplo n.º 1
0
        public void SaveProject(IVsHierarchy project)
        {
            if (!cmdPackage.IsUseSolutionDirEnabled)
            {
                SaveJsonForProject(project);
            }
            else
            {
                string slnFilename  = vsHelper.GetSolutionFilename();
                string jsonFilename = Path.ChangeExtension(slnFilename, "args.json");

                using (solutionFsWatcher?.TemporarilyDisable())
                {
                    if (cmdPackage.ToolWindowViewModel.TreeViewModel.AllArguments.Any())
                    {
                        if (!vsHelper.CanEditFile(jsonFilename))
                        {
                            Logger.Error($"VS or the user did no let us edit our file :/ '{jsonFilename}'");
                        }
                        else
                        {
                            try
                            {
                                using (Stream fileStream = File.Open(jsonFilename, FileMode.Create, FileAccess.Write))
                                {
                                    SolutionDataSerializer.Serialize(cmdPackage.ToolWindowViewModel, fileStream);
                                }
                            }
                            catch (Exception e)
                            {
                                Logger.Warn($"Failed to write to file '{jsonFilename}' with error '{e}'.");
                            }
                        }
                    }
                    else
                    {
                        Logger.Info("Deleting solution json file because no project has command arguments but json file exists.");

                        try
                        {
                            File.Delete(jsonFilename);
                        }
                        catch (Exception e)
                        {
                            Logger.Warn($"Failed to delete file '{jsonFilename}' with error '{e}'.");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void SaveJsonForSolution()
        {
            if (!cmdPackage.IsVcsSupportEnabled)
            {
                return;
            }

            string jsonFilename = FullFilenameForSolutionJsonFile();

            using (solutionFsWatcher?.TemporarilyDisable())
            {
                if (cmdPackage.ToolWindowViewModel.TreeViewModel.AllArguments.Any())
                {
                    if (!vsHelper.CanEditFile(jsonFilename))
                    {
                        Logger.Error($"VS or the user did no let us edit our file :/ '{jsonFilename}'");
                    }
                    else
                    {
                        try
                        {
                            using (Stream fileStream = File.Open(jsonFilename, FileMode.Create, FileAccess.Write))
                            {
                                SolutionDataSerializer.Serialize(cmdPackage.ToolWindowViewModel, fileStream);
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.Warn($"Failed to write to file '{jsonFilename}' with error '{e}'.");
                        }
                    }
                }
                else
                {
                    Logger.Info("Deleting solution json file because no project has command arguments but json file exists.");

                    try
                    {
                        File.Delete(jsonFilename);
                    }
                    catch (Exception e)
                    {
                        Logger.Warn($"Failed to delete file '{jsonFilename}' with error '{e}'.");
                    }
                }
            }
        }