コード例 #1
0
ファイル: CollectionTests.cs プロジェクト: kthompson/Upnp
        public void CustomActionCollectionShouldContainItem()
        {
            var col = new CustomActionCollection<Tuple<string, string>>(_ => { }, _ => { });
            col.Add(Tuple.Create("hi", "hi"));

            Assert.AreEqual(1, col.Count);
            Assert.IsTrue(col.Contains(Tuple.Create("hi", "hi")));
            Assert.IsFalse(col.Contains(Tuple.Create("hi", "bye")));
        }
コード例 #2
0
        public void CustomActionCollectionShouldContainItem()
        {
            var col = new CustomActionCollection <Tuple <string, string> >(_ => { }, _ => { });

            col.Add(Tuple.Create("hi", "hi"));

            Assert.AreEqual(1, col.Count);
            Assert.IsTrue(col.Contains(Tuple.Create("hi", "hi")));
            Assert.IsFalse(col.Contains(Tuple.Create("hi", "bye")));
        }
コード例 #3
0
        public void CustomActionCollectionShouldRemoveAndClear()
        {
            var col = new CustomActionCollection <Tuple <string, int> >(_ => { }, _ => { })
            {
                Tuple.Create("hi1", 1),
                Tuple.Create("hi2", 2),
                Tuple.Create("hi3", 3)
            };

            Assert.AreEqual(3, col.Count);
            col.Remove(Tuple.Create("hi2", 2));

            Assert.AreEqual(2, col.Count);
            col.Clear();
            Assert.AreEqual(0, col.Count);
        }
コード例 #4
0
ファイル: CollectionTests.cs プロジェクト: kthompson/Upnp
        public void CustomActionCollectionShouldRemoveAndClear()
        {
            var col = new CustomActionCollection<Tuple<string, int>>(_ => { }, _ => { })
            {
                Tuple.Create("hi1", 1),
                Tuple.Create("hi2", 2),
                Tuple.Create("hi3", 3)
            };

            Assert.AreEqual(3, col.Count);
            col.Remove(Tuple.Create("hi2", 2));

            Assert.AreEqual(2, col.Count);
            col.Clear();
            Assert.AreEqual(0, col.Count);
        }
コード例 #5
0
ファイル: CollectionTests.cs プロジェクト: kthompson/Upnp
        public void CustomActionCollectionShouldEnumerate()
        {
            var col = new CustomActionCollection<Tuple<string, int>>(_ => { }, _ => { })
            {
                Tuple.Create("hi1", 1),
                Tuple.Create("hi2", 2),
                Tuple.Create("hi3", 3)
            };

            Assert.AreEqual(3, col.Count);
            var i = 0;
            foreach (var tuple in col)
            {
                i++;
                Assert.AreEqual("hi" + i, tuple.Item1);
                Assert.AreEqual(i, tuple.Item2);
            }
            Assert.AreEqual(3, i);
        }
コード例 #6
0
        public void CustomActionCollectionShouldEnumerate()
        {
            var col = new CustomActionCollection <Tuple <string, int> >(_ => { }, _ => { })
            {
                Tuple.Create("hi1", 1),
                Tuple.Create("hi2", 2),
                Tuple.Create("hi3", 3)
            };

            Assert.AreEqual(3, col.Count);
            var i = 0;

            foreach (var tuple in col)
            {
                i++;
                Assert.AreEqual("hi" + i, tuple.Item1);
                Assert.AreEqual(i, tuple.Item2);
            }
            Assert.AreEqual(3, i);
        }
コード例 #7
0
 public CustomActions()
 {
     _siteCustomActions = new CustomActionCollection(this.ParentTemplate);
     _webCustomActions = new CustomActionCollection(this.ParentTemplate);
 }
コード例 #8
0
        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 (!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.Sequence != customAction.Sequence)
                        {
                            scope.LogPropertyUpdate("Sequence");
                            existingCustomAction.Sequence = customAction.Sequence;
                            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();
                        }
                    }
                }
            }
        }
コード例 #9
0
        public static bool ValidateCustomActions(CustomActionCollection source, CustomActionCollection target, TokenParser tokenParser, Web web = null)
        {
            int sCount = 0;
            int tCount = 0;

            if (web != null && web.IsNoScriptSite())
            {
                Console.WriteLine("Skipping validation of custom actions due to noscript site.");
                return true;
            }

            foreach (CustomAction srcSCA in source)
            {
                //Only count the enabled ones
                if (srcSCA.Enabled && !srcSCA.Remove)
                {
                    // ensure token in source are parsed before comparing with target
                    srcSCA.Title = tokenParser.ParseString(srcSCA.Title);
                    srcSCA.ImageUrl = tokenParser.ParseString(srcSCA.ImageUrl);
                    srcSCA.ScriptBlock = tokenParser.ParseString(srcSCA.ScriptBlock);
                    srcSCA.ScriptSrc = tokenParser.ParseString(srcSCA.ScriptSrc, "~site", "~sitecollection");
                    srcSCA.Title = tokenParser.ParseString(srcSCA.Title);
                    srcSCA.Url = tokenParser.ParseString(srcSCA.Url);
                    if (srcSCA.CommandUIExtension != null)
                    {
                        srcSCA.CommandUIExtension = XElement.Parse(tokenParser.ParseString(srcSCA.CommandUIExtension.ToString()));
                    }

                    sCount++;
                    foreach (CustomAction tgtSCA in target)
                    {
                        if (tgtSCA.CommandUIExtension != null)
                        {
                            // Drop the namespace attribute before comparing (xmlns="http://schemas.microsoft.com/sharepoint").
                            // SharePoint injects this namespace when we extract a custom action that has a commandUIExtension
                            tgtSCA.CommandUIExtension = RemoveAllNamespaces(tgtSCA.CommandUIExtension);
                        }

                        // Use our custom action "Equals" implementation
                        if (srcSCA.Equals(tgtSCA))
                        {
                            tCount++;
                            break;
                        }
                        else
                        {
                            Console.WriteLine("{0} is not matching", tgtSCA.Name);
                        }
                    }
                }
            }

            if (sCount != tCount)
            {
                return false;
            }

            // cross check that enabled false custom actions do not exist anymore
            foreach (CustomAction srcSCA in source)
            {
                if (!srcSCA.Enabled || srcSCA.Remove)
                {
                    var ca = target.Where(w => w.Name == srcSCA.Name).FirstOrDefault();
                    if (ca != null)
                    {
                        return false;
                    }
                }
            }

            return true;
        }
コード例 #10
0
        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);
                        }
                    }
                }
            }
        }
コード例 #11
0
        public static bool ValidateCustomActions(CustomActionCollection source, CustomActionCollection target, TokenParser tokenParser)
        {
            int sCount = 0;
            int tCount = 0;

            foreach (CustomAction srcSCA in source)
            {
                //Only count the enabled ones
                if (srcSCA.Enabled && !srcSCA.Remove)
                {
                    // ensure token in source are parsed before comparing with target
                    srcSCA.Title       = tokenParser.ParseString(srcSCA.Title);
                    srcSCA.ImageUrl    = tokenParser.ParseString(srcSCA.ImageUrl);
                    srcSCA.ScriptBlock = tokenParser.ParseString(srcSCA.ScriptBlock);
                    srcSCA.ScriptSrc   = tokenParser.ParseString(srcSCA.ScriptSrc, "~site", "~sitecollection");
                    srcSCA.Title       = tokenParser.ParseString(srcSCA.Title);
                    srcSCA.Url         = tokenParser.ParseString(srcSCA.Url);
                    if (srcSCA.CommandUIExtension != null)
                    {
                        srcSCA.CommandUIExtension = XElement.Parse(tokenParser.ParseString(srcSCA.CommandUIExtension.ToString()));
                    }

                    sCount++;
                    foreach (CustomAction tgtSCA in target)
                    {
                        if (tgtSCA.CommandUIExtension != null)
                        {
                            // Drop the namespace attribute before comparing (xmlns="http://schemas.microsoft.com/sharepoint").
                            // SharePoint injects this namespace when we extract a custom action that has a commandUIExtension
                            tgtSCA.CommandUIExtension = RemoveAllNamespaces(tgtSCA.CommandUIExtension);
                        }

                        // Use our custom action "Equals" implementation
                        if (srcSCA.Equals(tgtSCA))
                        {
                            tCount++;
                            break;
                        }
                        else
                        {
                            Console.WriteLine("{0} is not matching", tgtSCA.Name);
                        }
                    }
                }
            }

            if (sCount != tCount)
            {
                return(false);
            }

            // cross check that enabled false custom actions do not exist anymore
            foreach (CustomAction srcSCA in source)
            {
                if (!srcSCA.Enabled || srcSCA.Remove)
                {
                    var ca = target.Where(w => w.Name == srcSCA.Name).FirstOrDefault();
                    if (ca != null)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #12
0
        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);
                        }
                    }
                }
            }
        }
コード例 #13
0
        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 (!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);
            #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)
                    {
                        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 !ONPREMISES
                        if (customAction.Description.ContainsResourceToken())
                        {
                            if (existingCustomAction.DescriptionResource.SetUserResourceValue(customAction.Description, parser))
                            {
                                isDirty = true;
                            }
                        }
            #endif
                        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.Sequence != customAction.Sequence)
                        {
                            scope.LogPropertyUpdate("Sequence");
                            existingCustomAction.Sequence = customAction.Sequence;
                            isDirty = true;
                        }
                        if (existingCustomAction.Title != parser.ParseString(customAction.Title))
                        {
                            scope.LogPropertyUpdate("Title");
                            existingCustomAction.Title = parser.ParseString(customAction.Title);
                            isDirty = true;
                        }
            #if !ONPREMISES
                        if (customAction.Title.ContainsResourceToken())
                        {
                            if (existingCustomAction.TitleResource.SetUserResourceValue(customAction.Title, parser))
                            {
                                isDirty = true;
                            }

                        }
            #endif
                        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();
                        }
                    }
                }
            }
        }
コード例 #14
0
 /// <summary>
 /// Constructor for CustomActions class
 /// </summary>
 public CustomActions()
 {
     _siteCustomActions = new CustomActionCollection(this.ParentTemplate);
     _webCustomActions  = new CustomActionCollection(this.ParentTemplate);
 }