/// <summary> /// This function is the callback used to execute a command when the a menu item is clicked. /// See the Initialize method to see how the menu item is associated to this function using /// the OleMenuCommandService service and the MenuCommand class. /// </summary> private async Task RegisterModifyPluginCallbackAsync(object sender, EventArgs args) { try { var session = Math.Abs(DateTime.Now.ToString(CultureInfo.CurrentCulture).GetHashCode()); Status.Update($">>>>> Starting new session: {session} <<<<<"); var selected = DteHelper.GetSelectedProjects().ToArray(); if (!selected.Any()) { throw new UserException("Please select a project first."); } foreach (var project in selected) { Status.Update($">>> Processing project: {DteHelper.GetProjectName(project)} <<<"); DteHelper.SetCurrentProject(project); AssemblyHelper.BuildProject(); await RegisterModifyPluginAsync(); Status.Update($"^^^ Finished processing project: {DteHelper.GetProjectName(project)} ^^^"); } Status.Update($"^^^^^ Finished session: {session} ^^^^^"); } catch (UserException e) { VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, e.Message, "Error", OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } catch (Exception e) { var error1 = "[ERROR] " + e.Message + (e.InnerException != null ? "\n" + "[ERROR] " + e.InnerException.Message : ""); Status.Update(error1); Status.Update(e.StackTrace); Status.Update("Unable to register assembly, see error above."); var error2 = e.Message + "\n" + e.StackTrace; MessageBox.Show(error2, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { Status.Update(">>>>> DONE! <<<<<"); } }
private void CopySettingsCallback(object sender, EventArgs args) { try { var session = Math.Abs(DateTime.Now.ToString(CultureInfo.CurrentCulture).GetHashCode()); Status.Update($">>>>> Starting new session: {session} <<<<<"); var selected = DteHelper.GetSelectedProjects().ToArray(); if (selected.Length < 2) { throw new UserException("Please select at least two projects first."); } Status.Update($">>> Processing copy <<<"); if (!CopySettings()) { throw new UserException("Couldn't find settings in any of the selected projects to copy."); } Status.Update($"^^^ Finished processing copy ^^^"); Status.Update($"^^^^^ Finished session: {session} ^^^^^"); } catch (UserException e) { VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, e.Message, "Error", OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } catch (Exception e) { var error1 = "[ERROR] " + e.Message + (e.InnerException != null ? "\n" + "[ERROR] " + e.InnerException.Message : ""); Status.Update(error1); Status.Update(e.StackTrace); Status.Update("Unable to update assembly, see error above."); var error2 = e.Message + "\n" + e.StackTrace; MessageBox.Show(error2, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { Status.Update(">>>>> DONE! <<<<<"); } }
private static bool CopySettings() { var projects = DteHelper.GetSelectedProjects().ToArray(); if (projects.Length <= 1) { return(false); } var currentProject = DteHelper.CurrentProject; SettingsArray sourceSettingsArray = null; foreach (var project in projects) { DteHelper.SetCurrentProject(project); sourceSettingsArray = Configuration.LoadConfigs(); var settings = sourceSettingsArray.GetSelectedSettings(); if (settings.Id == Guid.Empty && (string.IsNullOrEmpty(settings.ServerName) || string.IsNullOrEmpty(settings.Username))) { continue; } else { break; } } if (sourceSettingsArray == null) { return(false); } Status.Update($"Copying settings from project: {DteHelper.CurrentProject.Name} ..."); foreach (var settingsQ in sourceSettingsArray.SettingsList) { settingsQ.Id = Guid.Empty; } foreach (var project in projects) { DteHelper.SetCurrentProject(project); var settingsArray = Configuration.LoadConfigs(); var settings = settingsArray.GetSelectedSettings(); if (settings.Id == Guid.Empty && (string.IsNullOrEmpty(settings.ServerName) || string.IsNullOrEmpty(settings.Username))) { Configuration.SaveConfigs(sourceSettingsArray); Status.Update($"Copied settings to project: {project.Name}."); } } DteHelper.SetCurrentProject(currentProject); return(true); }