Ejemplo n.º 1
0
        public static EventReceiverDefinition RegisterEventReceiver(List list, string name, string url, EventReceiverType eventReceiverType, EventReceiverSynchronization synchronization, bool force, ClientContext clientContext)
        {
            clientContext.Load(list.EventReceivers);

            clientContext.ExecuteQuery();

            bool receiverExists = false;
            foreach (var receiver in list.EventReceivers)
            {
                if (receiver.ReceiverName == name)
                {
                    receiverExists = true;
                    if (force)
                    {
                        receiver.DeleteObject();
                        clientContext.ExecuteQuery();
                        receiverExists = false;
                    }
                }
            }
            EventReceiverDefinition def = null;
            if (!receiverExists)
            {
                EventReceiverDefinitionCreationInformation receiver = new EventReceiverDefinitionCreationInformation();
                receiver.EventType = eventReceiverType;
                receiver.ReceiverUrl = url;
                receiver.ReceiverName = name;
                receiver.Synchronization = synchronization;
                def = list.EventReceivers.Add(receiver);
                clientContext.Load(def);
                clientContext.ExecuteQuery();
            }
            return def;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers a remote event receiver
        /// </summary>
        /// <param name="web">The web to process</param>
        /// <param name="name">The name of the event receiver (needs to be unique among the event receivers registered on this list)</param>
        /// <param name="url">The URL of the remote WCF service that handles the event</param>
        /// <param name="eventReceiverType"></param>
        /// <param name="synchronization"></param>
        /// <param name="sequenceNumber"></param>
        /// <param name="force">If True any event already registered with the same name will be removed first.</param>
        /// <returns>Returns an EventReceiverDefinition if succeeded. Returns null if failed.</returns>
        public static EventReceiverDefinition AddRemoteEventReceiver(this Web web, string name, string url, EventReceiverType eventReceiverType, EventReceiverSynchronization synchronization, int sequenceNumber, bool force)
        {
            var query = from receiver
                   in web.EventReceivers
                        where receiver.ReceiverName == name
                        select receiver;
            var receivers = web.Context.LoadQuery(query);
            web.Context.ExecuteQueryRetry();

            var receiverExists = receivers.Any();
            if (receiverExists && force)
            {
                var receiver = receivers.FirstOrDefault();
                receiver.DeleteObject();
                web.Context.ExecuteQueryRetry();
                receiverExists = false;
            }
            EventReceiverDefinition def = null;

            if (!receiverExists)
            {
                EventReceiverDefinitionCreationInformation receiver = new EventReceiverDefinitionCreationInformation();
                receiver.EventType = eventReceiverType;
                receiver.ReceiverUrl = url;
                receiver.ReceiverName = name;
                receiver.SequenceNumber = sequenceNumber;
                receiver.Synchronization = synchronization;
                def = web.EventReceivers.Add(receiver);
                web.Context.Load(def);
                web.Context.ExecuteQueryRetry();
            }
            return def;
        }
        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);

            if (flag)
            {
                return(flag);
            }
            switch (peekedName)
            {
            case "ReceiverAssembly":
                flag = true;
                reader.ReadName();
                this.m_receiverAssembly = reader.ReadString();
                break;

            case "ReceiverClass":
                flag = true;
                reader.ReadName();
                this.m_receiverClass = reader.ReadString();
                break;

            case "ReceiverName":
                flag = true;
                reader.ReadName();
                this.m_receiverName = reader.ReadString();
                break;

            case "SequenceNumber":
                flag = true;
                reader.ReadName();
                this.m_sequenceNumber = reader.ReadInt32();
                break;

            case "Synchronization":
                flag = true;
                reader.ReadName();
                this.m_synchronization = reader.ReadEnum <EventReceiverSynchronization>();
                break;

            case "EventType":
                flag = true;
                reader.ReadName();
                this.m_eventType = reader.ReadEnum <EventReceiverType>();
                break;

            case "ReceiverUrl":
                flag = true;
                reader.ReadName();
                this.m_receiverUrl = reader.ReadString();
                break;
            }
            return(flag);
        }
Ejemplo n.º 4
0
  public static void AddListItemRemoteEventReceiver(ClientContext context, string listName, EventReceiverType eventType,
 EventReceiverSynchronization synchronization, string receiverName,
 string receiverUrl, int sequence, string receiverAssemblyName = "", string receiverClassName = "")
  {
      var list = context.Web.Lists.GetByTitle(listName);
      context.Load(list);
      var eventReceivers = list.EventReceivers;
      context.Load(eventReceivers);
      context.ExecuteQuery();
      var newRER = new EventReceiverDefinitionCreationInformation();
      newRER.EventType = eventType;
      newRER.ReceiverName = receiverName;
      newRER.ReceiverClass = receiverClassName;
      newRER.ReceiverAssembly = receiverAssemblyName;
      newRER.ReceiverUrl = receiverUrl;
      newRER.Synchronization = synchronization;
      newRER.SequenceNumber = sequence;
      list.EventReceivers.Add(newRER);
      list.Update();
      context.ExecuteQuery();
  }
Ejemplo n.º 5
0
        public SPOEventReceiverDefinition AddEventReceiver(
            EventReceiverType eventType,
            string receiverAssembly,
            string receiverClass,
            string receiverName,
            string receiverUrl,
            int sequenceNumber,
            EventReceiverSynchronization synchronization)
        {
            EventReceiverDefinitionCreationInformation erdci = new EventReceiverDefinitionCreationInformation
            {
                EventType        = eventType,
                ReceiverAssembly = receiverAssembly,
                ReceiverClass    = receiverClass,
                ReceiverName     = receiverName,
                ReceiverUrl      = receiverUrl,
                SequenceNumber   = sequenceNumber,
                Synchronization  = synchronization
            };

            return(AddEventReceiver(erdci));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Registers a remote event receiver
 /// </summary>
 /// <param name="web">The web to process</param>
 /// <param name="name">The name of the event receiver (needs to be unique among the event receivers registered on this list)</param>
 /// <param name="url">The URL of the remote WCF service that handles the event</param>
 /// <param name="eventReceiverType"></param>
 /// <param name="synchronization"></param>
 /// <param name="force">If True any event already registered with the same name will be removed first.</param>
 /// <returns>Returns an EventReceiverDefinition if succeeded. Returns null if failed.</returns>
 public static EventReceiverDefinition AddRemoteEventReceiver(this Web web, string name, string url, EventReceiverType eventReceiverType, EventReceiverSynchronization synchronization, bool force)
 {
     return web.AddRemoteEventReceiver(name, url, eventReceiverType, synchronization, 1000, force);
 }
Ejemplo n.º 7
0
 public static EventReceiverDefinition RegisterRemoteEventReceiver(this Web web, string name, string url, EventReceiverType eventReceiverType, EventReceiverSynchronization synchronization, bool force)
 {
     return(web.AddRemoteEventReceiver(name, url, eventReceiverType, synchronization, force));
 }
Ejemplo n.º 8
0
 public SPOEventReceiverDefinition AddEventReceiver(
     EventReceiverType eventType,
     string receiverAssembly,
     string receiverClass,
     string receiverName,
     string receiverUrl,
     int sequenceNumber,
     EventReceiverSynchronization synchronization)
 {
     EventReceiverDefinitionCreationInformation erdci = new EventReceiverDefinitionCreationInformation
     {
         EventType = eventType,
         ReceiverAssembly = receiverAssembly,
         ReceiverClass = receiverClass,
         ReceiverName = receiverName,
         ReceiverUrl = receiverUrl,
         SequenceNumber = sequenceNumber,
         Synchronization = synchronization
     };
     return AddEventReceiver(erdci);
 }
 public static EventReceiverDefinition RegisterRemoteEventReceiver(this List list, string name, string url, EventReceiverType eventReceiverType, EventReceiverSynchronization synchronization, bool force)
 {
     return list.AddRemoteEventReceiver(name, url, eventReceiverType, synchronization, force);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Registers a remote event receiver
        /// </summary>
        /// <param name="web">The web to process</param>
        /// <param name="name">The name of the event receiver (needs to be unique among the event receivers registered on this list)</param>
        /// <param name="url">The URL of the remote WCF service that handles the event</param>
        /// <param name="eventReceiverType"></param>
        /// <param name="synchronization"></param>
        /// <param name="sequenceNumber"></param>
        /// <param name="force">If True any event already registered with the same name will be removed first.</param>
        /// <returns>Returns an EventReceiverDefinition if succeeded. Returns null if failed.</returns>
        public static EventReceiverDefinition AddRemoteEventReceiver(this Web web, string name, string url, EventReceiverType eventReceiverType, EventReceiverSynchronization synchronization, int sequenceNumber, bool force)
        {
            var query = from receiver
                        in web.EventReceivers
                        where receiver.ReceiverName == name
                        select receiver;

            web.Context.LoadQuery(query);
            web.Context.ExecuteQueryRetry();

            var receiverExists = query.Any();

            if (receiverExists && force)
            {
                var receiver = query.FirstOrDefault();
                receiver.DeleteObject();
                web.Context.ExecuteQueryRetry();
                receiverExists = false;
            }
            EventReceiverDefinition def = null;

            if (!receiverExists)
            {
                EventReceiverDefinitionCreationInformation receiver = new EventReceiverDefinitionCreationInformation();
                receiver.EventType       = eventReceiverType;
                receiver.ReceiverUrl     = url;
                receiver.ReceiverName    = name;
                receiver.SequenceNumber  = sequenceNumber;
                receiver.Synchronization = synchronization;
                def = web.EventReceivers.Add(receiver);
                web.Context.Load(def);
                web.Context.ExecuteQueryRetry();
            }
            return(def);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Registers a remote event receiver
 /// </summary>
 /// <param name="site">The site collection to process</param>
 /// <param name="name">The name of the event receiver (needs to be unique among the event receivers registered on this site)</param>
 /// <param name="url">The URL of the remote WCF service that handles the event</param>
 /// <param name="eventReceiverType"></param>
 /// <param name="synchronization"></param>
 /// <param name="force">If True any event already registered with the same name will be removed first.</param>
 /// <returns>Returns an EventReceiverDefinition if succeeded. Returns null if failed.</returns>
 public static EventReceiverDefinition AddRemoteEventReceiver(this Site site, string name, string url, EventReceiverType eventReceiverType, EventReceiverSynchronization synchronization, bool force)
 {
     return(site.AddRemoteEventReceiver(name, url, eventReceiverType, synchronization, 1000, force));
 }