예제 #1
0
        // ===========================================================================================================
        /// <summary>
        /// Applies the current template as an open XML ".pnp" package on the specified web
        /// </summary>
        /// <param name="web">The <b>Web</b> on which to apply the template</param>
        /// <param name="templateProvider">The <b>XMLTemplateProvider</b> that is mapped to the client's working directory</param>
        // ===========================================================================================================
        private void ApplyOpenXML(Web web, XMLTemplateProvider templateProvider)
        {
            logger.Info("Applying open XML package '{0}' from file '{1}'", this.Name, this.Path);

            // --------------------------------------------------
            // Formats the template's execution rendering
            // --------------------------------------------------
            ProvisioningTemplateApplyingInformation ptai = GetTemplateApplyInfo();

            // --------------------------------------------------
            // Replaces the regular provider by an OpenXml one
            // --------------------------------------------------
            string workingDirectory = templateProvider.Connector.Parameters[PARAMETER_CONNECTION_STRING].ToString();
            FileSystemConnector fileSystemConnector     = new FileSystemConnector(workingDirectory, "");
            OpenXMLConnector    openXmlConnector        = new OpenXMLConnector(this.Path, fileSystemConnector);
            XMLTemplateProvider openXmlTemplateProvider = new XMLOpenXMLTemplateProvider(openXmlConnector);

            // --------------------------------------------------
            // Loops through all templates within the .pnp package
            // --------------------------------------------------
            List <ProvisioningTemplate> templates = openXmlTemplateProvider.GetTemplates();

            foreach (ProvisioningTemplate template in templates)
            {
                logger.Info("Applying template '{0}' from file '{1}'", template.Id, this.Path);

                // --------------------------------------------------
                // Applies the template
                // --------------------------------------------------
                template.Connector = openXmlTemplateProvider.Connector;
                web.ApplyProvisioningTemplate(template, ptai);
            }
        }
예제 #2
0
        private ProvisioningTemplate GetProvisioningTemplate()
        {
            var connector        = new OpenXMLConnector(stream);
            var templateProvider = new XMLOpenXMLTemplateProvider(connector);

            var templates = templateProvider.GetTemplates();
            var template  = templates.Single();

            template.Connector = connector;

            return(template);
        }
예제 #3
0
        public static async Task <PnpFilePreviewModel> GetAsync(string resourceId, string uri)
        {
            // Retrieve an access token so we can make API calls
            string accessToken = await AuthHelper.GetUserAccessTokenSilentAsync(resourceId);

            // Read the PnP file content
            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", accessToken);
            using (Stream stream = await client.GetStreamAsync(uri))
            {
                XMLTemplateProvider provider = new XMLOpenXMLTemplateProvider(new OpenXMLConnector(stream));

                // Get the list of the templates
                return(new PnpFilePreviewModel
                {
                    Templates = provider.GetTemplates().Select(p => new PnpFilePreviewItemModel
                    {
                        DisplayName = p.DisplayName,
                        ImagePreviewUrl = p.ImagePreviewUrl
                    }).ToArray()
                });
            }
        }