private void OnNotificationEvent(object sender, NotificationEventArgs args)
 {
     var currentSub = _subscriptions.FirstOrDefault(x => x.Value.Id == args.Subscription.Id);
     var eventData = new SubscriptionNotificationEventCollection(currentSub.Key, args.Events);
     this._EventProcessor.Invoke(eventData);
 }
        private void OnNotificationEvent(object sender, NotificationEventArgs args)
        {
            var messages = new List<MessageReceived>();

            foreach (var argEvent in args.Events)
            {
                var mailReceivedEvent = argEvent as ItemEvent;
                if (mailReceivedEvent == null) continue;
                if (mailReceivedEvent.EventType != EventType.NewMail) continue;

                ServiceResponseCollection<GetItemResponse> items = _service.BindToItems(new[] { mailReceivedEvent.ItemId }, new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients));
                foreach (GetItemResponse item in items)
                {
                    var message = new MessageReceived();

                    message.From = ((EmailAddress)item.Item[EmailMessageSchema.From]).Address;
                    message.To = ((EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray();
                    message.Subject = item.Item.Subject;
                    message.Message = item.Item.Body.ToString();
                    if (item.Item.HasAttachments)
                    {
                        var memStreams = new List<MemoryStream>();
                        foreach (var attachment in item.Item.Attachments.Where(a => a is FileAttachment))
                        {
                            var fileAttachment = attachment as FileAttachment;
                            var ms = new MemoryStream();
                            fileAttachment.Load(ms);

                            memStreams.Add(ms);
                        }

                        message.Attachments = memStreams.ToArray();
                    }

                    //cast it to mail mesage to forward it to trello board
                    var msg = (EmailMessage)item.Item;

                    string messageBodyPrefix = "This message was sent by: " + message.From;
                    ResponseMessage responseMessage = msg.CreateForward();
                    responseMessage.ToRecipients.Add(_trelloForwardingEmailAddress);
                    responseMessage.BodyPrefix = messageBodyPrefix;
                    responseMessage.SendAndSaveCopy();

                    messages.Add(message);
                }
            }

            _callback(messages.ToArray());
        }
        /// <summary>
        /// Issues the notification events.
        /// </summary>
        /// <param name="gseResponse">The GetStreamingEvents response.</param>
        private void IssueNotificationEvents(GetStreamingEventsResponse gseResponse)
        {
            foreach (GetStreamingEventsResults.NotificationGroup events in gseResponse.Results.Notifications)
            {
                StreamingSubscription subscription = null;

                lock (this.lockObject)
                {
                    // Client can do any good or bad things in the below event handler
                    if (this.subscriptions != null && this.subscriptions.ContainsKey(events.SubscriptionId))
                    {
                        subscription = this.subscriptions[events.SubscriptionId];
                    }
                }

                if (subscription != null)
                {
                    NotificationEventArgs eventArgs = new NotificationEventArgs(
                        subscription,
                        events.Events);

                    if (this.OnNotificationEvent != null)
                    {
                        this.OnNotificationEvent(this, eventArgs);
                    }
                }
            }
        }
Esempio n. 4
0
 static void OnEvent(object sender, NotificationEventArgs args)
 {
     foreach (NotificationEvent notification in args.Events)
     {
         if (notification.EventType == EventType.NewMail && notification is ItemEvent)
         {
             Log("Zarejestrowałem nową wiadomość");
             TryGetAttachment(service, ((ItemEvent)notification).ItemId);
         }
     }
 }
 // 新しい予定を受信 !
 private void subcon_OnNotificationEvent(object sender, NotificationEventArgs args)
 {
     try
     {
         foreach (NotificationEvent notifyEvt in args.Events)
         {
             if ((notifyEvt is ItemEvent) &&
                 ((notifyEvt.EventType == EventType.Created) ||
                 (notifyEvt.EventType == EventType.Modified) ||
                 (notifyEvt.EventType == EventType.Deleted)))
             {
                 string messageType = string.Empty;
                 if (notifyEvt.EventType == EventType.Created)
                     messageType = "Created";
                 else if (notifyEvt.EventType == EventType.Modified)
                     messageType = "Modified";
                 else if (notifyEvt.EventType == EventType.Deleted)
                     messageType = "Deleted";
                 ItemEvent itemEvt = (ItemEvent)notifyEvt;
                 JsonObject jsonObj;
                 if (notifyEvt.EventType == EventType.Created)
                 {
                     Appointment ap = Appointment.Bind(sv, itemEvt.ItemId);
                     jsonObj = new JsonObject(
                         new KeyValuePair<string, JsonValue>("MessageType", messageType),
                         new KeyValuePair<string, JsonValue>("Subject", ap.Subject),
                         new KeyValuePair<string, JsonValue>("StartYear", ap.Start.Year),
                         new KeyValuePair<string, JsonValue>("StartMonth", ap.Start.Month),
                         new KeyValuePair<string, JsonValue>("StartDate", ap.Start.Day),
                         new KeyValuePair<string, JsonValue>("StartHour", ap.Start.Hour),
                         new KeyValuePair<string, JsonValue>("StartMinute", ap.Start.Minute),
                         new KeyValuePair<string, JsonValue>("StartSecond", ap.Start.Second));
                 }
                 else
                 {
                     // 注 : Modified / Deleted では、アイテムが削除されていて Bind に失敗する場合があるので、その確認をすること (ここでは、何もしない...)
                     jsonObj = new JsonObject(
                         new KeyValuePair<string, JsonValue>("MessageType", messageType));
                 }
                 this.SendMessage(jsonObj.ToString());
             }
         }
     }
     catch (Exception ex)
     {
         this.SendInternalError(ex);
     }
 }
 private void OnNotificationEvent(object sender, NotificationEventArgs args)
 {
     _meetingCacheService.ClearUpcomingAppointmentsForRoom(_roomAddress);
     _broadcastService.BroadcastUpdate(_roomAddress);
 }