public void CanSerializeDomainObjectWithJsonFormatter() { using (Stream _formattedTemplate = new FileStream(this._provisioningTemplatePath5, FileMode.Open, FileAccess.Read, FileShare.Read)) { ITemplateFormatter formatter = XMLPnPSchemaFormatter.GetSpecificFormatter(this._provisioningTemplatePath5NamespaceURI); XMLTemplateProvider xmlProvider = new XMLFileSystemTemplateProvider( String.Format(@"{0}\..\..\Resources", AppDomain.CurrentDomain.BaseDirectory), "Templates"); formatter.Initialize(xmlProvider); var _pt = formatter.ToProvisioningTemplate(_formattedTemplate, "WORKFLOWSITE"); JsonTemplateProvider jsonProvider = new JsonFileSystemTemplateProvider( String.Format(@"{0}\..\..\Resources", AppDomain.CurrentDomain.BaseDirectory), "Templates"); jsonProvider.SaveAs(_pt, @"c:\temp\ProvisioningSchema-2015-05-ReferenceSample-01.json"); var _ptBack = jsonProvider.GetTemplate(@"c:\temp\ProvisioningSchema-2015-05-ReferenceSample-01.json"); Assert.IsTrue(_pt.Equals(_ptBack)); } }
public void CanHandleDomainObjectWithJsonFormatter() { using (Stream _formattedTemplate = new FileStream(this._provisioningTemplatePath7, FileMode.Open, FileAccess.Read, FileShare.Read)) { ITemplateFormatter formatter = new JsonPnPFormatter(); JsonTemplateProvider provider = new JsonFileSystemTemplateProvider( String.Format(@"{0}\..\..\..\Resources", AppDomain.CurrentDomain.BaseDirectory), "Templates"); formatter.Initialize(provider); var _pt = formatter.ToProvisioningTemplate(_formattedTemplate, "WORKFLOWSITE"); var _formattedTemplateBack = formatter.ToFormattedTemplate(_pt); Assert.IsNotNull(_formattedTemplateBack); } }
public SPCopyListCopyResult SPCopyList(string sourceSite, string targetSite, string listName, SPCopyListCopyOptions options) { SPCopyListCopyResult result = new SPCopyListCopyResult(); CheckConnected(); Web web = SourceContext.Web; ProvisioningTemplateCreationInformation ptci = new ProvisioningTemplateCreationInformation(web); JsonTemplateProvider jsonProvider = new JsonFileSystemTemplateProvider(); var template = web.GetProvisioningTemplate(); template.Lists.RemoveAll(l => l.Title != listName); Web targetWeb = TargetContext.Web; var ptai = new ProvisioningTemplateApplyingInformation(); ptai.HandlersToProcess = Handlers.Lists; TargetContext.Load(targetWeb.Lists); TargetContext.ExecuteQueryRetry(); bool listExists = ListExists(listName, targetWeb.Lists); //TODO - remove var debugList = template.Lists.Find(l => l.Title == listName); if (options == SPCopyListCopyOptions.AbortOnDuplicate) { if (listExists) { result.Conflict = true; result.ListCopied = false; result.ConflictAction = SPCopyListCopyResult.SPCopyListConflictAction.Aborted; } else { result.Conflict = false; result.ListCopied = true; result.ConflictAction = SPCopyListCopyResult.SPCopyListConflictAction.None; targetWeb.ApplyProvisioningTemplate(template, ptai); } } else if (options == SPCopyListCopyOptions.Merge) { if (listExists) { result.Conflict = true; result.ListCopied = true; result.ConflictAction = SPCopyListCopyResult.SPCopyListConflictAction.Merged; } else { result.Conflict = false; result.ListCopied = true; result.ConflictAction = SPCopyListCopyResult.SPCopyListConflictAction.None; } targetWeb.ApplyProvisioningTemplate(template, ptai); } else if (options == SPCopyListCopyOptions.Overwrite) { if (listExists) { result.Conflict = true; result.ListCopied = true; result.ConflictAction = SPCopyListCopyResult.SPCopyListConflictAction.Overwritten; DeleteTargetList(targetWeb, listName); } else { result.Conflict = false; result.ListCopied = true; result.ConflictAction = SPCopyListCopyResult.SPCopyListConflictAction.None; } targetWeb.ApplyProvisioningTemplate(template, ptai); } else if (options == SPCopyListCopyOptions.Rename) { if (listExists) { result.Conflict = true; result.ListCopied = true; result.ConflictAction = SPCopyListCopyResult.SPCopyListConflictAction.Renamed; var list = template.Lists.Find(l => l.Title == listName); list.Title = GenerateUniqueListName(targetWeb.Lists, listName); list.Url = AlignUrlWithTitle(list.Title, list.Url); } else { result.Conflict = false; result.ListCopied = true; result.ConflictAction = SPCopyListCopyResult.SPCopyListConflictAction.None; } targetWeb.ApplyProvisioningTemplate(template, ptai); } return(result); }