Example #1
0
 protected override void ProcessRecord()
 {
     WriteObject(LoadProvisioningTemplate
                 .LoadProvisioningTemplateFromFile(Path,
                                                   SessionState.Path.CurrentFileSystemLocation.Path,
                                                   TemplateProviderExtensions));
 }
Example #2
0
        protected override void ProcessRecord()
        {
            if (String.IsNullOrEmpty(Source))
            {
                throw new ArgumentNullException("Source");
            }

            if (String.IsNullOrEmpty(Folder))
            {
                throw new ArgumentNullException("Folder");
            }

            // Load the template
            ProvisioningTemplate template = LoadProvisioningTemplate
                                            .LoadProvisioningTemplateFromFile(Path,
                                                                              SessionState.Path.CurrentFileSystemLocation.Path,
                                                                              TemplateProviderExtensions);

            if (template == null)
            {
                throw new ApplicationException("Invalid template file!");
            }

            // Load the file and add it to the .PNP file
            using (FileStream fs = new FileStream(Source, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                Folder = Folder.Replace("\\", "/");

                String fileName  = Source.IndexOf("\\") > 0 ? Source.Substring(Source.LastIndexOf("\\") + 1) : Source;
                String container = !String.IsNullOrEmpty(Container) ? Container : String.Empty;
                String 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
                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);
            }
        }
Example #3
0
        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);
            }
        }