protected SPEventReceiverDefinition FindEventReceiverDefinition(SPEventReceiverDefinitionCollection receivers, EventReceiverDefinition definition)
        {
            var receiverName = definition.Name.ToUpper();

            return receivers.OfType<SPEventReceiverDefinition>()
                            .FirstOrDefault(r =>
                                !string.IsNullOrEmpty(r.Name) &&
                                r.Name.ToUpper() == receiverName);
        }
        protected Microsoft.SharePoint.Client.EventReceiverDefinition FindEventReceiverDefinition(EventReceiverDefinitionCollection receivers, EventReceiverDefinition definition)
        {
            var receiverName = definition.Name.ToUpper();

            receivers.Context.Load(receivers);
            receivers.Context.ExecuteQuery();

            return receivers.OfType<Microsoft.SharePoint.Client.EventReceiverDefinition>()
                            .FirstOrDefault(r =>
                                !string.IsNullOrEmpty(r.ReceiverName) &&
                                r.ReceiverName.ToUpper() == receiverName);
        }
Exemple #3
0
        private void DeployEventReceiver(object modelHost, EventReceiverDefinitionCollection eventReceivers,
                                         EventReceiverDefinition definition)
        {
            var context = eventReceivers.Context;

            var existingReceiver = FindEventReceiverDefinition(eventReceivers, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existingReceiver,
                ObjectType       = typeof(Microsoft.SharePoint.Client.EventReceiverDefinition),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            bool isNew = false;

            if (existingReceiver == null)
            {
                isNew = true;

                existingReceiver = eventReceivers.Add(new EventReceiverDefinitionCreationInformation
                {
                    ReceiverName     = definition.Name,
                    EventType        = (EventReceiverType)Enum.Parse(typeof(EventReceiverType), definition.Type),
                    Synchronization  = (EventReceiverSynchronization)Enum.Parse(typeof(EventReceiverSynchronization), definition.Synchronization),
                    ReceiverAssembly = definition.Assembly,
                    ReceiverClass    = definition.Class,
                    SequenceNumber   = definition.SequenceNumber,
                });
            }

            MapEventReceiverProperties(definition, existingReceiver, isNew);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = existingReceiver,
                ObjectType       = typeof(Microsoft.SharePoint.Client.EventReceiverDefinition),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            existingReceiver.Update();
            context.ExecuteQuery();
        }
        private void DeployEventReceiver(object modelHost, EventReceiverDefinitionCollection eventReceivers,
            EventReceiverDefinition definition)
        {
            var context = eventReceivers.Context;

            var existingReceiver = FindEventReceiverDefinition(eventReceivers, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = existingReceiver,
                ObjectType = typeof(Microsoft.SharePoint.Client.EventReceiverDefinition),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            bool isNew = false;

            if (existingReceiver == null)
            {
                isNew = true;

                existingReceiver = eventReceivers.Add(new EventReceiverDefinitionCreationInformation
                {
                    ReceiverName = definition.Name,
                    EventType = (EventReceiverType)Enum.Parse(typeof(EventReceiverType), definition.Type),
                    Synchronization = (EventReceiverSynchronization)Enum.Parse(typeof(EventReceiverSynchronization), definition.Synchronization),
                    ReceiverAssembly = definition.Assembly,
                    ReceiverClass = definition.Class,
                    SequenceNumber = definition.SequenceNumber,
                });
            }

            MapEventReceiverProperties(definition, existingReceiver, isNew);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = existingReceiver,
                ObjectType = typeof(Microsoft.SharePoint.Client.EventReceiverDefinition),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            existingReceiver.Update();
            context.ExecuteQuery();
        }
 private void DeployWebEventReceiver(object modelHost, WebModelHost listModelHost, EventReceiverDefinition definition)
 {
     DeployEventReceiver(modelHost, listModelHost.HostWeb.EventReceivers, definition);
 }
 private void DeployListEventReceiver(object modelHost, ListModelHost listModelHost, EventReceiverDefinition definition)
 {
     DeployEventReceiver(modelHost, listModelHost.HostList.EventReceivers, definition);
 }
 private void DeploySiteEventReceiver(object modelHost, SiteModelHost siteModelHost, EventReceiverDefinition definition)
 {
     DeployEventReceiver(modelHost, siteModelHost.HostSite.EventReceivers, definition);
 }
 private static void MapEventReceiverProperties(EventReceiverDefinition definition,
     Microsoft.SharePoint.Client.EventReceiverDefinition existingReceiver,
     bool isNew)
 {
     // nothing can be updated, shame :(
 }
Exemple #9
0
        protected Microsoft.SharePoint.Client.EventReceiverDefinition FindEventReceiverDefinition(EventReceiverDefinitionCollection receivers, EventReceiverDefinition definition)
        {
            var receiverName = definition.Name.ToUpper();

            receivers.Context.Load(receivers);
            receivers.Context.ExecuteQuery();

            return(receivers.OfType <Microsoft.SharePoint.Client.EventReceiverDefinition>()
                   .FirstOrDefault(r =>
                                   !string.IsNullOrEmpty(r.ReceiverName) &&
                                   r.ReceiverName.ToUpper() == receiverName));
        }
 public static ModelNode AddEventReceiver(this ModelNode model, EventReceiverDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
Exemple #11
0
 private void DeployListEventReceiver(object modelHost, ListModelHost listModelHost, EventReceiverDefinition definition)
 {
     DeployEventReceiver(modelHost, listModelHost.HostList.EventReceivers, definition);
 }
Exemple #12
0
 private void DeploySiteEventReceiver(object modelHost, SiteModelHost siteModelHost, EventReceiverDefinition definition)
 {
     DeployEventReceiver(modelHost, siteModelHost.HostSite.EventReceivers, definition);
 }
Exemple #13
0
 private static void MapEventReceiverProperties(EventReceiverDefinition definition,
                                                Microsoft.SharePoint.Client.EventReceiverDefinition existingReceiver,
                                                bool isNew)
 {
     // nothing can be updated, shame :(
 }
 private void DeployContentTypeEventReceiver(object modelHost, SPContentType contentType, EventReceiverDefinition definition)
 {
     DeployEventReceiver(modelHost, contentType.EventReceivers, definition);
 }
        private static void MapEventReceiverProperties(
            EventReceiverDefinition definition,
            SPEventReceiverDefinition existingReceiver,
            bool isNew)
        {
            existingReceiver.Name = definition.Name;
            existingReceiver.Data = definition.Data;

            if (isNew)
                existingReceiver.Type = (SPEventReceiverType)Enum.Parse(typeof(SPEventReceiverType), definition.Type);

            existingReceiver.Assembly = definition.Assembly;
            existingReceiver.Class = definition.Class;
            existingReceiver.SequenceNumber = definition.SequenceNumber;
            existingReceiver.Synchronization = (SPEventReceiverSynchronization)Enum.Parse(typeof(SPEventReceiverSynchronization), definition.Synchronization);
        }
        private void DeployEventReceiver(object modelHost, SPEventReceiverDefinitionCollection eventReceivers,
            EventReceiverDefinition definition)
        {
            var existingReceiver = FindEventReceiverDefinition(eventReceivers, definition);

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

            bool isNew = false;

            if (existingReceiver == null)
                existingReceiver = CreateNewEventReceiverDefinition(modelHost, eventReceivers, out isNew);

            MapEventReceiverProperties(definition, existingReceiver, isNew);

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

            existingReceiver.Update();
        }
Exemple #17
0
 private void DeployWebEventReceiver(object modelHost, WebModelHost listModelHost, EventReceiverDefinition definition)
 {
     DeployEventReceiver(modelHost, listModelHost.HostWeb.EventReceivers, definition);
 }
 public static ModelNode AddEventReceiver(this ModelNode model, EventReceiverDefinition definition)
 {
     return AddEventReceiver(model, definition, null);
 }