Example #1
0
        /// <summary>
        /// Constructor for ProvisioningTemplate class
        /// </summary>
        public ProvisioningTemplate()
        {
            this.connector = new FileSystemConnector(".", "");

            this._localizations = new LocalizationCollection(this);
            this._siteFields    = new FieldCollection(this);
            this._contentTypes  = new ContentTypeCollection(this);
            this._propertyBags  = new PropertyBagEntryCollection(this);
            this._lists         = new ListInstanceCollection(this);

            this._siteSecurity = new SiteSecurity();
            this._siteSecurity.ParentTemplate = this;

            this._composedLook = new ComposedLook();
            this._composedLook.ParentTemplate = this;
            this._features = new Features();
            this._features.ParentTemplate      = this;
            this._customActions                = new CustomActions();
            this._customActions.ParentTemplate = this;

            this._files                 = new FileCollection(this);
            this._directories           = new DirectoryCollection(this);
            this._providers             = new ProviderCollection(this); // Deprecated
            this._extensibilityHandlers = new ExtensibilityHandlerCollection(this);
            this._pages                 = new PageCollection(this);
            this._termGroups            = new TermGroupCollection(this);

            this._supportedUILanguages = new SupportedUILanguageCollection(this);
            this._addins = new AddInCollection(this);

            this._siteWebhooks    = new SiteWebhookCollection(this);
            this._clientSidePages = new ClientSidePageCollection(this);
        }
        public static bool Validate(CustomActions sourceCustomActions, CustomActions targetCustomActions, TokenParser tokenParser, Web web)
        {
            if (web.IsNoScriptSite())
            {
                Console.WriteLine("Skipping validation of custom actions due to noscript site.");
                return true;
            }

            Console.WriteLine("Custom Action validation started...");

            bool isSiteCustomActionsMatch = false;
            bool isWebCustomActionsMatch = false;
            if (sourceCustomActions.SiteCustomActions.Count > 0)
            {
                isSiteCustomActionsMatch = ValidateCustomActions(sourceCustomActions.SiteCustomActions, targetCustomActions.SiteCustomActions, tokenParser, web);
                Console.WriteLine("Site Custom Actions validation " + isSiteCustomActionsMatch);
            }

            if (sourceCustomActions.WebCustomActions.Count > 0)
            {
                isWebCustomActionsMatch = ValidateCustomActions(sourceCustomActions.WebCustomActions, targetCustomActions.WebCustomActions, tokenParser, web);
                Console.WriteLine("Web Custom  Actions validation " + isWebCustomActionsMatch);
            }

            if (!isSiteCustomActionsMatch || !isWebCustomActionsMatch)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public static bool Validate(CustomActions sourceCustomActions, CustomActions targetCustomActions, TokenParser tokenParser)
        {
            Console.WriteLine("Custom Action validation started...");

            bool isSiteCustomActionsMatch = false;
            bool isWebCustomActionsMatch = false;
            if (sourceCustomActions.SiteCustomActions.Count > 0)
            {
                isSiteCustomActionsMatch = ValidateCustomActions(sourceCustomActions.SiteCustomActions, targetCustomActions.SiteCustomActions, tokenParser);
                Console.WriteLine("Site Custom Actions validation " + isSiteCustomActionsMatch);
            }

            if (sourceCustomActions.WebCustomActions.Count > 0)
            {
                isWebCustomActionsMatch = ValidateCustomActions(sourceCustomActions.WebCustomActions, targetCustomActions.WebCustomActions, tokenParser);
                Console.WriteLine("Web Custom  Actions validation " + isWebCustomActionsMatch);
            }

            if (!isSiteCustomActionsMatch || !isWebCustomActionsMatch)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
        {
            using (var scope = new PnPMonitoredScope(CoreResources.Provisioning_ObjectHandlers_CustomActions))
            {
                var context = web.Context as ClientContext;
                bool isSubSite = web.IsSubSite();
                var webCustomActions = web.GetCustomActions();
                var siteCustomActions = context.Site.GetCustomActions();

                var customActions = new CustomActions();
                foreach (var customAction in webCustomActions)
                {
                    scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_web_scoped_custom_action___0___to_template, customAction.Name);
                    customActions.WebCustomActions.Add(CopyUserCustomAction(customAction));
                }

                // if this is a sub site then we're not creating entities for site collection scoped custom actions
                if (!isSubSite)
                {
                    foreach (var customAction in siteCustomActions)
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_site_scoped_custom_action___0___to_template, customAction.Name);
                        customActions.SiteCustomActions.Add(CopyUserCustomAction(customAction));
                    }
                }

                template.CustomActions = customActions;

                // If a base template is specified then use that one to "cleanup" the generated template model
                if (creationInfo.BaseTemplate != null)
                {
                    template = CleanupEntities(template, creationInfo.BaseTemplate, isSubSite, scope);
                }
            }
            return template;
        }
        private bool ValidateCustomActions(CustomActions srcCustomActions, CustomActions targetCustomActions, TokenParser sParser, TokenParser tParser, bool rootSite)
        {
            List<Localization> sCustomActions = LoadCustomActions(srcCustomActions, rootSite);
            List<Localization> tCustomActions = LoadCustomActions(targetCustomActions, rootSite);

            if (sCustomActions.Count > 0)
            {
                if (!Validatelocalization(sCustomActions, tCustomActions, sParser, tParser)) { return false; }
            }

            return true;
        }
        private List<Localization> LoadCustomActions(CustomActions customActions, bool rootSite)
        {
            List<Localization> locCustomActions = new List<Localization>();

            if (rootSite)
            {
                foreach (CustomAction action in customActions.SiteCustomActions)
                {
                    locCustomActions.Add(new Localization(action.Name, action.Title, action.Description));
                }
            }
            foreach (CustomAction action in customActions.WebCustomActions)
            {
                locCustomActions.Add(new Localization(action.Name, action.Title, action.Description));
            }

            return locCustomActions;
        }
Example #7
0
        public override ProvisioningTemplate CreateEntities(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
        {
            var context = web.Context as ClientContext;
            bool isSubSite = web.IsSubSite();
            var webCustomActions = web.GetCustomActions();
            var siteCustomActions = context.Site.GetCustomActions();

            var customActions = new CustomActions();
            foreach (var customAction in webCustomActions)
            {
                customActions.WebCustomActions.Add(CopyUserCustomAction(customAction));
            }
            
            // if this is a sub site then we're not creating entities for site collection scoped custom actions
            if (!isSubSite)
            {
                foreach (var customAction in siteCustomActions)
                {
                    customActions.SiteCustomActions.Add(CopyUserCustomAction(customAction));
                }
            }

            template.CustomActions = customActions;

            // If a base template is specified then use that one to "cleanup" the generated template model
            if (creationInfo.BaseTemplate != null)
            {
                template = CleanupEntities(template, creationInfo.BaseTemplate, isSubSite);
            }

            return template;
        }