protected override void ExecuteCmdlet()
        {
            if (!SelectedWeb.IsPropertyAvailable("Url"))
            {
                ClientContext.Load(SelectedWeb, w => w.Url);
                ClientContext.ExecuteQueryRetry();
            }
            if (!System.IO.Path.IsPathRooted(Path))
            {
                Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
            }

            FileInfo fileInfo = new FileInfo(Path);

            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(fileInfo.DirectoryName, "");

            var provisioningTemplate = provider.GetTemplate(fileInfo.Name);

            if (provisioningTemplate != null)
            {
                var fileSystemConnector = new FileSystemConnector(fileInfo.DirectoryName, "");
                provisioningTemplate.Connector = fileSystemConnector;

                var applyingInformation = new ProvisioningTemplateApplyingInformation();
                applyingInformation.ProgressDelegate = (message, step, total) =>
                {
                    WriteProgress(new ProgressRecord(0, string.Format("Applying template to {0}", SelectedWeb.Url), message) { PercentComplete = (100 / total) * step });
                };

                SelectedWeb.ApplyProvisioningTemplate(provisioningTemplate, applyingInformation);
            }
        }
        protected override void ExecuteCmdlet()
        {
            if (!SelectedWeb.IsPropertyAvailable("Url"))
            {
                ClientContext.Load(SelectedWeb, w => w.Url);
                ClientContext.ExecuteQueryRetry();
            }
            if (!System.IO.Path.IsPathRooted(Path))
            {
                Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
            }
            if (!string.IsNullOrEmpty(ResourceFolder))
            {
                if (System.IO.Path.IsPathRooted(ResourceFolder))
                {
                    ResourceFolder = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, ResourceFolder);
                }
            }

            FileInfo fileInfo = new FileInfo(Path);

            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(fileInfo.DirectoryName, "");

            var provisioningTemplate = provider.GetTemplate(fileInfo.Name);

            if (provisioningTemplate != null)
            {
                FileSystemConnector fileSystemConnector = null;
                if (string.IsNullOrEmpty(ResourceFolder))
                {
                    fileSystemConnector = new FileSystemConnector(fileInfo.DirectoryName, "");
                }
                else
                {
                    fileSystemConnector = new FileSystemConnector(ResourceFolder, "");
                }
                provisioningTemplate.Connector = fileSystemConnector;

                var applyingInformation = new ProvisioningTemplateApplyingInformation();

                applyingInformation.ProgressDelegate = (message, step, total) =>
                {
                    WriteProgress(new ProgressRecord(0, string.Format("Applying template to {0}", SelectedWeb.Url), message) { PercentComplete = (100 / total) * step });
                };

                applyingInformation.MessagesDelegate = (message, type) =>
                {
                    if (type == ProvisioningMessageType.Warning)
                    {
                        WriteWarning(message);
                    }
                };

                applyingInformation.OverwriteSystemPropertyBagValues = OverwriteSystemPropertyBagValues;
                SelectedWeb.ApplyProvisioningTemplate(provisioningTemplate, applyingInformation);
            }
        }
        public static ProvisioningTemplate GetTemplateFromUrl(string templatesFolder, string templateFile)
        {
            ProvisioningTemplate template = null;

            try
            {
                var templateProvider = new XMLFileSystemTemplateProvider(templatesFolder, "");

                template = templateProvider.GetTemplate(templateFile);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: ProvisioningHelper.GetTemplateFromUrl({0}) - {1}", templateFile, ex.Message);
            }

            return template;
        }
Exemple #4
0
        private static void ExecuteCustomCode()
        {
            Console.WriteLine("Hello, SPO!");
            Web rw = mysite.RootWeb;

            /*get sample template
            Console.WriteLine("Getting template...");
            ProvisioningTemplate pt = rw.GetProvisioningTemplate();
            XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(@"C:\Users\eskaggs\OneDrive\Code\sharepoint\PnP.ProvEnginePractice\PnP.ProvEnginePractice", "");
            string templateName = "template.xml";
            provider.SaveAs(pt, templateName);
            */

            //Apply template defined in Template1.xml to the current site
            Console.WriteLine("Applying template...");
            XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(@"C:\Users\eskaggs\OneDrive\Code\sharepoint\PnP.ProvEnginePractice\PnP.ProvEnginePractice", "");
            string templateName = "Template1.xml";
            ProvisioningTemplate pt = provider.GetTemplate(templateName);
            rw.ApplyProvisioningTemplate(pt, null);
        }
Exemple #5
0
        public void GetTemplateForCurrentSiteTest()
        {
            using (ClientContext cc = TestCommon.CreateClientContext())
            {
                using (ClientContext ctx = cc.Clone("https://bertonline.sharepoint.com/sites/temp2/s1"))
                {

                    ProvisioningTemplate p = ctx.Web.GetProvisioningTemplate();

                    Assert.IsNotNull(p);

                    // Save to file system
                    XMLFileSystemTemplateProvider xmlProv = new XMLFileSystemTemplateProvider("c:\\temp", "");
                    xmlProv.SaveAs(p, "test.xml");

                    // Verify that the saved XML is still valid
                    var p2 = xmlProv.GetTemplate("test.xml");
                }
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            string tenantAdminUser = "******";
            string tenantAdminPassword = "******";
            string siteCollectionUrl = "https://your_tenant.sharepoint.com/sites/entwikipnp";

            XMLTemplateProvider provider =
                        new XMLFileSystemTemplateProvider(@"D:\Github\PnP\Samples\Provisioning.Extensibility\Provisioning.Extensibility.Console\Templates\", "");

            var template = provider.GetTemplate("PublishingPageProviderDemo.xml");
            template.Connector = new FileSystemConnector(@"D:\Github\PnP\Samples\Provisioning.Extensibility\Provisioning.Extensibility.Console\", "");

            using (ClientContext context = new ClientContext(siteCollectionUrl))
            {
                context.Credentials =
                    new SharePointOnlineCredentials(
                        tenantAdminUser, 
                        tenantAdminPassword.ToSecureString());

                context.Web.ApplyProvisioningTemplate(template);
            }
        }
        public TestProvisioningTemplateResult TestProvisioningTemplate(ClientContext cc, string templateName, Handlers handlersToProcess = Handlers.All, ProvisioningTemplateApplyingInformation ptai = null, ProvisioningTemplateCreationInformation ptci = null)
        {
            try
            {
                // Read the template from XML and apply it
                XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(string.Format(@"{0}\..\..\Framework\Functional", AppDomain.CurrentDomain.BaseDirectory), "Templates");
                ProvisioningTemplate sourceTemplate = provider.GetTemplate(templateName);

                if (ptai == null)
                {
                    ptai = new ProvisioningTemplateApplyingInformation();
                    ptai.HandlersToProcess = handlersToProcess;
                }

                if (ptai.ProgressDelegate == null)
                {
                    ptai.ProgressDelegate = delegate (String message, Int32 progress, Int32 total)
                    {
                        Console.WriteLine("Applying template - {0}/{1} - {2}", progress, total, message);
                    };
                }

                sourceTemplate.Connector = provider.Connector;

                TokenParser sourceTokenParser = new TokenParser(cc.Web, sourceTemplate);

                cc.Web.ApplyProvisioningTemplate(sourceTemplate, ptai);

                // Read the site we applied the template to
                if (ptci == null)
                {
                    ptci = new ProvisioningTemplateCreationInformation(cc.Web);
                    ptci.HandlersToProcess = handlersToProcess;
                }

                if (ptci.ProgressDelegate == null)
                {
                    ptci.ProgressDelegate = delegate (String message, Int32 progress, Int32 total)
                    {
                        Console.WriteLine("Getting template - {0}/{1} - {2}", progress, total, message);
                    };
                }

                ProvisioningTemplate targetTemplate = cc.Web.GetProvisioningTemplate(ptci);

                return new TestProvisioningTemplateResult()
                {
                    SourceTemplate = sourceTemplate,
                    SourceTokenParser = sourceTokenParser,
                    TargetTemplate = targetTemplate,
                    TargetTokenParser = new TokenParser(cc.Web, targetTemplate),
                };
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.ToDetailedString());
                throw;
            }
        }
        public void XMLResolveInvalidXInclude()
        {
            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(
                    String.Format(@"{0}\..\..\Resources",
                    AppDomain.CurrentDomain.BaseDirectory),
                    "Templates");

            var result = provider.GetTemplate("ProvisioningTemplate-2015-05-NOT-Valid-XInclude-01.xml");

            Assert.IsTrue(result.PropertyBagEntries.Count == 0);
        }
        public void ResolveSchemaFormatV201505()
        {
            var _expectedID = "SPECIALTEAM";
            var _expectedVersion = 1.0;

            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(
                    String.Format(@"{0}\..\..\Resources",
                    AppDomain.CurrentDomain.BaseDirectory),
                    "Templates");

            var result = provider.GetTemplate("ProvisioningSchema-2015-05-ReferenceSample-01.xml");

            Assert.AreEqual(_expectedID, result.Id);
            Assert.AreEqual(_expectedVersion, result.Version);
            Assert.IsTrue(result.Lists.Count == 2);
            Assert.IsTrue(result.Files.Count == 5);
            Assert.IsTrue(result.SiteFields.Count == 4);
        }
Exemple #10
0
        /// <summary>
        /// Applies actual template on top of given site URL. 
        /// </summary>
        /// <param name="webFullUrl"></param>
        /// <param name="siteRequest"></param>
        public void ApplyCustomTemplateToSite(ClientContext ctx, SiteCollectionRequest siteRequest, string resourcesPath)
        {
            // Template to be applied to site
            ProvisioningTemplate template = null;

            // Apply modification to provided site
            switch (siteRequest.ProvisioningType)
            {
                case SiteProvisioningType.Identity:

                    // Get template from xml file
                    XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(resourcesPath, "");
                    template = provider.GetTemplate(siteRequest.TemplateId);

                    break;
                case SiteProvisioningType.TemplateSite:

                    // Get template from existing site
                    using (ClientContext cc2 = ctx.Clone(siteRequest.TemplateId))
                    {

                        // Specify null as base template since we do want "everything" in this case
                        ProvisioningTemplateCreationInformation creationInfo = new ProvisioningTemplateCreationInformation(cc2.Web);
                        creationInfo.BaseTemplate = cc2.Web.GetBaseTemplate();
                        creationInfo.PersistComposedLookFiles = true;
                        creationInfo.FileConnector = new FileSystemConnector(resourcesPath, "");

                        // Get template from existing site
                        template = cc2.Web.GetProvisioningTemplate(creationInfo);
                    }
                    break;
                default:
                    break;
            }

            // Apply template to the site
            template.Connector = new FileSystemConnector(resourcesPath, "");
            ctx.Web.ApplyProvisioningTemplate(template);
        }
        public void CanProvisionObjectsRequiredField()
        {

            XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(resourceFolder, "");
            var template = provider.GetTemplate(resourceFolder + "/" + fileName);
            FileSystemConnector connector = new FileSystemConnector(resourceFolder, "");

            template.Connector = connector;
            // replace whatever files is in the template with a file we control
            template.Files.Clear();
            template.Files.Add(new Core.Framework.Provisioning.Model.File() { Overwrite = true, Src = fileName, Folder = "Lists/ProjectDocuments" });

            using (var ctx = TestCommon.CreateClientContext())
            {
                var parser = new TokenParser(ctx.Web, template);
                new ObjectField().ProvisionObjects(ctx.Web, template, parser,
                    new ProvisioningTemplateApplyingInformation());
                new ObjectContentType().ProvisionObjects(ctx.Web, template, parser,
                    new ProvisioningTemplateApplyingInformation());
                new ObjectListInstance().ProvisionObjects(ctx.Web, template, parser,
                    new ProvisioningTemplateApplyingInformation());

                new ObjectFiles().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());


                ctx.Web.EnsureProperties(w => w.ServerRelativeUrl);

                var file = ctx.Web.GetFileByServerRelativeUrl(
                    UrlUtility.Combine(ctx.Web.ServerRelativeUrl,
                        UrlUtility.Combine("Lists/ProjectDocuments", fileName)));
                ctx.Load(file, f => f.Exists);
                ctx.ExecuteQueryRetry();
                Assert.IsTrue(file.Exists);

                // cleanup for artifacts specific to this test
                foreach (var list in template.Lists)
                {
                    ctx.Web.GetListByUrl(list.Url).DeleteObject();

                }

                foreach (var ct in template.ContentTypes)
                {
                    ctx.Web.GetContentTypeById(ct.Id).DeleteObject();
                }

                var idsToDelete = new List<Guid>();
                foreach (var field in ctx.Web.Fields)
                {
                    if (field.Group == "My Columns")
                    {
                        idsToDelete.Add(field.Id);
                    }
                }
                foreach (var guid in idsToDelete)
                {
                    ctx.Web.GetFieldById<Microsoft.SharePoint.Client.Field>(guid).DeleteObject();
                }
                ctx.ExecuteQueryRetry();
            }



        }
        static void Main(string[] args)
        {
            bool interactiveLogin = true;
            string templateSiteUrl = "https://mbakirov367.sharepoint.com/sites/demo4";
            string targetSiteUrl = "https://mbakirov367.sharepoint.com/sites/demo4f";
            string loginId = "*****@*****.**";

            // Get pwd from environment variable, so that we do to need to show that.
            string pwd = "";
            if (interactiveLogin)
            {
                pwd = GetInput("Password", true);
            }
            else
            {
                pwd = System.Environment.GetEnvironmentVariable("MSOPWD", EnvironmentVariableTarget.User);
            }

            if (string.IsNullOrEmpty(pwd))
            {
                System.Console.WriteLine("MSOPWD user environment variable empty or no password was specified, cannot continue. Press any key to abort.");
                System.Console.ReadKey();
                return;
            }

            // Template
            ProvisioningTemplate template;

            // Get access to source site
            using (var ctx = new ClientContext(templateSiteUrl))
            {
                //Provide count and pwd for connecting to the source
                var passWord = new SecureString();
                foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c);
                ctx.Credentials = new SharePointOnlineCredentials(loginId, passWord);

                // Get template from existing site
                template = ctx.Web.GetProvisioningTemplate();
            }

            // Save template using XML provider
            XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(@"c:\temp\pnpprovisioningdemo", "");
            string templateName = "template.xml";
            provider.SaveAs(template, templateName);

            // Load the saved model again
            ProvisioningTemplate p2 = provider.GetTemplate(templateName);

            // Get the available, valid templates
            var templates = provider.GetTemplates();
            foreach(var template1 in templates)
            {
                Console.WriteLine("Found template with ID {0}", template1.Id);
            }

            // Get access to target site and apply template
            using (var ctx = new ClientContext(targetSiteUrl))
            {
                //Provide count and pwd for connecting to the source
                var passWord = new SecureString();
                foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c);
                ctx.Credentials = new SharePointOnlineCredentials(loginId, passWord);

                // Apply template to existing site
                ctx.Web.ApplyProvisioningTemplate(template);
            }
        }
Exemple #13
0
        public static void ProvisionArtifactsByTemplate()
        {
            // Create a PnP AuthenticationManager object
            AuthenticationManager am = new AuthenticationManager();

            // Authenticate against SPO with an App-Only access token
            using (ClientContext context = am.GetAzureADAppOnlyAuthenticatedContext(
                O365ProjectsAppContext.CurrentSiteUrl, O365ProjectsAppSettings.ClientId,
                O365ProjectsAppSettings.TenantId, O365ProjectsAppSettings.AppOnlyCertificate))
            {
                Web web = context.Web;

                // Load the template from the file system
                XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(
                    String.Format(HttpContext.Current.Server.MapPath(".")),
                    "ProvisioningTemplates");

                ProvisioningTemplate template = provider.GetTemplate("O365ProjectsAppSite.xml");

                // Configure the AppSiteUrl parameter
                template.Parameters["AppSiteUrl"] = O365ProjectsAppContext.CurrentAppSiteUrl;

                // Apply the template to the target site
                template.Connector = provider.Connector;
                web.ApplyProvisioningTemplate(template);
            }
        }
        protected override void ExecuteCmdlet()
        {
            SelectedWeb.EnsureProperty(w => w.Url);

            if (!System.IO.Path.IsPathRooted(Path))
            {
                Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
            }
            if (!string.IsNullOrEmpty(ResourceFolder))
            {
                if (!System.IO.Path.IsPathRooted(ResourceFolder))
                {
                    ResourceFolder = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, ResourceFolder);
                }
            }

            FileInfo fileInfo = new FileInfo(Path);

            XMLTemplateProvider provider = null;
            ProvisioningTemplate provisioningTemplate = null;
            var isOpenOfficeFile = IsOpenOfficeFile(Path);
            if (isOpenOfficeFile)
            {
                var fileSystemconnector = new FileSystemConnector(fileInfo.DirectoryName, "");
                provider = new XMLOpenXMLTemplateProvider(new OpenXMLConnector(fileInfo.Name, fileSystemconnector));
                var fileName = fileInfo.Name.Substring(0, fileInfo.Name.LastIndexOf(".")) + ".xml";
                provisioningTemplate = provider.GetTemplate(fileName);
            }
            else
            {
                provider = new XMLFileSystemTemplateProvider(fileInfo.DirectoryName, "");
                provisioningTemplate = provider.GetTemplate(fileInfo.Name);
            }

            if (provisioningTemplate != null)
            {
                if (isOpenOfficeFile)
                {
                    provisioningTemplate.Connector = provider.Connector;
                }
                else
                {
                    FileSystemConnector fileSystemConnector = null;
                    if (ResourceFolder != null)
                    {
                        fileSystemConnector = new FileSystemConnector(ResourceFolder, "");
                        provisioningTemplate.Connector = fileSystemConnector;
                    }
                    else
                    {
                        provisioningTemplate.Connector = provider.Connector;
                    }
                }

                if (Parameters != null)
                {
                    foreach (var parameter in Parameters.Keys)
                    {
                        if (provisioningTemplate.Parameters.ContainsKey(parameter.ToString()))
                        {
                            provisioningTemplate.Parameters[parameter.ToString()] = Parameters[parameter].ToString();
                        }
                        else
                        {
                            provisioningTemplate.Parameters.Add(parameter.ToString(), Parameters[parameter].ToString());
                        }
                    }
                }

                var applyingInformation = new ProvisioningTemplateApplyingInformation();

                if (this.MyInvocation.BoundParameters.ContainsKey("Handlers"))
                {
                    applyingInformation.HandlersToProcess = Handlers;
                }
                if (this.MyInvocation.BoundParameters.ContainsKey("ExcludeHandlers"))
                {
                    foreach (var handler in (OfficeDevPnP.Core.Framework.Provisioning.Model.Handlers[])Enum.GetValues(typeof(Handlers)))
                    {
                        if (!ExcludeHandlers.Has(handler) && handler != Handlers.All)
                        {
                            Handlers = Handlers | handler;
                        }
                    }
                    applyingInformation.HandlersToProcess = Handlers;
                }

                if (ExtensibilityHandlers != null)
                {
                    applyingInformation.ExtensibilityHandlers = ExtensibilityHandlers.ToList<ExtensibilityHandler>();
                }

                applyingInformation.ProgressDelegate = (message, step, total) =>
                {
                    WriteProgress(new ProgressRecord(0, string.Format("Applying template to {0}", SelectedWeb.Url), message) { PercentComplete = (100 / total) * step });
                };

                applyingInformation.MessagesDelegate = (message, type) =>
                {
                    if (type == ProvisioningMessageType.Warning)
                    {
                        WriteWarning(message);
                    }
                };

                applyingInformation.OverwriteSystemPropertyBagValues = OverwriteSystemPropertyBagValues;
                SelectedWeb.ApplyProvisioningTemplate(provisioningTemplate, applyingInformation);
            }
        }
        protected override void ExecuteCmdlet()
        {
            SelectedWeb.EnsureProperty(w => w.Url);

            if (!System.IO.Path.IsPathRooted(Path))
            {
                Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
            }
            if (!string.IsNullOrEmpty(ResourceFolder))
            {
                if (System.IO.Path.IsPathRooted(ResourceFolder))
                {
                    ResourceFolder = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, ResourceFolder);
                }
            }

            FileInfo fileInfo = new FileInfo(Path);

            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(fileInfo.DirectoryName, "");

            var provisioningTemplate = provider.GetTemplate(fileInfo.Name);

            if (provisioningTemplate != null)
            {
                FileSystemConnector fileSystemConnector = null;
                if (string.IsNullOrEmpty(ResourceFolder))
                {
                    fileSystemConnector = new FileSystemConnector(fileInfo.DirectoryName, "");
                }
                else
                {
                    fileSystemConnector = new FileSystemConnector(ResourceFolder, "");
                }
                provisioningTemplate.Connector = fileSystemConnector;

                if (Parameters != null)
                {
                    foreach (var parameter in Parameters.Keys)
                    {
                        if (provisioningTemplate.Parameters.ContainsKey(parameter.ToString()))
                        {
                            provisioningTemplate.Parameters[parameter.ToString()] = Parameters[parameter].ToString();
                        }
                        else
                        {
                            provisioningTemplate.Parameters.Add(parameter.ToString(), Parameters[parameter].ToString());
                        }
                    }
                }

                var applyingInformation = new ProvisioningTemplateApplyingInformation();

                applyingInformation.ProgressDelegate = (message, step, total) =>
                {
                    WriteProgress(new ProgressRecord(0, string.Format("Applying template to {0}", SelectedWeb.Url), message) { PercentComplete = (100 / total) * step });
                };

                applyingInformation.MessagesDelegate = (message, type) =>
                {
                    if (type == ProvisioningMessageType.Warning)
                    {
                        WriteWarning(message);
                    }
                };

                applyingInformation.OverwriteSystemPropertyBagValues = OverwriteSystemPropertyBagValues;
                SelectedWeb.ApplyProvisioningTemplate(provisioningTemplate, applyingInformation);
            }
        }
Exemple #16
0
        public void XMLFileSystemGetTemplate1Test()
        {
            var _expectedID = "SPECIALTEAM";
            var _expectedVersion = 1.0;

            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(
                    String.Format(@"{0}\..\..\Resources",
                    AppDomain.CurrentDomain.BaseDirectory),
                    "Templates");

            var result = provider.GetTemplate("ProvisioningTemplate-2015-03-Sample-01.xml");

            Assert.AreEqual(_expectedID, result.ID);
            Assert.AreEqual(_expectedVersion, result.Version);
            Assert.IsTrue(result.Lists.Count == 1);
            Assert.IsTrue(result.Files.Count == 1);
            Assert.IsTrue(result.SiteFields.Count == 4);
        }
        protected override void BeginProcessing()
        {
            if (!System.IO.Path.IsPathRooted(Path))
            {
                Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
            }

            if (MyInvocation.BoundParameters.ContainsKey("Out"))
            {
                if (!System.IO.Path.IsPathRooted(Out))
                {
                    Out = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Out);
                }
            }

            FileInfo fileInfo = new FileInfo(Path);

            XMLTemplateProvider provider =
            new XMLFileSystemTemplateProvider(fileInfo.DirectoryName, "");

            var provisioningTemplate = provider.GetTemplate(fileInfo.Name);

            if (provisioningTemplate != null)
            {
                ITemplateFormatter formatter = null;
                switch (ToSchema)
                {
                    case XMLPnPSchemaVersion.LATEST:
                        {
                            formatter = XMLPnPSchemaFormatter.LatestFormatter;
                            break;
                        }
                    case XMLPnPSchemaVersion.V201503:
                        {
            #pragma warning disable CS0618 // Type or member is obsolete
                            formatter = XMLPnPSchemaFormatter.GetSpecificFormatter(XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_03);
            #pragma warning restore CS0618 // Type or member is obsolete
                            break;
                        }
                    case XMLPnPSchemaVersion.V201505:
                        {
            #pragma warning disable CS0618 // Type or member is obsolete
                            formatter = XMLPnPSchemaFormatter.GetSpecificFormatter(XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_05);
            #pragma warning restore CS0618 // Type or member is obsolete
                            break;
                        }
                    case XMLPnPSchemaVersion.V201508:
                        {
            #pragma warning disable CS0618 // Type or member is obsolete
                            formatter = XMLPnPSchemaFormatter.GetSpecificFormatter(XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_08);
            #pragma warning restore CS0618 // Type or member is obsolete
                            break;
                        }
                    case XMLPnPSchemaVersion.V201512:
                        {
                            formatter = XMLPnPSchemaFormatter.GetSpecificFormatter(XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12);
                            break;
                        }
                    case XMLPnPSchemaVersion.V201605:
                        {
                            formatter = XMLPnPSchemaFormatter.GetSpecificFormatter(XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2016_05);
                            break;
                        }
                }

                if (!string.IsNullOrEmpty(Out))
                {
                    if (File.Exists(Out))
                    {
                        if (Force || ShouldContinue(string.Format(Resources.File0ExistsOverwrite, Out), Resources.Confirm))
                        {
                            File.WriteAllText(Out, provisioningTemplate.ToXML(formatter), Encoding);
                        }
                    }
                    else
                    {
                        File.WriteAllText(Out, provisioningTemplate.ToXML(formatter), Encoding);
                    }
                }
                else
                {
                    WriteObject(provisioningTemplate.ToXML(formatter));
                }
            }
        }
        public void XMLFileSystemConvertTemplatesFromV201503toV201505()
        {
            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(
                    String.Format(@"{0}\..\..\Resources",
                    AppDomain.CurrentDomain.BaseDirectory),
                    "Templates");

            var _source1 = provider.GetTemplate("ProvisioningTemplate-2015-03-Sample-01.xml");
            provider.SaveAs(_source1, "ProvisioningTemplate-2015-05-Sample-01.xml", XMLPnPSchemaFormatter.LatestFormatter);

            var _source2 = provider.GetTemplate("ProvisioningTemplate-2015-03-Sample-02.xml");
            provider.SaveAs(_source2, "ProvisioningTemplate-2015-05-Sample-02.xml", XMLPnPSchemaFormatter.LatestFormatter);
        }
Exemple #19
0
        static void Main(string[] args)
        {
            bool interactiveLogin = true;
            string templateSiteUrl = "https://bertonline.sharepoint.com/sites/130049";
            string targetSiteUrl = "https://bertonline.sharepoint.com/sites/pr1";
            // Office 365: [email protected]
            // OnPrem: DOMAIN\Username
            string loginId = "*****@*****.**";

            // Get pwd from environment variable, so that we do to need to show that.
            string pwd = "";
            if (interactiveLogin)
            {
                pwd = GetInput("Password", true);
            }
            else
            {
                pwd = Environment.GetEnvironmentVariable("MSOPWD", EnvironmentVariableTarget.User);
            }

            if (string.IsNullOrEmpty(pwd))
            {
                Console.WriteLine("MSOPWD user environment variable empty or no password was specified, cannot continue. Press any key to abort.");
                Console.ReadKey();
                return;
            }

            // Template 
            ProvisioningTemplate template;

            // Get access to source site
            using (var ctx = new ClientContext(templateSiteUrl))
            {
                //Provide count and pwd for connecting to the source
                ctx.Credentials = GetCredentials(targetSiteUrl, loginId, pwd);

                // Get template from existing site
                template = ctx.Web.GetProvisioningTemplate();
            }

            // Save template using XML provider
            XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(@"c:\temp\pnpprovisioningdemo", "");
            string templateName = "template.xml";
            provider.SaveAs(template, templateName);

            // Load the saved model again
            ProvisioningTemplate p2 = provider.GetTemplate(templateName);

            // Get the available, valid templates
            var templates = provider.GetTemplates();
            foreach (var template1 in templates)
            {
                Console.WriteLine("Found template with ID {0}", template1.Id);
            }

            // Get access to target site and apply template
            using (var ctx = new ClientContext(targetSiteUrl))
            {
                //Provide count and pwd for connecting to the source               
                ctx.Credentials = GetCredentials(targetSiteUrl, loginId, pwd);

                // Apply template to existing site
                ctx.Web.ApplyProvisioningTemplate(template);
            }
        }
        public void XMLEncryptionTest()
        {
            X509Certificate2 certificate = RetrieveCertificateFromStore(new X509Store(StoreLocation.CurrentUser), "PnPTestCertificate");

            if (certificate == null)
            {
                Assert.Inconclusive("Missing certificate with SN=PnPTestCertificate in CurrentUser Certificate Store, so can't test");
            }

            XMLEncryptionTemplateProviderExtension extension =
                new XMLEncryptionTemplateProviderExtension();

            extension.Initialize(certificate);

            ITemplateProviderExtension[] extensions = new ITemplateProviderExtension[] { extension };

            XMLTemplateProvider provider =
                new XMLFileSystemTemplateProvider(
                    String.Format(@"{0}\..\..\Resources",
                    AppDomain.CurrentDomain.BaseDirectory),
                    "Templates");

            var template = provider.GetTemplate("ProvisioningTemplate-2016-05-Sample-01.xml");
            template.DisplayName = "Ciphered template";

            provider.SaveAs(template, "ProvisioningTemplate-2016-05-Ciphered.xml", extensions);
            var result = provider.GetTemplate("ProvisioningTemplate-2016-05-Ciphered.xml", extensions);

            provider.Delete("ProvisioningTemplate-2016-05-Ciphered.xml");

            Assert.IsTrue(result.DisplayName == "Ciphered template");
        }