private void GetUserCreds(ProvisioningTemplateToolsConfiguration config, string projectFolderPath, string credsFilePath) { ProvisioningCredentials creds = null; //prompt for credentials then persist to .user xml file VSToolsConfigWindow cfgWindow = new VSToolsConfigWindow(); cfgWindow.txtSiteUrl.Text = config.Deployment.TargetSite; cfgWindow.txtUsername.Text = config.Deployment.Credentials.Username; cfgWindow.ShowDialog(); bool saveNeeded = false; if (cfgWindow.DialogResult.HasValue && cfgWindow.DialogResult.Value) { config.Deployment.TargetSite = cfgWindow.txtSiteUrl.Text; creds = new ProvisioningCredentials() { Username = cfgWindow.txtUsername.Text, }; creds.SetSecurePassword(cfgWindow.txtPassword.Password); config.Deployment.Credentials = creds; saveNeeded = true; } if (saveNeeded) { //serialize the credentials to a file XmlHelpers.SerializeObject(config.Deployment.Credentials, credsFilePath); //save the config to a file SaveConfigForProject(projectFolderPath, config); //reset any cached sp contexts ProvisioningService.ResetSPContexts(); } }
private bool SaveConfigForProject(string projectFolderPath, ProvisioningTemplateToolsConfiguration config) { try { var configFilePath = Path.Combine(projectFolderPath, Resources.FileNameProvisioningTemplate); XmlHelpers.SerializeObject(config, configFilePath); var configItem = this.DTE.Solution.FindProjectItem(configFilePath); if (configItem == null) { var project = Helpers.ProjectHelpers.GetProject(); project.ProjectItems.AddFromFile(configFilePath); } } catch (Exception ex) { LogService.Exception("Error saving to config xml file", ex); return false; } return true; }
private ProvisioningTemplateLocationInfo GetParentProvisioningTemplateInformation(string projectItemFullPath, string projectFolderPath, ProvisioningTemplateToolsConfiguration config) { Models.ProvisioningTemplateLocationInfo templateInfo = null; try { templateInfo = ProjectHelpers.GetParentProvisioningTemplateInformation(projectItemFullPath, projectFolderPath, config); } catch (Exception ex) { LogService.Exception("GetParentProvisioningTemplateInformation", ex); } if (templateInfo == null) { LogService.Warn("Cannot determine template for the supplied item: " + projectItemFullPath); } return templateInfo; }