示例#1
0
        protected SPUserCustomAction GetCurrentCustomUserAction(object modelHost,
                                                                UserCustomActionDefinition customActionModel)
        {
            SPUserCustomActionCollection userCustomActions = null;

            return(GetCurrentCustomUserAction(modelHost, customActionModel, out userCustomActions));
        }
        /// <summary>
        /// Provision all pending customizations to specified web.
        /// Customizations will be shown on specified list pages, for lists with specified ID (this can be your custom list template ID),
        /// to users with appropriate rights.
        /// </summary>
        /// <param name="featureUniqueGuid">Guid, needed for feature-scoped cleanup in FeatureDeactivating using <see cref="RibbonCustomAction.RemoveAllCustomizations"/> method.</param>
        /// <param name="userCustomActions">Collection of custom actions of web or list (web.UserCustomActions or list.UserCustomActions)</param>
        /// <param name="templateId">Custom list template Id, for which ribbon elements will be registered</param>
        /// <param name="whichForms">List forms, which will display the ribbon</param>
        /// <param name="rights">Rights user needs to access the ribbon</param>
        /// <returns>Id of provisioned custom action</returns>

        // Overloads for this method are in "RibbonCustomAction/ProvisionOverloads.cs"
        public Guid Provision(Guid featureUniqueGuid, SPUserCustomActionCollection userCustomActions, string templateId, ListForms whichForms, SPBasePermissions?rights)
        {
            var customAction = userCustomActions.Add();

            customAction.Name               = "Hemrika.SharePresence.Common.Ribbon._" + featureUniqueGuid.ToString().Replace("-", "") + "._" + Guid.NewGuid().ToString().Replace("-", "");
            customAction.Location           = GetRibbonLocationByListForms(whichForms);
            customAction.CommandUIExtension = XmlGenerator.Current.GetCommandUIExtensionXML(RibbonXML, RibbonCommandsXML, RibbonTemplatesXML);
            if (customAction.Scope != SPUserCustomActionScope.List)
            {
                if (String.IsNullOrEmpty(templateId) || templateId == ((int)ListTypes.All).ToString())
                {
                    customAction.RegistrationType = SPUserCustomActionRegistrationType.ContentType;
                    customAction.RegistrationId   = "0x";
                }
                else if (templateId != ((int)ListTypes.None).ToString())
                {
                    customAction.RegistrationType = SPUserCustomActionRegistrationType.List;
                    customAction.RegistrationId   = templateId;
                }
            }
            if (rights.HasValue)
            {
                customAction.Rights = rights.Value;
            }

            customAction.Update();

            return(customAction.Id);
        }
示例#3
0
        public SPUserCustomActionCollectionInstance(ObjectInstance prototype, SPUserCustomActionCollection userCustomActionCollection)
            : this(prototype)
        {
            if (userCustomActionCollection == null)
            {
                throw new ArgumentNullException("userCustomActionCollection");
            }

            m_userCustomActionCollection = userCustomActionCollection;
        }
        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());
        }
示例#5
0
 private void DeleteCustomAction(SPList spList)
 {
     try
     {
         SPUserCustomActionCollection customActions = spList.UserCustomActions;
         foreach (var customAction in customActions.Where(customAction => customAction.Title == Const.DownloadCustomActionTitle))
         {
             customAction.Delete();
             spList.Update();
             break;
         }
     }
     catch (Exception ex)
     {
         WriteExToLog(ex);
     }
 }
示例#6
0
        public static void AddECBMenu(this SPList list, string title, string location, string url, SPBasePermissions basePermission)
        {
            SPUserCustomActionCollection spUserCustomActionCollection = list.UserCustomActions;
            var spUserCustomAction = spUserCustomActionCollection.FirstOrDefault(p => p.Title == title);

            if (spUserCustomAction == null)
            {
                spUserCustomAction          = spUserCustomActionCollection.Add();
                spUserCustomAction.Location = location;
                spUserCustomAction.Sequence = 100;
                spUserCustomAction.Title    = title;
                if (basePermission != null)
                {
                    spUserCustomAction.Rights = basePermission;
                }
                spUserCustomAction.Url = url;
                spUserCustomAction.Update();
            }
        }
示例#7
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();
        }
示例#8
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()));
        }
示例#9
0
        private bool IsMultiDownloadEnable(SPList spList)
        {
            SPUserCustomActionCollection customActions = spList.UserCustomActions;

            return(customActions.Any(customAction => customAction.Title == Const.DownloadCustomActionTitle && customAction.Location == "CommandUI.Ribbon"));
        }