Rebase() 공개 메소드

public Rebase ( Web web ) : void
web Web
리턴 void
        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                var context = web.Context as ClientContext;
                var site    = context.Site;

                // Check if this is not a noscript site as we're not allowed to update some properties
                bool isNoScriptSite = web.IsNoScriptSite();

                // if this is a sub site then we're not enabling the site collection scoped custom actions
                if (!web.IsSubSite())
                {
                    var siteCustomActions = template.CustomActions.SiteCustomActions;
                    ProvisionCustomActionImplementation(site, siteCustomActions, parser, scope, isNoScriptSite);
                }

                var webCustomActions = template.CustomActions.WebCustomActions;
                ProvisionCustomActionImplementation(web, webCustomActions, parser, scope, isNoScriptSite);

                // Switch parser context back to it's original context
                parser.Rebase(web);
            }
            return(parser);
        }
        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                var context = web.Context as ClientContext;
                var site = context.Site;

                // Check if this is not a noscript site as we're not allowed to update some properties
                bool isNoScriptSite = web.IsNoScriptSite();

                // if this is a sub site then we're not enabling the site collection scoped custom actions
                if (!web.IsSubSite())
                {
                    var siteCustomActions = template.CustomActions.SiteCustomActions;
                    ProvisionCustomActionImplementation(site, siteCustomActions, parser, scope, isNoScriptSite);
                }

                var webCustomActions = template.CustomActions.WebCustomActions;
                ProvisionCustomActionImplementation(web, webCustomActions, parser, scope, isNoScriptSite);

                // Switch parser context back to it's original context
                parser.Rebase(web);
            }
            return parser;
        }
예제 #3
0
        public override void ProvisionObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            Log.Info(Constants.LOGGING_SOURCE_FRAMEWORK_PROVISIONING, CoreResources.Provisioning_ObjectHandlers_CustomActions);

            var context = web.Context as ClientContext;
            var site    = context.Site;

            // if this is a sub site then we're not enabling the site collection scoped custom actions
            if (!web.IsSubSite())
            {
                var siteCustomActions = template.CustomActions.SiteCustomActions;
                ProvisionCustomActionImplementation(site, siteCustomActions);
            }

            var webCustomActions = template.CustomActions.WebCustomActions;

            ProvisionCustomActionImplementation(web, webCustomActions);

            // Switch parser context back to it's original context
            TokenParser.Rebase(web);
        }
예제 #4
0
        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(CoreResources.Provisioning_ObjectHandlers_CustomActions))
            {
                var context = web.Context as ClientContext;
                var site = context.Site;

                // if this is a sub site then we're not enabling the site collection scoped custom actions
                if (!web.IsSubSite())
                {
                    var siteCustomActions = template.CustomActions.SiteCustomActions;
                    ProvisionCustomActionImplementation(site, siteCustomActions, parser, scope);
                }

                var webCustomActions = template.CustomActions.WebCustomActions;
                ProvisionCustomActionImplementation(web, webCustomActions, parser, scope);

                // Switch parser context back to it's original context
                parser.Rebase(web);
            }
            return parser;
        }
        private void ProvisionCustomActionImplementation(object parent, List <CustomAction> customActions, TokenParser parser, PnPMonitoredScope scope)
        {
            Web  web  = null;
            Site site = null;

            if (parent is Site)
            {
                site = parent as Site;

                // Switch parser context;
                parser.Rebase(site.RootWeb);
            }
            else
            {
                web = parent as Web;

                // Switch parser context
                parser.Rebase(web);
            }
            foreach (var customAction in customActions)
            {
                var caExists = false;
                if (site != null)
                {
                    caExists = site.CustomActionExists(customAction.Name);
                }
                else
                {
                    caExists = web.CustomActionExists(customAction.Name);
                }
                if (!caExists)
                {
                    var customActionEntity = new CustomActionEntity()
                    {
                        CommandUIExtension = customAction.CommandUIExtension != null?parser.ParseString(customAction.CommandUIExtension.ToString()) : string.Empty,
                                                 Description      = customAction.Description,
                                                 Group            = customAction.Group,
                                                 ImageUrl         = parser.ParseString(customAction.ImageUrl),
                                                 Location         = customAction.Location,
                                                 Name             = customAction.Name,
                                                 RegistrationId   = customAction.RegistrationId,
                                                 RegistrationType = customAction.RegistrationType,
                                                 Remove           = customAction.Remove,
                                                 Rights           = customAction.Rights,
                                                 ScriptBlock      = parser.ParseString(customAction.ScriptBlock),
                                                 ScriptSrc        = parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection"),
                                                 Sequence         = customAction.Sequence,
                                                 Title            = customAction.Title,
                                                 Url = parser.ParseString(customAction.Url)
                    };

                    if (site != null)
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_custom_action___0___to_scope_Site, customActionEntity.Name);
                        site.AddCustomAction(customActionEntity);
                    }
                    else
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_custom_action___0___to_scope_Web, customActionEntity.Name);
                        web.AddCustomAction(customActionEntity);
                    }
                }
                else
                {
                    UserCustomAction existingCustomAction = null;
                    if (site != null)
                    {
                        existingCustomAction = site.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
                    }
                    else
                    {
                        existingCustomAction = web.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
                    }
                    if (existingCustomAction != null)
                    {
                        var isDirty = false;

                        if (customAction.CommandUIExtension != null)
                        {
                            if (existingCustomAction.CommandUIExtension != parser.ParseString(customAction.CommandUIExtension.ToString()))
                            {
                                scope.LogPropertyUpdate("CommandUIExtension");
                                existingCustomAction.CommandUIExtension = parser.ParseString(customAction.CommandUIExtension.ToString());
                                isDirty = true;
                            }
                        }

                        if (existingCustomAction.Description != customAction.Description)
                        {
                            scope.LogPropertyUpdate("Description");
                            existingCustomAction.Description = customAction.Description;
                            isDirty = true;
                        }
                        if (existingCustomAction.Group != customAction.Group)
                        {
                            scope.LogPropertyUpdate("Group");
                            existingCustomAction.Group = customAction.Group;
                            isDirty = true;
                        }
                        if (existingCustomAction.ImageUrl != parser.ParseString(customAction.ImageUrl))
                        {
                            scope.LogPropertyUpdate("ImageUrl");
                            existingCustomAction.ImageUrl = parser.ParseString(customAction.ImageUrl);
                            isDirty = true;
                        }
                        if (existingCustomAction.Location != customAction.Location)
                        {
                            scope.LogPropertyUpdate("Location");
                            existingCustomAction.Location = customAction.Location;
                            isDirty = true;
                        }
                        if (existingCustomAction.RegistrationId != customAction.RegistrationId)
                        {
                            scope.LogPropertyUpdate("RegistrationId");
                            existingCustomAction.RegistrationId = customAction.RegistrationId;
                            isDirty = true;
                        }
                        if (existingCustomAction.RegistrationType != customAction.RegistrationType)
                        {
                            scope.LogPropertyUpdate("RegistrationType");
                            existingCustomAction.RegistrationType = customAction.RegistrationType;
                            isDirty = true;
                        }
                        if (existingCustomAction.ScriptBlock != parser.ParseString(customAction.ScriptBlock))
                        {
                            scope.LogPropertyUpdate("ScriptBlock");
                            existingCustomAction.ScriptBlock = parser.ParseString(customAction.ScriptBlock);
                            isDirty = true;
                        }
                        if (existingCustomAction.ScriptSrc != parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection"))
                        {
                            scope.LogPropertyUpdate("ScriptSrc");
                            existingCustomAction.ScriptSrc = parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection");
                            isDirty = true;
                        }
                        if (existingCustomAction.Title != parser.ParseString(customAction.Title))
                        {
                            scope.LogPropertyUpdate("Title");
                            existingCustomAction.Title = parser.ParseString(customAction.Title);
                            isDirty = true;
                        }
                        if (existingCustomAction.Url != parser.ParseString(customAction.Url))
                        {
                            scope.LogPropertyUpdate("Url");
                            existingCustomAction.Url = parser.ParseString(customAction.Url);
                            isDirty = true;
                        }
                        if (isDirty)
                        {
                            existingCustomAction.Update();
                            existingCustomAction.Context.ExecuteQueryRetry();
                        }
                    }
                }
            }
        }
        private void ProvisionCustomActionImplementation(object parent, CustomActionCollection customActions, TokenParser parser, PnPMonitoredScope scope, bool isNoScriptSite = false)
        {
            Web  web  = null;
            Site site = null;

            if (parent is Site)
            {
                site = parent as Site;

                // Switch parser context;
                parser.Rebase(site.RootWeb);
            }
            else
            {
                web = parent as Web;

                // Switch parser context
                parser.Rebase(web);
            }
            foreach (var customAction in customActions)
            {
                if (isNoScriptSite && Guid.Empty == customAction.ClientSideComponentId)
                {
                    scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_CustomActions_SkippingAddUpdateDueToNoScript, customAction.Name);
                    continue;
                }

                var caExists = false;
                if (site != null)
                {
                    caExists = site.CustomActionExists(customAction.Name);
                }
                else
                {
                    caExists = web.CustomActionExists(customAction.Name);
                }

                // If the CustomAction does not exist, we don't have to remove it, and it is enabled
                if (!caExists && !customAction.Remove && customAction.Enabled)
                {
                    // Then we add it to the target
                    var customActionEntity = new CustomActionEntity()
                    {
#if !ONPREMISES
                        ClientSideComponentId         = customAction.ClientSideComponentId,
                        ClientSideComponentProperties = customAction.ClientSideComponentProperties,
#endif
                        CommandUIExtension = customAction.CommandUIExtension != null?parser.ParseString(customAction.CommandUIExtension.ToString()) : string.Empty,
                                                 Description      = parser.ParseString(customAction.Description),
                                                 Group            = customAction.Group,
                                                 ImageUrl         = parser.ParseString(customAction.ImageUrl),
                                                 Location         = customAction.Location,
                                                 Name             = customAction.Name,
                                                 RegistrationId   = customAction.RegistrationId,
                                                 RegistrationType = customAction.RegistrationType,
                                                 Remove           = customAction.Remove,
                                                 Rights           = customAction.Rights,
                                                 ScriptBlock      = parser.ParseString(customAction.ScriptBlock),
                                                 ScriptSrc        = parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection"),
                                                 Sequence         = customAction.Sequence,
                                                 Title            = parser.ParseString(customAction.Title),
                                                 Url = parser.ParseString(customAction.Url)
                    };


                    if (site != null)
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_custom_action___0___to_scope_Site, customActionEntity.Name);
                        site.AddCustomAction(customActionEntity);
#if !ONPREMISES
                        if ((!string.IsNullOrEmpty(customAction.Title) && customAction.Title.ContainsResourceToken()) ||
                            (!string.IsNullOrEmpty(customAction.Description) && customAction.Description.ContainsResourceToken()))
                        {
                            var uca = site.GetCustomActions().Where(uc => uc.Name == customAction.Name).FirstOrDefault();
                            SetCustomActionResourceValues(parser, customAction, uca);
                        }
#endif
                    }
                    else
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_custom_action___0___to_scope_Web, customActionEntity.Name);
                        web.AddCustomAction(customActionEntity);
#if !ONPREMISES
                        if (customAction.Title.ContainsResourceToken() || customAction.Description.ContainsResourceToken())
                        {
                            var uca = web.GetCustomActions().Where(uc => uc.Name == customAction.Name).FirstOrDefault();
                            SetCustomActionResourceValues(parser, customAction, uca);
                        }
#endif
                    }
                }
                else
                {
                    UserCustomAction existingCustomAction = null;
                    if (site != null)
                    {
                        existingCustomAction = site.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
                    }
                    else
                    {
                        existingCustomAction = web.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
                    }
                    if (existingCustomAction != null)
                    {
                        // If we have to remove the existing CustomAction
                        if (customAction.Remove)
                        {
                            // We simply remove it
                            existingCustomAction.DeleteObject();
                            existingCustomAction.Context.ExecuteQueryRetry();
                        }
                        else
                        {
                            UpdateCustomAction(parser, scope, customAction, existingCustomAction, isNoScriptSite);
                        }
                    }
                }
            }
        }
예제 #7
0
        private void ProvisionCustomActionImplementation(object parent, List<CustomAction> customActions, TokenParser parser, PnPMonitoredScope scope)
        {
            Web web = null;
            Site site = null;
            if (parent is Site)
            {
                site = parent as Site;

                // Switch parser context;
                parser.Rebase(site.RootWeb);
            }
            else
            {
                web = parent as Web;

                // Switch parser context
                parser.Rebase(web);
            }
            foreach (var customAction in customActions)
            {
                var caExists = false;
                if (site != null)
                {
                    caExists = site.CustomActionExists(customAction.Name);
                }
                else
                {
                    caExists = web.CustomActionExists(customAction.Name);
                }
                if (!caExists)
                {
                    var customActionEntity = new CustomActionEntity()
                    {
                        CommandUIExtension = customAction.CommandUIExtension != null ? parser.ParseString(customAction.CommandUIExtension.ToString()) : string.Empty,
                        Description = customAction.Description,
                        Group = customAction.Group,
                        ImageUrl = parser.ParseString(customAction.ImageUrl),
                        Location = customAction.Location,
                        Name = customAction.Name,
                        RegistrationId = customAction.RegistrationId,
                        RegistrationType = customAction.RegistrationType,
                        Remove = customAction.Remove,
                        Rights = customAction.Rights,
                        ScriptBlock = parser.ParseString(customAction.ScriptBlock),
                        ScriptSrc = parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection"),
                        Sequence = customAction.Sequence,
                        Title = customAction.Title,
                        Url = parser.ParseString(customAction.Url)
                    };

                    if (site != null)
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_custom_action___0___to_scope_Site, customActionEntity.Name);
                        site.AddCustomAction(customActionEntity);
                    }
                    else
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_custom_action___0___to_scope_Web, customActionEntity.Name);
                        web.AddCustomAction(customActionEntity);
                    }
                }
                else
                {
                    UserCustomAction existingCustomAction = null;
                    if (site != null)
                    {
                        existingCustomAction = site.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
                    }
                    else
                    {
                        existingCustomAction = web.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
                    }
                    if (existingCustomAction != null)
                    {
                        var isDirty = false;

                        if (customAction.CommandUIExtension != null)
                        {
                            if (existingCustomAction.CommandUIExtension != parser.ParseString(customAction.CommandUIExtension.ToString()))
                            {
                                scope.LogPropertyUpdate("CommandUIExtension");
                                existingCustomAction.CommandUIExtension = parser.ParseString(customAction.CommandUIExtension.ToString());
                                isDirty = true;
                            }
                        }

                        if (existingCustomAction.Description != customAction.Description)
                        {
                            scope.LogPropertyUpdate("Description");
                            existingCustomAction.Description = customAction.Description;
                            isDirty = true;
                        }
                        if (existingCustomAction.Group != customAction.Group)
                        {
                            scope.LogPropertyUpdate("Group");
                            existingCustomAction.Group = customAction.Group;
                            isDirty = true;
                        }
                        if (existingCustomAction.ImageUrl != parser.ParseString(customAction.ImageUrl))
                        {
                            scope.LogPropertyUpdate("ImageUrl");
                            existingCustomAction.ImageUrl = parser.ParseString(customAction.ImageUrl);
                            isDirty = true;
                        }
                        if (existingCustomAction.Location != customAction.Location)
                        {
                            scope.LogPropertyUpdate("Location");
                            existingCustomAction.Location = customAction.Location;
                            isDirty = true;
                        }
                        if (existingCustomAction.RegistrationId != customAction.RegistrationId)
                        {
                            scope.LogPropertyUpdate("RegistrationId");
                            existingCustomAction.RegistrationId = customAction.RegistrationId;
                            isDirty = true;
                        }
                        if (existingCustomAction.RegistrationType != customAction.RegistrationType)
                        {
                            scope.LogPropertyUpdate("RegistrationType");
                            existingCustomAction.RegistrationType = customAction.RegistrationType;
                            isDirty = true;
                        }
                        if (existingCustomAction.ScriptBlock != parser.ParseString(customAction.ScriptBlock))
                        {
                            scope.LogPropertyUpdate("ScriptBlock");
                            existingCustomAction.ScriptBlock = parser.ParseString(customAction.ScriptBlock);
                            isDirty = true;
                        }
                        if (existingCustomAction.ScriptSrc != parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection"))
                        {
                            scope.LogPropertyUpdate("ScriptSrc");
                            existingCustomAction.ScriptSrc = parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection");
                            isDirty = true;
                        }
                        if (existingCustomAction.Title != parser.ParseString(customAction.Title))
                        {
                            scope.LogPropertyUpdate("Title");
                            existingCustomAction.Title = parser.ParseString(customAction.Title);
                            isDirty = true;
                        }
                        if (existingCustomAction.Url != parser.ParseString(customAction.Url))
                        {
                            scope.LogPropertyUpdate("Url");
                            existingCustomAction.Url = parser.ParseString(customAction.Url);
                            isDirty = true;
                        }
                        if (isDirty)
                        {
                            existingCustomAction.Update();
                            existingCustomAction.Context.ExecuteQueryRetry();
                        }
                    }
                }
            }
        }
        private void ProvisionCustomActionImplementation(object parent, CustomActionCollection customActions, TokenParser parser, PnPMonitoredScope scope)
        {
            Web web = null;
            Site site = null;
            if (parent is Site)
            {
                site = parent as Site;

                // Switch parser context;
                parser.Rebase(site.RootWeb);
            }
            else
            {
                web = parent as Web;

                // Switch parser context
                parser.Rebase(web);
            }
            foreach (var customAction in customActions)
            {
                var caExists = false;
                if (site != null)
                {
                    caExists = site.CustomActionExists(customAction.Name);
                }
                else
                {
                    caExists = web.CustomActionExists(customAction.Name);
                }

                // If the CustomAction does not exist, we don't have to remove it, and it is enabled
                if (!caExists && !customAction.Remove && customAction.Enabled)
                {
                    // Then we add it to the target
                    var customActionEntity = new CustomActionEntity()
                    {
                        CommandUIExtension = customAction.CommandUIExtension != null ? parser.ParseString(customAction.CommandUIExtension.ToString()) : string.Empty,
                        Description = parser.ParseString(customAction.Description),
                        Group = customAction.Group,
                        ImageUrl = parser.ParseString(customAction.ImageUrl),
                        Location = customAction.Location,
                        Name = customAction.Name,
                        RegistrationId = customAction.RegistrationId,
                        RegistrationType = customAction.RegistrationType,
                        Remove = customAction.Remove,
                        Rights = customAction.Rights,
                        ScriptBlock = parser.ParseString(customAction.ScriptBlock),
                        ScriptSrc = parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection"),
                        Sequence = customAction.Sequence,
                        Title = parser.ParseString(customAction.Title),
                        Url = parser.ParseString(customAction.Url)
                    };

                    if (site != null)
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_custom_action___0___to_scope_Site, customActionEntity.Name);
                        site.AddCustomAction(customActionEntity);
            #if !ONPREMISES
                        if ((!string.IsNullOrEmpty(customAction.Title) && customAction.Title.ContainsResourceToken()) ||
                            (!string.IsNullOrEmpty(customAction.Description) && customAction.Description.ContainsResourceToken()))
                        {
                            var uca = site.GetCustomActions().Where(uc => uc.Name == customAction.Name).FirstOrDefault();
                            SetCustomActionResourceValues(parser, customAction, uca);
                        }
            #endif
                    }
                    else
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_custom_action___0___to_scope_Web, customActionEntity.Name);
                        web.AddCustomAction(customActionEntity);
            #if !ONPREMISES
                        if (customAction.Title.ContainsResourceToken() || customAction.Description.ContainsResourceToken())
                        {
                            var uca = web.GetCustomActions().Where(uc => uc.Name == customAction.Name).FirstOrDefault();
                            SetCustomActionResourceValues(parser, customAction, uca);
                        }
            #endif
                    }
                }
                else
                {
                    UserCustomAction existingCustomAction = null;
                    if (site != null)
                    {
                        existingCustomAction = site.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
                    }
                    else
                    {
                        existingCustomAction = web.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
                    }
                    if (existingCustomAction != null)
                    {
                        // If we have to remove the existing CustomAction
                        if (customAction.Remove)
                        {
                            // We simply remove it
                            existingCustomAction.DeleteObject();
                            existingCustomAction.Context.ExecuteQueryRetry();
                        }
                        else
                        {
                            UpdateCustomAction(parser, scope, customAction, existingCustomAction);
                        }
                    }
                }
            }
        }
예제 #9
0
        private void ProvisionCustomActionImplementation(object parent, List <CustomAction> customActions)
        {
            Web  web  = null;
            Site site = null;

            if (parent is Site)
            {
                site = parent as Site;

                // Switch parser context;
                TokenParser.Rebase(site.RootWeb);
            }
            else
            {
                web = parent as Web;

                // Switch parser context
                TokenParser.Rebase(web);
            }
            foreach (var customAction in customActions)
            {
                var caExists = false;
                if (site != null)
                {
                    caExists = site.CustomActionExists(customAction.Name);
                }
                else
                {
                    caExists = web.CustomActionExists(customAction.Name);
                }
                if (!caExists)
                {
                    var customActionEntity = new CustomActionEntity()
                    {
                        CommandUIExtension = customAction.CommandUIExtension != null?customAction.CommandUIExtension.ToString().ToParsedString() : string.Empty,
                                                 Description      = customAction.Description,
                                                 Group            = customAction.Group,
                                                 ImageUrl         = customAction.ImageUrl.ToParsedString(),
                                                 Location         = customAction.Location,
                                                 Name             = customAction.Name,
                                                 RegistrationId   = customAction.RegistrationId,
                                                 RegistrationType = customAction.RegistrationType,
                                                 Remove           = customAction.Remove,
                                                 Rights           = customAction.Rights,
                                                 ScriptBlock      = customAction.ScriptBlock.ToParsedString(),
                                                 ScriptSrc        = customAction.ScriptSrc.ToParsedString("~site", "~sitecollection"),
                                                 Sequence         = customAction.Sequence,
                                                 Title            = customAction.Title,
                                                 Url = customAction.Url.ToParsedString()
                    };

                    if (site != null)
                    {
                        site.AddCustomAction(customActionEntity);
                    }
                    else
                    {
                        web.AddCustomAction(customActionEntity);
                    }
                }
                else
                {
                    UserCustomAction existingCustomAction = null;
                    if (site != null)
                    {
                        existingCustomAction = site.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
                    }
                    else
                    {
                        existingCustomAction = web.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
                    }
                    if (existingCustomAction != null)
                    {
                        var isDirty = false;

                        if (customAction.CommandUIExtension != null)
                        {
                            if (existingCustomAction.CommandUIExtension != customAction.CommandUIExtension.ToString().ToParsedString())
                            {
                                existingCustomAction.CommandUIExtension = customAction.CommandUIExtension.ToString().ToParsedString();
                                isDirty = true;
                            }
                        }

                        if (existingCustomAction.Description != customAction.Description)
                        {
                            existingCustomAction.Description = customAction.Description;
                            isDirty = true;
                        }
                        if (existingCustomAction.Group != customAction.Group)
                        {
                            existingCustomAction.Group = customAction.Group;
                            isDirty = true;
                        }
                        if (existingCustomAction.ImageUrl != customAction.ImageUrl.ToParsedString())
                        {
                            existingCustomAction.ImageUrl = customAction.ImageUrl.ToParsedString();
                            isDirty = true;
                        }
                        if (existingCustomAction.Location != customAction.Location)
                        {
                            existingCustomAction.Location = customAction.Location;
                            isDirty = true;
                        }
                        if (existingCustomAction.RegistrationId != customAction.RegistrationId)
                        {
                            existingCustomAction.RegistrationId = customAction.RegistrationId;
                            isDirty = true;
                        }
                        if (existingCustomAction.RegistrationType != customAction.RegistrationType)
                        {
                            existingCustomAction.RegistrationType = customAction.RegistrationType;
                            isDirty = true;
                        }
                        if (existingCustomAction.ScriptBlock != customAction.ScriptBlock.ToParsedString())
                        {
                            existingCustomAction.ScriptBlock = customAction.ScriptBlock.ToParsedString();
                            isDirty = true;
                        }
                        if (existingCustomAction.ScriptSrc != customAction.ScriptSrc.ToParsedString("~site", "~sitecollection"))
                        {
                            existingCustomAction.ScriptSrc = customAction.ScriptSrc.ToParsedString("~site", "~sitecollection");
                            isDirty = true;
                        }
                        if (existingCustomAction.Title != customAction.Title.ToParsedString())
                        {
                            existingCustomAction.Title = customAction.Title.ToParsedString();
                            isDirty = true;
                        }
                        if (existingCustomAction.Url != customAction.Url.ToParsedString())
                        {
                            existingCustomAction.Url = customAction.Url.ToParsedString();
                            isDirty = true;
                        }
                        if (isDirty)
                        {
                            existingCustomAction.Update();
                            existingCustomAction.Context.ExecuteQueryRetry();
                        }
                    }
                }
            }
        }
예제 #10
0
        private void ProvisionCustomActionImplementation(object parent, List <CustomAction> customActions)
        {
            Web  web  = null;
            Site site = null;

            if (parent is Site)
            {
                site = parent as Site;

                // Switch parser context;
                TokenParser.Rebase(site.RootWeb);
            }
            else
            {
                web = parent as Web;
            }
            foreach (var customAction in customActions)
            {
                var caExists = false;
                if (site != null)
                {
                    caExists = site.CustomActionExists(customAction.Name);
                }
                else
                {
                    caExists = web.CustomActionExists(customAction.Name);
                }
                if (!caExists)
                {
                    var customActionEntity = new CustomActionEntity();
                    customActionEntity.CommandUIExtension = customAction.CommandUIExtension.ToParsedString();


                    customActionEntity.Description      = customAction.Description;
                    customActionEntity.Group            = customAction.Group;
                    customActionEntity.ImageUrl         = customAction.ImageUrl.ToParsedString();
                    customActionEntity.Location         = customAction.Location;
                    customActionEntity.Name             = customAction.Name;
                    customActionEntity.RegistrationId   = customAction.RegistrationId;
                    customActionEntity.RegistrationType = customAction.RegistrationType;
                    customActionEntity.Remove           = customAction.Remove;
                    customActionEntity.Rights           = customAction.Rights;
                    customActionEntity.ScriptBlock      = customAction.ScriptBlock;
                    customActionEntity.ScriptSrc        = customAction.ScriptSrc.ToParsedString();
                    customActionEntity.Sequence         = customAction.Sequence;
                    customActionEntity.Title            = customAction.Title;
                    customActionEntity.Url = customAction.Url.ToParsedString();

                    if (site != null)
                    {
                        site.AddCustomAction(customActionEntity);
                    }
                    else
                    {
                        web.AddCustomAction(customActionEntity);
                    }
                }
            }

            // Rebase parser context to current web
            TokenParser.Rebase(web);
        }