private bool AddItemToTemplate(string projectItemFullPath, LoadedXMLProvisioningTemplate loadedTemplate) { if (loadedTemplate != null && loadedTemplate.Template != null) { // Item is PnP resource. var src = ProvisioningHelper.MakeRelativePath(projectItemFullPath, loadedTemplate.ResourcesPath); var targetFolder = String.Join("/", Path.GetDirectoryName(src).Split('\\')); loadedTemplate.Template.Files.Add(new OfficeDevPnP.Core.Framework.Provisioning.Model.File() { Src = src, Folder = targetFolder, Overwrite = true, Security = null }); LogService.Info("Item added to template: " + src); return(true); } return(false); }
public async System.Threading.Tasks.Task <bool> DeployProvisioningTemplates(IEnumerable <DeployTemplateItem> templates) { if (IsBusy) { LogService.Warn("DeployProvisioningTemplates is busy processing pending requests."); return(false); } bool success = true; IsBusy = true; try { //this.ResetSPContextCollection(); this.ResetPendingTemplates(); this.AddToPendingTemplates(templates); await System.Threading.Tasks.Task.Run(() => { while (pendingTemplatesToDeploy.Count > 0) { var deployItem = pendingTemplatesToDeploy.Dequeue(); LogService.Info(string.Format("Start {1:t} - {0}...", deployItem.GetDeployTitle(), System.DateTime.Now)); var siteUrl = deployItem.Config.Deployment.TargetSite; var login = deployItem.Config.Deployment.Credentials.Username; try { var ctx = GetSPContext(siteUrl, login, deployItem.Config.Deployment.Credentials.GetSecurePassword()); ProvisioningTemplateApplyingInformation ptai = new ProvisioningTemplateApplyingInformation(); ptai.ProgressDelegate = delegate(string message, int step, int total) { LogService.Info(string.Format("Deploying {0}, Step {1}/{2}", message, step, total)); }; LogService.Info("Applying template..."); ctx.Web.ApplyProvisioningTemplate(deployItem.Template, ptai); success = true; } catch (Exception ex) { LogService.Info("Error during provisioning: " + ex.Message); success = false; } LogService.Info(string.Format("End {2:t} (success={1}) - {0}", deployItem.GetDeployTitle(), success, System.DateTime.Now)); } }); } catch (Exception ex) { success = false; LogService.Exception("DeployProvisioningTemplates", ex); this.ResetSPContexts(); } finally { IsBusy = false; //this.ResetSPContextCollection(); } return(success); }