Exemplo n.º 1
0
        private void ButtonRemoveClick(object sender, EventArgs e)
        {
            try
            {
                TreeNode node = treeViewItems.SelectedNode;
                SPEventReceiverDefinition er = (SPEventReceiverDefinition)node.Tag;
                if (MessageBox.Show("Are you sure you want to remove this event handler?", "Event Handler Explorer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    er.Delete();
                    comboBoxEventType.SelectedIndex = -1;
                    comboBoxClasses.Items.Clear();
                    node.Parent.Nodes.Remove(node);
                    Logger(@"Event handler unregistered(iisreset needed)");

                    if (checkboxAutoIisReset.Checked)
                    {
                        LaunchPsCommand(Settings.ScriptIisReset);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger(ex.Message, Color.LightBlue);
            }
        }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            string assembly = "ExternalListEvents, Culture=neutral, Version=1.0.0.0, PublicKeyToken=f3e998418ec415ce";

            using (SPSite siteCollection = new SPSite("http://dev.wingtip13.com/bcs"))
            {
                using (SPWeb site = siteCollection.OpenWeb())
                {
                    SPList customers = site.Lists["Customers"];
                    SPEventReceiverDefinitionCollection receivers        = customers.EventReceivers;
                    SPEventReceiverDefinition           activityReceiver = null;
                    foreach (SPEventReceiverDefinition receiver in receivers)
                    {
                        if (receiver.Assembly.Equals(assembly, StringComparison.OrdinalIgnoreCase))
                        {
                            activityReceiver = receiver;
                            break;
                        }
                    }

                    if (activityReceiver != null)
                    {
                        activityReceiver.Delete();
                    }
                }
            }
        }
        private static void UpdateListItemEventReceivers(SPSite site)
        {
            //Upgrade All Lists Instances with new Event Receiver Assembly for
            //Lists based on the Training Course Content Type

            string          newAssembly   = "Contoso.TrainingManagement, Version=2.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"; //our new assembly info
            string          newClass      = "Contoso.TrainingManagement.TrainingCourseItemEventReceiver";
            SPContentTypeId contentTypeId = new SPContentTypeId(ContentTypes.TrainingCourse);                                                //our custom ctype

            foreach (SPWeb web in site.AllWebs)
            {
                using ( web )
                {
                    for (int i = 0; i < web.Lists.Count; i++)
                    {
                        SPList          list      = web.Lists[i];
                        SPContentTypeId bestMatch = list.ContentTypes.BestMatch(contentTypeId);
                        if (bestMatch.IsChildOf(contentTypeId))
                        {
                            for (int j = 0; j < list.EventReceivers.Count; j++)
                            {
                                SPEventReceiverDefinition eventReceiverDefinition = list.EventReceivers[j];
                                if (String.Compare(eventReceiverDefinition.Assembly, newAssembly, true) != 0)
                                {
                                    list.EventReceivers.Add(eventReceiverDefinition.Type, newAssembly, newClass);
                                    eventReceiverDefinition.Delete();
                                    list.Update();
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void Delete(this SPEventReceiverDefinitionCollection collection, string name)
        {
            SPEventReceiverDefinition receiverDefinition = collection.Cast <SPEventReceiverDefinition>()
                                                           .SingleOrDefault(receiver => string.Equals(receiver.Name, name));

            if (receiverDefinition != null)
            {
                receiverDefinition.Delete();
                receiverDefinition.Update();
            }
        }
Exemplo n.º 5
0
        public void DisableDiscussionBoardProcessing(SPList list)
        {
            SPEventReceiverDefinition receiver = null;

            do
            {
                receiver = list.EventReceivers.OfType <SPEventReceiverDefinition>().Where(p => string.Equals(p.Class, ReceiverType.FullName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                if (receiver != null)
                {
                    receiver.Delete();
                }
            } while (receiver != null);
        }
        public static void RemoveEventReceiver(SPList list)
        {
            SPEventReceiverDefinition receiverToDelete = null;

            foreach (SPEventReceiverDefinition receiver in list.EventReceivers)
            {
                if (receiver.Class == "MyLocalBroadband.Activities.WSS.PublishedOriginalUpdatedReceiver")
                {
                    receiverToDelete = receiver;
                }
            }
            if (receiverToDelete != null)
            {
                receiverToDelete.Delete();
            }
            list.Update();
        }
Exemplo n.º 7
0
        public static void RemoveEventReceivers(this SPList list, Type eventReceiverType, params SPEventReceiverType[] eventReceiverTypes)
        {
            List <SPEventReceiverDefinition> receivers = new List <SPEventReceiverDefinition>();

            for (int i = 0; i < list.EventReceivers.Count; ++i)
            {
                SPEventReceiverDefinition r = list.EventReceivers[i];
                if (r.Class.Equals(eventReceiverType.FullName) && (eventReceiverTypes.Length == 0 || eventReceiverTypes.Contains(r.Type)))
                {
                    receivers.Add(r);
                }
            }

            foreach (SPEventReceiverDefinition r in receivers)
            {
                r.Delete();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Unregisters a specified event receiver from the list.
        /// </summary>
        /// <param name="list">The list to use.</param>
        /// <param name="eventReceiverClassName">The name of the event receiver to remove.</param>
        public static void UnregisterEventReceivers(this SPList list, string eventReceiverClassName)
        {
            List <Guid> eventReceiverIdsToDelete = new List <Guid>();

            foreach (SPEventReceiverDefinition eventReceiver in list.EventReceivers)
            {
                if (eventReceiver.Class.Equals(eventReceiverClassName, StringComparison.OrdinalIgnoreCase))
                {
                    eventReceiverIdsToDelete.Add(eventReceiver.Id);
                }
            }

            foreach (Guid eventReceiverId in eventReceiverIdsToDelete)
            {
                SPEventReceiverDefinition eventReceiver = list.EventReceivers[eventReceiverId];
                eventReceiver.Delete();
            }
        }
        /// <summary>
        /// Subscribes to event receivers.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <param name="remove">if set to <c>true</c> [remove].</param>
        private static void SubscribeToEventReceivers(SPList list, bool remove)
        {
            Assembly assembly  = Assembly.GetExecutingAssembly();
            string   className = typeof(ApprovalWorkflowItemsEventReceivers).FullName;

            if (remove)
            {
                for (int i = 0; i < list.EventReceivers.Count; i++)
                {
                    SPEventReceiverDefinition receiver = list.EventReceivers[i];
                    if (receiver.Assembly.Equals(assembly.FullName, StringComparison.OrdinalIgnoreCase) &&
                        (receiver.Type == SPEventReceiverType.ItemCheckedIn || receiver.Type == SPEventReceiverType.ItemUpdating || receiver.Type == SPEventReceiverType.ItemUpdated))
                    {
                        receiver.Delete();
                    }
                }
            }
            else
            {
                list.EventReceivers.Add(SPEventReceiverType.ItemCheckedIn, assembly.FullName, className);
                list.EventReceivers.Add(SPEventReceiverType.ItemUpdating, assembly.FullName, className);
                list.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assembly.FullName, className);
            }
        }
Exemplo n.º 10
0
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            try
            {
                SPWeb      web          = (SPWeb)properties.Feature.Parent;
                SPWeb      parentWeb    = web.Site.RootWeb;
                SPList     eventLog     = parentWeb.Lists.TryGetList("CCPEventFeatureLog");
                SPListItem eventLogItem = eventLog.AddItem();
                SPList     proposals    = web.Lists.TryGetList("Proposals");
                SPList     contracts    = web.Lists.TryGetList("Contracts");

                if (proposals != null)                     //remove receiver from proposals
                {
                    SPEventReceiverDefinition def1 = null; //event definition
                    foreach (SPEventReceiverDefinition receiver in proposals.EventReceivers)
                    {
                        if (receiver.Name == "ListEvents")
                        {
                            def1 = receiver;
                            break;
                        } //if
                    }     //for

                    if (def1 != null)
                    {
                        def1.Delete();
                    }//if

                    //Add log to eventlog
                    eventLogItem["Proposals"] = "Receiver Removed from " + proposals.Title + " at: " + web.Title + " : " + web.Url;
                    eventLogItem.Update();
                }//if
                else
                {
                    //Add log to eventlog
                    eventLogItem["Proposals"] = "No Proposals at: " + web.Title + " : " + web.Url;
                    eventLogItem.Update();
                }

                if (contracts != null)//remove receiver from contracts
                {
                    SPEventReceiverDefinition def2 = null;

                    foreach (SPEventReceiverDefinition receiver in contracts.EventReceivers)
                    {
                        if (receiver.Name == "ListEvents")
                        {
                            def2 = receiver;
                            break;
                        } //if
                    }     //for

                    if (def2 != null)
                    {
                        def2.Delete();
                    }//if

                    //Add log to eventlog
                    eventLogItem["Contracts"] = "Receiver Remove from " + contracts.Title + " at: " + web.Title + " : " + web.Url;
                    eventLogItem.Update();
                }//if
                else
                {
                    //Add log to eventlog
                    eventLogItem["Contracts"] = "No Contracts at: " + web.Title + " : " + web.Url;
                    eventLogItem.Update();
                }
            }
            catch (Exception e)
            {
                SPWeb      web       = (SPWeb)properties.Feature.Parent;
                SPWeb      parentWeb = web.Site.RootWeb;
                SPList     eventLog  = parentWeb.Lists.TryGetList("CCPEventFeatureLog");
                SPListItem item      = eventLog.AddItem();
                item["CCPWebEvents"] = "FeatureDeactivating : " + e.Message;
                item.Update();
            }
        }
Exemplo n.º 11
0
 public void Delete()
 {
     m_eventReceiverDefinition.Delete();
 }