/// <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 void MenuItemCallback(object sender, EventArgs e) { // Show a Message Box to prove we were here IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); Guid clsid = Guid.Empty; DeployConfiguration config = new DeployConfiguration(); SettingsManager settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider); WritableSettingsStore userSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings); if (!userSettingsStore.CollectionExists("SyncIIS")) { userSettingsStore.CreateCollection("SyncIIS"); } config.Domain = userSettingsStore.GetString("SyncIIS", "Domain", ""); config.SetSecurePassword(userSettingsStore.GetString("SyncIIS", "Password", "")); config.Site = userSettingsStore.GetString("SyncIIS", "Site", ""); config.Source = userSettingsStore.GetString("SyncIIS", "Source", ""); config.Target = userSettingsStore.GetString("SyncIIS", "Target", "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToList <string>(); config.Username = userSettingsStore.GetString("SyncIIS", "Username", ""); SyncWindow window = new SyncWindow(config); window.ShowDialog(); var settings = window.Configuration; userSettingsStore.SetString("SyncIIS", "Domain", settings.Domain); userSettingsStore.SetString("SyncIIS", "Password", settings.GetUnsecurePassword()); userSettingsStore.SetString("SyncIIS", "Site", settings.Site); userSettingsStore.SetString("SyncIIS", "Source", settings.Source); userSettingsStore.SetString("SyncIIS", "Target", string.Join(",", settings.Target.ToArray())); userSettingsStore.SetString("SyncIIS", "Username", settings.Username); }
public SyncWindow(DeployConfiguration config) { InitializeComponent(); this.Configuration = config; txtDestination.Text = string.Join(",", config.Target.ToArray()); txtPassword.Password = config.GetUnsecurePassword(); txtSite.Text = config.Site; txtSource.Text = config.Source; txtUsername.Text = ( config.Domain == "" ? config.Username : config.Domain + @"\" + config.Username); }
/// <summary> /// Runs the web deploy executable and redirects output to the data /// received event. /// </summary> /// <param name="verb">Action to be performed</param> /// <param name="source">Source Machine</param> /// <param name="destination">Destination Machine</param> /// <param name="config">Configuration parameter for determining /// things like username, password, domain</param> private void RunProcess( string verb, string source, string destination, DeployConfiguration config) { var arguments = "{0} {1} {2}"; try { var proc = new Process(); proc.StartInfo.FileName = webDeployLocation + "msdeploy.exe"; proc.StartInfo.Arguments = string.Format(arguments, verb, source, destination); OutputGenerated(this, "Source:" + source + "\r\n"); OutputGenerated(this, "Destination:" + destination + "\r\n"); OutputGenerated(this, webDeployLocation + proc.StartInfo.FileName + " " + proc.StartInfo.Arguments + "\r\n"); proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.Domain = config.Domain; proc.StartInfo.UserName = config.Username; proc.StartInfo.Password = config.Password; proc.EnableRaisingEvents = true; proc.StartInfo.CreateNoWindow = true; proc.Exited += proc_Exited; proc.OutputDataReceived += (sender, e) => { OutputGenerated(sender, e.Data + "\r\n"); }; proc.ErrorDataReceived += (sender, e) => { OutputGenerated(sender, e.Data + "\r\n"); }; proc.Start(); proc.BeginErrorReadLine(); proc.BeginOutputReadLine(); } catch (Exception e) { OutputGenerated(this, e.StackTrace + e.Message.ToString() + "\r\n"); } }
/// <summary> /// Calls Web Deploy (repeatedly, if necessary) given a certain /// configuration. /// </summary> /// <param name="config"></param> public void Deploy(DeployConfiguration config) { var verb = "-verb:sync"; var source = "-source:appHostConfig=\"{0}\",computername={1}"; var destination = "-dest:appHostConfig=\"{0}\",computername={1}"; source = string.Format(source, config.Site, config.Source); if (!SetWebDeployLocation()) { return; } foreach (var dest in config.Target) { RunProcess( verb, source, string.Format(destination, config.Site, dest), config); } }
/// <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 void MenuItemCallback(object sender, EventArgs e) { // Show a Message Box to prove we were here IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); Guid clsid = Guid.Empty; DeployConfiguration config = new DeployConfiguration(); SettingsManager settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider); WritableSettingsStore userSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings); if (!userSettingsStore.CollectionExists("SyncIIS")) { userSettingsStore.CreateCollection("SyncIIS"); } config.Domain = userSettingsStore.GetString("SyncIIS", "Domain", ""); config.SetSecurePassword(userSettingsStore.GetString("SyncIIS", "Password", "")); config.Site = userSettingsStore.GetString("SyncIIS", "Site", ""); config.Source = userSettingsStore.GetString("SyncIIS", "Source", ""); config.Target = userSettingsStore.GetString("SyncIIS", "Target", "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToList<string>(); config.Username = userSettingsStore.GetString("SyncIIS", "Username", ""); SyncWindow window = new SyncWindow(config); window.ShowDialog(); var settings = window.Configuration; userSettingsStore.SetString("SyncIIS", "Domain", settings.Domain); userSettingsStore.SetString("SyncIIS", "Password", settings.GetUnsecurePassword()); userSettingsStore.SetString("SyncIIS", "Site", settings.Site); userSettingsStore.SetString("SyncIIS", "Source", settings.Source); userSettingsStore.SetString("SyncIIS", "Target", string.Join(",", settings.Target.ToArray())); userSettingsStore.SetString("SyncIIS", "Username", settings.Username); }
/// <summary> /// Runs the web deploy executable and redirects output to the data /// received event. /// </summary> /// <param name="verb">Action to be performed</param> /// <param name="source">Source Machine</param> /// <param name="destination">Destination Machine</param> /// <param name="config">Configuration parameter for determining /// things like username, password, domain</param> private void RunProcess( string verb, string source, string destination, DeployConfiguration config) { var arguments = "{0} {1} {2}"; try { var proc = new Process(); proc.StartInfo.FileName = webDeployLocation + "msdeploy.exe"; proc.StartInfo.Arguments = string.Format(arguments, verb, source, destination); OutputGenerated(this, "Source:" + source + "\r\n"); OutputGenerated(this, "Destination:" + destination + "\r\n"); OutputGenerated(this, webDeployLocation + proc.StartInfo.FileName + " " + proc.StartInfo.Arguments + "\r\n"); proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.Domain = config.Domain; proc.StartInfo.UserName = config.Username; proc.StartInfo.Password = config.Password; proc.EnableRaisingEvents = true; proc.StartInfo.CreateNoWindow = true; proc.Exited += proc_Exited; proc.OutputDataReceived += (sender, e) => { OutputGenerated(sender, e.Data + "\r\n"); }; proc.ErrorDataReceived += (sender, e) => { OutputGenerated(sender, e.Data + "\r\n"); }; proc.Start(); proc.BeginErrorReadLine(); proc.BeginOutputReadLine(); } catch(Exception e) { OutputGenerated(this, e.StackTrace + e.Message.ToString() + "\r\n"); } }