Exemplo n.º 1
1
        // ===========================================================================================================
        /// <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);
            }
        }
Exemplo n.º 2
0
        // ===========================================================================================================
        /// <summary>
        /// Launches the current sequence by executing all it's templates 
        /// </summary>
        /// <param name="credentials">The credentials required for creating the client context</param>
        /// <param name="templateProvider">The <b>XMLTemplatePRovider</b> that is mapped to the client's working directory</param>
        // ===========================================================================================================
        public void Launch(ICredentials credentials, XMLTemplateProvider templateProvider)
        {
            if(!this.Ignore)
            {
                logger.Info("Launching sequence '{0}' ({1})", this.Name, this.Description);

                using (ClientContext ctx = new ClientContext(this.WebUrl))
                {
                    // --------------------------------------------------
                    // Sets the context with the provided credentials
                    // --------------------------------------------------
                    ctx.Credentials = credentials;
                    ctx.RequestTimeout = Timeout.Infinite;

                    // --------------------------------------------------
                    // Loads the full web for futur references (providers)
                    // --------------------------------------------------
                    Web web = ctx.Web;
                    ctx.Load(web);
                    ctx.ExecuteQueryRetry();

                    // --------------------------------------------------
                    // Launches the templates
                    // --------------------------------------------------
                    foreach (Template template in this.Templates)
                    {
                        template.Apply(web, templateProvider);
                    }
                }
            }
            else
            {
                logger.Info("Ignoring sequence '{0}' ({1})", this.Name, this.Description);
            }
        }
Exemplo n.º 3
0
 // ===========================================================================================================
 /// <summary>
 /// Returns whether the current template file exists based on the specified template provider
 /// </summary>
 /// <param name="templateProvider">The template provider that is mapped to the client's working directory</param>
 /// <returns>True if the template file exists, otherwise false</returns>
 // ===========================================================================================================
 private bool TemplateExists(XMLTemplateProvider templateProvider)
 {
     string workingDirectory = templateProvider.Connector.Parameters[PARAMETER_CONNECTION_STRING].ToString();
     string templatePath = System.IO.Path.Combine(workingDirectory, this.Path);
     return System.IO.File.Exists(templatePath);
 }
Exemplo n.º 4
0
 // ===========================================================================================================
 /// <summary>
 /// Applies the current template on the specified <b>Web</b> object
 /// </summary>
 /// <param name="web">The <b>Web</b> object on which the template needs to be applied</param>
 /// <param name="templateProvider">The <b>XMLTemplatePRovider</b> that is mapped to the client's working directory</param>
 // ===========================================================================================================
 public void Apply(Web web, XMLTemplateProvider templateProvider)
 {
     if(!this.Ignore)
     {
         if (TemplateExists(templateProvider))
         {
             if (IsOpenXml())
             {
                 // --------------------------------------------------
                 // Handles ".pnp" templates
                 // --------------------------------------------------
                 ApplyOpenXML(web, templateProvider);
             }
             else
             {
                 // --------------------------------------------------
                 // Handles regular ".xml" templates
                 // --------------------------------------------------
                 ApplyRegularXML(web, templateProvider);
             }
         }
         else
         {
             throw new FileNotFoundException(string.Format(ERROR_TEMPLATE_NOT_FOUND, System.IO.Path.Combine(templateProvider.Connector.Parameters[PARAMETER_CONNECTION_STRING].ToString(), this.Path)));
         }
     }
     else
     {
         logger.Info("Ignoring template '{0}' from file '{1}'", this.Name, this.Path);
     }
 }
Exemplo n.º 5
0
        // ===========================================================================================================
        /// <summary>
        /// Applies the current template as a regular XML template 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 ApplyRegularXML(Web web, XMLTemplateProvider templateProvider)
        {
            logger.Info("Applying template '{0}' from file '{1}'", this.Name, this.Path);

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

            // --------------------------------------------------
            // Loads the template 
            // --------------------------------------------------
            ProvisioningTemplate template = templateProvider.GetTemplate(this.Path);
            template.Connector = templateProvider.Connector;

            // --------------------------------------------------
            // Applies the template 
            // --------------------------------------------------
            web.ApplyProvisioningTemplate(template, ptai);
        }