static private LoadProvisioningTemplateFromFile ( String templatePath, String sessionPath, ITemplateProviderExtension templateProviderExtensions ) : OfficeDevPnP.Core.Framework.Provisioning.Model.ProvisioningTemplate | ||
templatePath | String | |
sessionPath | String | |
templateProviderExtensions | ITemplateProviderExtension | |
return | OfficeDevPnP.Core.Framework.Provisioning.Model.ProvisioningTemplate |
protected override void ProcessRecord() { WriteObject(LoadProvisioningTemplate .LoadProvisioningTemplateFromFile(Path, SessionState.Path.CurrentFileSystemLocation.Path, TemplateProviderExtensions)); }
protected override void ProcessRecord() { if (!System.IO.Path.IsPathRooted(Path)) { Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); } // Load the template var template = LoadProvisioningTemplate .LoadProvisioningTemplateFromFile(Path, TemplateProviderExtensions); if (template == null) { throw new ApplicationException("Invalid template file!"); } // Load the file and add it to the .PNP file using (var fs = new FileStream(Source, FileMode.Open, FileAccess.Read, FileShare.Read)) { Folder = Folder.Replace("\\", "/"); var fileName = Source.IndexOf("\\") > 0 ? Source.Substring(Source.LastIndexOf("\\") + 1) : Source; var container = !string.IsNullOrEmpty(Container) ? Container : string.Empty; var source = !string.IsNullOrEmpty(container) ? (container + "/" + fileName) : fileName; template.Connector.SaveFileStream(fileName, container, fs); if (template.Connector is ICommitableFileConnector) { ((ICommitableFileConnector)template.Connector).Commit(); } template.Files.Add(new OfficeDevPnP.Core.Framework.Provisioning.Model.File { Src = source, Folder = Folder, Overwrite = true, }); // Determine the output file name and path var outFileName = System.IO.Path.GetFileName(Path); var outPath = new FileInfo(Path).DirectoryName; var fileSystemConnector = new FileSystemConnector(outPath, ""); var formatter = XMLPnPSchemaFormatter.LatestFormatter; var extension = new FileInfo(Path).Extension.ToLowerInvariant(); if (extension == ".pnp") { XMLTemplateProvider provider = new XMLOpenXMLTemplateProvider(new OpenXMLConnector(outPath, fileSystemConnector)); var templateFileName = outFileName.Substring(0, outFileName.LastIndexOf(".", StringComparison.Ordinal)) + ".xml"; provider.SaveAs(template, templateFileName, formatter, TemplateProviderExtensions); } else { XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(Path, ""); provider.SaveAs(template, Path, formatter, TemplateProviderExtensions); } } }
protected override void ProcessRecord() { if (System.IO.Path.IsPathRooted(Path)) { Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path); } WriteObject(LoadProvisioningTemplate .LoadProvisioningTemplateFromFile(Path, TemplateProviderExtensions)); }
protected override void ProcessRecord() { if (!System.IO.Path.IsPathRooted(Path)) { Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); } // Load the template ProvisioningTemplate template = LoadProvisioningTemplate .LoadProvisioningTemplateFromFile(Path, TemplateProviderExtensions); if (template == null) { throw new ApplicationException("Invalid template file!"); } var fileToRemove = template.Files.FirstOrDefault(f => f.Src == FilePath); if (fileToRemove != null) { template.Files.Remove(fileToRemove); template.Connector.DeleteFile(FilePath); if (template.Connector is ICommitableFileConnector) { ((ICommitableFileConnector)template.Connector).Commit(); } // Determine the output file name and path var outFileName = System.IO.Path.GetFileName(Path); var outPath = new FileInfo(Path).DirectoryName; var fileSystemConnector = new FileSystemConnector(outPath, ""); var formatter = XMLPnPSchemaFormatter.LatestFormatter; var extension = new FileInfo(Path).Extension.ToLowerInvariant(); if (extension == ".pnp") { XMLTemplateProvider provider = new XMLOpenXMLTemplateProvider(new OpenXMLConnector(outPath, fileSystemConnector)); var templateFileName = outFileName.Substring(0, outFileName.LastIndexOf(".", StringComparison.Ordinal)) + ".xml"; provider.SaveAs(template, templateFileName, formatter, TemplateProviderExtensions); } else { XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(Path, ""); provider.SaveAs(template, Path, formatter, TemplateProviderExtensions); } } }
protected override void ProcessRecord() { if (String.IsNullOrEmpty(FilePath)) { throw new ArgumentNullException("FilePath"); } // Load the template ProvisioningTemplate template = LoadProvisioningTemplate .LoadProvisioningTemplateFromFile(Path, SessionState.Path.CurrentFileSystemLocation.Path, TemplateProviderExtensions); if (template == null) { throw new ApplicationException("Invalid template file!"); } var fileToRemove = template.Files.FirstOrDefault(f => f.Src == FilePath); if (fileToRemove != null) { template.Files.Remove(fileToRemove); template.Connector.DeleteFile(FilePath); if (template.Connector is ICommitableFileConnector) { ((ICommitableFileConnector)template.Connector).Commit(); } // Determine the output file name and path string outFileName = System.IO.Path.GetFileName(Path); string outPath = new System.IO.FileInfo(Path).DirectoryName; // Save the template back to the storage var fileSystemConnector = new FileSystemConnector(outPath, ""); ITemplateFormatter formatter = XMLPnPSchemaFormatter.LatestFormatter; XMLTemplateProvider provider = new XMLOpenXMLTemplateProvider( Path, fileSystemConnector); var templateFileName = outFileName.Substring(0, outFileName.LastIndexOf(".", StringComparison.Ordinal)) + ".xml"; provider.SaveAs(template, templateFileName, formatter, TemplateProviderExtensions); } }
protected override void ExecuteCmdlet() { if (!System.IO.Path.IsPathRooted(Path)) { Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); } var template = LoadProvisioningTemplate .LoadProvisioningTemplateFromFile(Path, TemplateProviderExtensions); if (template == null) { throw new ApplicationException("Invalid template file!"); } //We will remove a list if it's found so we can get the list ListInstance listInstance = template.Lists.Find(l => l.Title == List.Title); if (listInstance == null) { throw new ApplicationException("List does not exist in the template file!"); } List spList = List.GetList(SelectedWeb); ClientContext.Load(spList, l => l.RootFolder, l => l.HasUniqueRoleAssignments); ClientContext.ExecuteQueryRetry(); CamlQuery query = new CamlQuery(); var viewFieldsStringBuilder = new StringBuilder(); if (Fields != null) { viewFieldsStringBuilder.Append("<ViewFields>"); foreach (var field in Fields) { viewFieldsStringBuilder.AppendFormat("<FieldRef Name='{0}'/>", field); } viewFieldsStringBuilder.Append("</ViewFields>"); } query.ViewXml = string.Format("<View>{0}{1}</View>", Query, viewFieldsStringBuilder); var listItems = spList.GetItems(query); ClientContext.Load(listItems, lI => lI.Include(l => l.HasUniqueRoleAssignments, l => l.ContentType.StringId)); ClientContext.ExecuteQueryRetry(); Microsoft.SharePoint.Client.FieldCollection fieldCollection = spList.Fields; ClientContext.Load(fieldCollection, fs => fs.Include(f => f.InternalName, f => f.FieldTypeKind)); ClientContext.ExecuteQueryRetry(); var rows = new DataRowCollection(template); foreach (var listItem in listItems) { //Make sure we don't pull Folders.. Of course this won't work if (listItem.ServerObjectIsNull == false) { ClientContext.Load(listItem); ClientContext.ExecuteQueryRetry(); if (!(listItem.FileSystemObjectType == FileSystemObjectType.Folder)) { DataRow row = new DataRow(); if (IncludeSecurity && listItem.HasUniqueRoleAssignments) { row.Security.ClearSubscopes = true; row.Security.CopyRoleAssignments = false; var roleAssignments = listItem.RoleAssignments; ClientContext.Load(roleAssignments); ClientContext.ExecuteQueryRetry(); ClientContext.Load(roleAssignments, r => r.Include(a => a.Member.LoginName, a => a.Member, a => a.RoleDefinitionBindings)); ClientContext.ExecuteQueryRetry(); foreach (var roleAssignment in roleAssignments) { var principalName = roleAssignment.Member.LoginName; var roleBindings = roleAssignment.RoleDefinitionBindings; foreach (var roleBinding in roleBindings) { row.Security.RoleAssignments.Add(new OfficeDevPnP.Core.Framework.Provisioning.Model.RoleAssignment() { Principal = principalName, RoleDefinition = roleBinding.Name }); } } } if (Fields != null) { foreach (var field in Fields) { Microsoft.SharePoint.Client.Field dataField = fieldCollection.FirstOrDefault(f => f.InternalName == field); if (dataField != null) { var defaultFieldValue = listItem[field] as string; row.Values.Add(field, defaultFieldValue); } } } else { //All fields are added foreach (var field in fieldCollection) { var fldKey = (from f in listItem.FieldValues.Keys where f == field.InternalName select f).FirstOrDefault(); if (!string.IsNullOrEmpty(fldKey)) { var fieldValue = listItem[field.InternalName] as string; row.Values.Add(field.InternalName, fieldValue); } } } rows.Add(row); } } } template.Lists.Remove(listInstance); listInstance.DataRows.AddRange(rows); template.Lists.Add(listInstance); var outFileName = System.IO.Path.GetFileName(Path); var outPath = new FileInfo(Path).DirectoryName; var fileSystemConnector = new FileSystemConnector(outPath, ""); var formatter = XMLPnPSchemaFormatter.LatestFormatter; var extension = new FileInfo(Path).Extension.ToLowerInvariant(); if (extension == ".pnp") { XMLTemplateProvider provider = new XMLOpenXMLTemplateProvider(new OpenXMLConnector(Path, fileSystemConnector)); var templateFileName = outFileName.Substring(0, outFileName.LastIndexOf(".", StringComparison.Ordinal)) + ".xml"; provider.SaveAs(template, templateFileName, formatter, TemplateProviderExtensions); } else { XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(Path, ""); provider.SaveAs(template, Path, formatter, TemplateProviderExtensions); } }
protected override void ExecuteCmdlet() { if (!System.IO.Path.IsPathRooted(Path)) { Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); } // Load the template var template = LoadProvisioningTemplate .LoadProvisioningTemplateFromFile(Path, TemplateProviderExtensions); if (template == null) { throw new ApplicationException("Invalid template file!"); } List spList = List.GetList(SelectedWeb); ClientContext.Load(spList, l => l.RootFolder, l => l.HasUniqueRoleAssignments); ClientContext.ExecuteQueryRetry(); //We will remove a list if it's found so we can get the list ListInstance listInstance = template.Lists.Find(l => l.Title == spList.Title); if (listInstance == null) { throw new ApplicationException("List does not exist in the template file!"); } Microsoft.SharePoint.Client.Folder listFolder = spList.RootFolder; ClientContext.Load(listFolder); ClientContext.ExecuteQueryRetry(); IList <OfficeDevPnP.Core.Framework.Provisioning.Model.Folder> folders = GetChildFolders(listFolder); template.Lists.Remove(listInstance); listInstance.Folders.AddRange(folders); template.Lists.Add(listInstance); // Determine the output file name and path var outFileName = System.IO.Path.GetFileName(Path); var outPath = new FileInfo(Path).DirectoryName; var fileSystemConnector = new FileSystemConnector(outPath, ""); var formatter = XMLPnPSchemaFormatter.LatestFormatter; var extension = new FileInfo(Path).Extension.ToLowerInvariant(); if (extension == ".pnp") { XMLTemplateProvider provider = new XMLOpenXMLTemplateProvider(new OpenXMLConnector(outPath, fileSystemConnector)); var templateFileName = outFileName.Substring(0, outFileName.LastIndexOf(".", StringComparison.Ordinal)) + ".xml"; provider.SaveAs(template, templateFileName, formatter, TemplateProviderExtensions); } else { XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(Path, ""); provider.SaveAs(template, Path, formatter, TemplateProviderExtensions); } }