protected override void OnSaveOptions(string key, Stream stream) { base.OnSaveOptions(key, stream); if (key == SolutionOptionKey) { Logger.Info("Saving all commands."); if (IsVcsSupportEnabled) { Logger.Info("VcsSupport is enabled."); foreach (EnvDTE.Project project in vsHelper.FindAllProjects()) { ViewModel.ListViewModel vm = null; if (ToolWindowViewModel.SolutionArguments.TryGetValue(project, out vm)) { string filePath = FullFilenameForProjectJsonFile(project); FileSystemWatcher fsWatcher = projectFsWatchers.GetValueOrDefault(project); if (vm.DataCollection.Count != 0) { using (fsWatcher?.TemporarilyDisable()) { try { using (Stream fileStream = File.Open(filePath, FileMode.Create, FileAccess.Write)) { Logic.ToolWindowProjectDataSerializer.Serialize(vm, fileStream); } } catch (Exception e) { Logger.Warn($"Failed to write to file '{filePath}' with error '{e}'."); } } } else if (File.Exists(filePath)) { Logger.Info("Deleting json file because command list is empty but json-file exists."); try { File.Delete(filePath); } catch (Exception e) { Logger.Warn($"Failed to delete file '{filePath}' with error '{e}'."); } } } } } Logic.ToolWindowSolutionDataSerializer.Serialize(ToolWindowViewModel, stream); } Logger.Info("All Commands Saved."); }
private void SaveJsonForProject(IVsHierarchy project) { if (!cmdPackage.IsVcsSupportEnabled || project == null) { return; } var guid = project.GetGuid(); var vm = cmdPackage.ToolWindowViewModel.TreeViewModel.Projects.GetValueOrDefault(guid); string filePath = FullFilenameForProjectJsonFileFromProject(project); FileSystemWatcher fsWatcher = projectFsWatchers.GetValueOrDefault(guid); if (vm != null && vm.Items.Any()) { using (fsWatcher?.TemporarilyDisable()) { // Tell VS that we're about to change this file // This matters if the user has TFVC with server workpace (see #57) if (!vsHelper.CanEditFile(filePath)) { Logger.Error($"VS or the user did no let us edit our file :/"); } else { try { using (Stream fileStream = File.Open(filePath, FileMode.Create, FileAccess.Write)) { ProjectDataSerializer.Serialize(vm, fileStream); } } catch (Exception e) { Logger.Warn($"Failed to write to file '{filePath}' with error '{e}'."); } } } } else if (File.Exists(filePath)) { Logger.Info("Deleting json file because command list is empty but json-file exists."); try { File.Delete(filePath); } catch (Exception e) { Logger.Warn($"Failed to delete file '{filePath}' with error '{e}'."); } } }
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}'."); } } } } }
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}'."); } } } }
private void SaveJsonForProject(IVsHierarchy project) { if (!IsVcsSupportEnabled || project == null) { return; } var guid = project.GetGuid(); var vm = ToolWindowViewModel.TreeViewModel.Projects.GetValueOrDefault(guid); string filePath = FullFilenameForProjectJsonFileFromProject(project); FileSystemWatcher fsWatcher = projectFsWatchers.GetValueOrDefault(guid); if (vm != null && vm.Items.Any()) { using (fsWatcher?.TemporarilyDisable()) { try { using (Stream fileStream = File.Open(filePath, FileMode.Create, FileAccess.Write)) { Logic.ToolWindowProjectDataSerializer.Serialize(vm, fileStream); } } catch (Exception e) { Logger.Warn($"Failed to write to file '{filePath}' with error '{e}'."); } } } else if (File.Exists(filePath)) { Logger.Info("Deleting json file because command list is empty but json-file exists."); try { File.Delete(filePath); } catch (Exception e) { Logger.Warn($"Failed to delete file '{filePath}' with error '{e}'."); } } }
private void SaveJsonForProject(Project project) { if (!IsVcsSupportEnabled || project == null) { return; } ListViewModel vm = ToolWindowViewModel.SolutionArguments[project.UniqueName]; string filePath = FullFilenameForProjectJsonFileFromProject(project); FileSystemWatcher fsWatcher = projectFsWatchers.GetValueOrDefault(project.UniqueName); if (vm.DataCollection.Count != 0) { using (fsWatcher?.TemporarilyDisable()) { try { using (Stream fileStream = File.Open(filePath, FileMode.Create, FileAccess.Write)) { Logic.ToolWindowProjectDataSerializer.Serialize(vm, fileStream); } } catch (Exception e) { Logger.Warn($"Failed to write to file '{filePath}' with error '{e}'."); } } } else if (File.Exists(filePath)) { Logger.Info("Deleting json file because command list is empty but json-file exists."); try { File.Delete(filePath); } catch (Exception e) { Logger.Warn($"Failed to delete file '{filePath}' with error '{e}'."); } } }