コード例 #1
0
        private void DeploySiteCustomAction(
            object modelHost,
            SPSite site, UserCustomActionDefinition customActionModel)
        {
            var existingAction = site.UserCustomActions.FirstOrDefault(a => a.Name == customActionModel.Name);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = existingAction,
                ObjectType = typeof(SPUserCustomAction),
                ObjectDefinition = customActionModel,
                ModelHost = modelHost
            });

            if (existingAction == null)
                existingAction = site.UserCustomActions.Add();

            MapCustomAction(existingAction, customActionModel);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = existingAction,
                ObjectType = typeof(SPUserCustomAction),
                ObjectDefinition = customActionModel,
                ModelHost = modelHost
            });

            existingAction.Update();
        }
コード例 #2
0
        protected UserCustomAction GetCurrentCustomUserAction(object modelHost,
           UserCustomActionDefinition customActionModel)
        {
            UserCustomActionCollection userCustomActions = null;

            return GetCurrentCustomUserAction(modelHost, customActionModel, out userCustomActions);
        }
        public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options)
        {
            var item = (reverseHost as UserCustomActionReverseHost).HostUserCustomAction;

            var def = new UserCustomActionDefinition();

            def.Title = item.Title;
            def.Name = item.Name;
            def.Description = item.Description;

            def.Group = item.Group;

            def.ScriptSrc = item.ScriptSrc;
            def.ScriptBlock = item.ScriptBlock;

            def.Location = item.Location;
            def.Sequence = item.Sequence;

            def.Url = item.Url;

            def.RegistrationId = item.RegistrationId;
            def.RegistrationType = item.RegistrationType.ToString();

            return new UserCustomActionModelNode
            {
                Options = { RequireSelfProcessing = true },
                Value = def
            };
        }
コード例 #4
0
 private void MapCustomAction(SPUserCustomAction existringAction, UserCustomActionDefinition customAction)
 {
     existringAction.Description = customAction.Description;
     existringAction.Group = customAction.Group;
     existringAction.Location = customAction.Location;
     existringAction.Name = customAction.Name;
     existringAction.ScriptBlock = customAction.ScriptBlock;
     existringAction.ScriptSrc = customAction.ScriptSrc;
     existringAction.Title = customAction.Title;
 }
コード例 #5
0
        protected UserCustomAction GetCustomAction(SiteModelHost modelHost, UserCustomActionDefinition model)
        {
            var site = modelHost.HostSite;
            var context = site.Context;

            context.Load(site, s => s.UserCustomActions);
            context.ExecuteQuery();

            return site.UserCustomActions.FirstOrDefault(a => a.Name == model.Name);
        }
コード例 #6
0
        private SPUserCustomAction GetCurrentCustomUserAction(object modelHost, UserCustomActionDefinition customActionModel
            , out SPUserCustomActionCollection userCustomActions)
        {
            if (modelHost is SiteModelHost)
                userCustomActions = (modelHost as SiteModelHost).HostSite.UserCustomActions;
            else if (modelHost is WebModelHost)
                userCustomActions = (modelHost as WebModelHost).HostWeb.UserCustomActions;
            else if (modelHost is ListModelHost)
                userCustomActions = (modelHost as ListModelHost).HostList.UserCustomActions;
            else
            {
                throw new Exception(string.Format("modelHost of type {0} is not supported.", modelHost.GetType()));
            }

            return userCustomActions.FirstOrDefault(a => !string.IsNullOrEmpty(a.Name) && a.Name.ToUpper() == customActionModel.Name.ToUpper());
        }
コード例 #7
0
        private void DeploySiteCustomAction(object modelHost, UserCustomActionDefinition model)
        {
            UserCustomActionCollection userCustomActions = null;
            var existingAction = GetCurrentCustomUserAction(modelHost, model, out userCustomActions);

            var context = userCustomActions.Context;

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = null,
                ObjectType = typeof(UserCustomAction),
                ObjectDefinition = model,
                ModelHost = modelHost
            });

            if (existingAction == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new user custom action");
                existingAction = userCustomActions.Add();
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing user custom action");
            }

            MapCustomAction(existingAction, model);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = existingAction,
                ObjectType = typeof(UserCustomAction),
                ObjectDefinition = model,
                ModelHost = modelHost
            });


            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Calling existingAction.Update()");
            existingAction.Update();

            context.ExecuteQueryWithTrace();
        }
コード例 #8
0
        private void DeploySiteCustomAction(
            object modelHost,
            UserCustomActionDefinition customActionModel)
        {
            SPUserCustomActionCollection userCustomActions = null;
            var existingAction = GetCurrentCustomUserAction(modelHost, customActionModel, out userCustomActions);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = existingAction,
                ObjectType = typeof(SPUserCustomAction),
                ObjectDefinition = customActionModel,
                ModelHost = modelHost
            });

            if (existingAction == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new user custom action");
                existingAction = userCustomActions.Add();
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing user custom action");
            }

            MapCustomAction(existingAction, customActionModel);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = existingAction,
                ObjectType = typeof(SPUserCustomAction),
                ObjectDefinition = customActionModel,
                ModelHost = modelHost
            });

            existingAction.Update();
        }
コード例 #9
0
        private void ValidateModel(SiteModelHost siteModelHost, UserCustomActionDefinition customActionModel)
        {
            var customAction = GetCustomAction(siteModelHost, customActionModel);

            TraceUtils.WithScope(traceScope =>
            {
                var pair = new ComparePair<UserCustomActionDefinition, UserCustomAction>(customActionModel, customAction);

                traceScope.WriteLine(string.Format("Validating model:[{0}] custom action:[{1}]", customActionModel, customAction));

                traceScope.WithTraceIndent(trace => pair
                    .ShouldBeEqual(trace, m => m.Title, o => o.Title)
                    .ShouldBeEqual(trace, m => m.Description, o => o.Description)
                    .ShouldBeEqual(trace, m => m.Group, o => o.Group)
                    .ShouldBeEqual(trace, m => m.Name, o => o.Name)
                    .ShouldBeEqual(trace, m => m.Sequence, o => o.Sequence)
                    .ShouldBeEqual(trace, m => m.Location, o => o.Location));
            });
        }
コード例 #10
0
        private void DeploySiteCustomAction(SiteModelHost modelHost, UserCustomActionDefinition model)
        {
            var site = modelHost.HostSite;
            var context = site.Context;

            var existingAction = GetCustomAction(modelHost, model);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = null,
                ObjectType = typeof(UserCustomAction),
                ObjectDefinition = model,
                ModelHost = modelHost
            });

            if (existingAction == null)
                existingAction = site.UserCustomActions.Add();

            MapCustomAction(existingAction, model);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = existingAction,
                ObjectType = typeof(UserCustomAction),
                ObjectDefinition = model,
                ModelHost = modelHost
            });

            existingAction.Update();

            context.ExecuteQuery();
        }
コード例 #11
0
        private void MapCustomAction(UserCustomAction existringAction, UserCustomActionDefinition customAction)
        {
            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Updating user custom action properties.");

            existringAction.Sequence = customAction.Sequence;
            existringAction.Description = customAction.Description;
            existringAction.Group = customAction.Group;
            existringAction.Location = customAction.Location;
            existringAction.Name = customAction.Name;
            existringAction.ScriptBlock = customAction.ScriptBlock;
            existringAction.ScriptSrc = customAction.ScriptSrc;
            existringAction.Title = customAction.Title;
            existringAction.Url = customAction.Url;

            if (!string.IsNullOrEmpty(customAction.CommandUIExtension))
                existringAction.CommandUIExtension = customAction.CommandUIExtension;

            if (!string.IsNullOrEmpty(customAction.RegistrationId))
                existringAction.RegistrationId = customAction.RegistrationId;

            if (!string.IsNullOrEmpty(customAction.RegistrationType))
            {
                // skipping setup for List script 
                // System.NotSupportedException: Setting this property is not supported.  A value of List has already been set and cannot be changed.
                if (customAction.RegistrationType != BuiltInRegistrationTypes.List)
                {
                    existringAction.RegistrationType =
                        (UserCustomActionRegistrationType)
                            Enum.Parse(typeof(UserCustomActionRegistrationType), customAction.RegistrationType, true);
                }
            }

            var permissions = new BasePermissions();

            if (customAction.Rights != null && customAction.Rights.Count > 0)
            {
                foreach (var permissionString in customAction.Rights)
                    permissions.Set((PermissionKind)Enum.Parse(typeof(PermissionKind), permissionString));
            }

            existringAction.Rights = permissions;
        }
コード例 #12
0
        public void Deploy_CustomUserActions()
        {
            // Step 1, define security groups
            var signinAsDifferentUser = new UserCustomActionDefinition
            {
                Title = "Signin as different user",
                Name = "Signin as different user",
                Group = BuiltInCustomActionLocationId.Microsoft.SharePoint.StandardMenu.Groups.SiteActions,
                Location = BuiltInCustomActionLocationId.Microsoft.SharePoint.StandardMenu.Location,
                Sequence = 2000,
                Url = "~site/_layouts/closeConnection.aspx?loginasanotheruser=true"
            };

            // watch out 'customer site sync handler' log message while checking Chrome/IE with F12
            var customerSiteSyncSettings = new UserCustomActionDefinition
            {
                Title = "Customer site sync handler",
                Name = "Customer site sync handler",
                Location = "ScriptLink",
                Sequence = 2010,
                ScriptBlock = "console.log('customer site sync handler');"
            };

            var jQueryFromCDN = new UserCustomActionDefinition
            {
                Title = "jquery",
                Name = "jquery",
                Location = "ScriptLink",
                Sequence = 3000,
                ScriptSrc = "~site/Style Library/libs/jquery/1.11.1/jquery.min.js"
            };

            var jQueryFromCDNInitHandler = new UserCustomActionDefinition
            {
                Title = "jquery-init-handler",
                Name = "jquery-init-handler",
                Location = "ScriptLink",
                Sequence = 3010,
                ScriptBlock = "jQuery(document).ready( function() {  console.log('hello from jQuery'); });"
            };


            // Step 2, define web model and artifact relationships - add security groups t the web 
            var model = SPMeta2Model
                             .NewSiteModel(site =>
                             {
                                 site
                                   .AddUserCustomAction(signinAsDifferentUser)
                                   .AddUserCustomAction(customerSiteSyncSettings)
                                   .AddUserCustomAction(jQueryFromCDN)
                                   .AddUserCustomAction(jQueryFromCDNInitHandler);
                             });

            // Step 3, deploy model
            DeploySiteModel(model);
        }
コード例 #13
0
 public static ModelNode AddUserCustomAction(this ModelNode model, UserCustomActionDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
コード例 #14
0
 public static ModelNode AddUserCustomAction(this ModelNode model, UserCustomActionDefinition definition)
 {
     return AddUserCustomAction(model, definition, null);
 }
コード例 #15
0
        protected virtual void ProcessLocalization(SPUserCustomAction obj, UserCustomActionDefinition definition)
        {
            if (definition.TitleResource.Any())
            {
                foreach (var locValue in definition.TitleResource)
                    LocalizationService.ProcessUserResource(obj, obj.TitleResource, locValue);
            }

            if (definition.DescriptionResource.Any())
            {
                foreach (var locValue in definition.DescriptionResource)
                    LocalizationService.ProcessUserResource(obj, obj.DescriptionResource, locValue);
            }

            if (definition.CommandUIExtensionResource.Any())
            {
                foreach (var locValue in definition.CommandUIExtensionResource)
                    LocalizationService.ProcessUserResource(obj, obj.CommandUIExtensionResource, locValue);
            }
        }
コード例 #16
0
 protected virtual void ProcessLocalization(UserCustomAction obj, UserCustomActionDefinition definition)
 {
     ProcessGenericLocalization(obj, new Dictionary<string, List<ValueForUICulture>>
     {
         { "TitleResource", definition.TitleResource },
         { "DescriptionResource", definition.DescriptionResource },
         { "CommandUIExtensionResource", definition.CommandUIExtensionResource },
     });
 }