예제 #1
0
        private void ExtractTemplate(string dirName, string fileName)
        {
            var outputTemplate = new ProvisioningTemplate();

            var helper = new OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.Utilities.ClientSidePageContentsHelper();

            var ci = new OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.ProvisioningTemplateCreationInformation(SelectedWeb);

            ci.PersistBrandingFiles = PersistBrandingFiles;
            if (!string.IsNullOrEmpty(dirName))
            {
                var fileSystemConnector = new FileSystemConnector(dirName, "");
                ci.FileConnector = fileSystemConnector;
            }
            helper.ExtractClientSidePage(SelectedWeb, outputTemplate, ci, new OfficeDevPnP.Core.Diagnostics.PnPMonitoredScope(), null, Identity.Name, false);

            if (!string.IsNullOrEmpty(fileName))
            {
                System.IO.File.WriteAllText(Path.Combine(dirName, fileName), outputTemplate.ToXML());
            }
            else
            {
                WriteObject(outputTemplate.ToXML());
            }
        }
        internal string ExtractElementXml(ProvisioningTemplate provisioningTemplate)
        {
            XElement provXml          = XElement.Parse(provisioningTemplate.ToXML(XMLPnPSchemaFormatter.GetSpecificFormatter(SchemaVersion)));
            var      namespaceManager = new XmlNamespaceManager(new NameTable());

            namespaceManager.AddNamespace("pnp", SchemaVersion);
            XElement ctXml = provXml.XPathSelectElement(XPathQuery, namespaceManager);

            return(ctXml.ToString(SaveOptions.DisableFormatting));
        }
        private void ExtractTemplate(string dirName, string fileName, ExtractConfiguration configuration)
        {
            var outputTemplate = new ProvisioningTemplate();

            outputTemplate.Id = Guid.NewGuid().ToString("N");
            var helper = new OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.Utilities.ClientSidePageContentsHelper();
            ProvisioningTemplateCreationInformation ci = null;

            if (configuration != null)
            {
                ci = configuration.ToCreationInformation(SelectedWeb);
            }
            else
            {
                ci = new ProvisioningTemplateCreationInformation(SelectedWeb);
            }
            if (MyInvocation.BoundParameters.ContainsKey(nameof(PersistBrandingFiles)))
            {
                ci.PersistBrandingFiles = PersistBrandingFiles;
            }
            if (!string.IsNullOrEmpty(dirName))
            {
                var fileSystemConnector = new FileSystemConnector(dirName, "");
                ci.FileConnector = fileSystemConnector;
            }
            helper.ExtractClientSidePage(SelectedWeb, outputTemplate, ci, new OfficeDevPnP.Core.Diagnostics.PnPMonitoredScope(), null, Identity.Name, false);

            if (!string.IsNullOrEmpty(fileName))
            {
                System.IO.File.WriteAllText(Path.Combine(dirName, fileName), outputTemplate.ToXML());
            }
            else
            {
                WriteObject(outputTemplate.ToXML());
            }
        }
예제 #4
0
        private List <string> ParseTemplate(ProvisioningTemplate template)
        {
            List <string> tokenIds = new List <string>();

            // Add parameter tokenid if parameters are specified
            if (template.Parameters != null && template.Parameters.Any())
            {
                tokenIds.Add("parameter");
            }

            var xml = template.ToXML();

            if (xml.IndexOfAny(TokenChars) == -1)
            {
                return(tokenIds);
            }

            bool   hasMatch = false;
            string tempXml  = xml;

            do
            {
                hasMatch = false;
                tempXml  = ReToken.Replace(xml, match =>
                {
                    for (int i = 0; i < match.Groups.Count; i++)
                    {
                        if (!ReGuid.IsMatch(match.Groups[i].Value))
                        {
                            string tokenString = match.Groups[i].Value.Replace("{", "").Replace("}", "").ToLower();

                            var colonIndex = tokenString.IndexOf(":");
                            if (colonIndex > -1)
                            {
                                tokenString = tokenString.Substring(0, colonIndex);
                            }
                            if (!tokenIds.Contains(tokenString) && !string.IsNullOrEmpty(tokenString))
                            {
                                tokenIds.Add(tokenString);
                            }
                        }
                    }

                    return("-");
                });
            } while (hasMatch && xml != tempXml);
            return(tokenIds);
        }