/// <summary>
    /// Trigger conversation event function.
    /// </summary>
    /// <param name="clip"></param>
    public static void TriggerConversationEvent(string sentence)
    {
        ConversationEvent thisEvent = null;

        if (instance.conversationEventDictionary.TryGetValue(CONVERSATIONEVENT, out thisEvent))
        {
            thisEvent.Invoke(sentence);
        }
    }
 public void OnSignalRaised(Conversation parameter)
 {
     Event.Invoke(parameter);
 }
示例#3
0
        private void _worker_DoWork(object sender, DoWorkEventArgs e)
        {
            var since = ReadLastPull();

            SaveLastPull(since);
            while (true)
            {
                Thread.Sleep(4000);
                var request = new RestRequest($"/sms/pushes/{since.ToString("s", CultureInfo.InvariantCulture)}",
                                              Method.GET, DataFormat.Json);
                var response = RestClient.Execute <IEnumerable <Push> >(request);
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    since = DateTime.UtcNow;
                    SaveLastPull(since);
                    continue;
                }

                if (!response.Data.Any())
                {
                    since = DateTime.UtcNow;
                    SaveLastPull(since);
                    continue;
                }

                since = response.Data.Max(d => d.DateCreated).ToUniversalTime() + TimeSpan.FromSeconds(1);
                SaveLastPull(since);

                foreach (var push in response.Data)
                {
                    switch (push.Name)
                    {
                    case "message-created":
                    {
                        var messageItem = JsonConvert.DeserializeObject <MessageItem>(push.Body);

                        var messageEventPayload = new MessageEventPayload
                        {
                            EventType   = MessageEventPayload.MessageEventType.Created,
                            MessageItem = messageItem
                        };

                        MessageEvent?.Invoke(this, messageEventPayload);
                        break;
                    }

                    case "message-deleted":
                    {
                        var messageItem = JsonConvert.DeserializeObject <MessageItem>(push.Body);

                        var messageEventPayload = new MessageEventPayload
                        {
                            EventType   = MessageEventPayload.MessageEventType.Deleted,
                            MessageItem = messageItem
                        };

                        MessageEvent?.Invoke(this, messageEventPayload);
                        break;
                    }

                    case "conversation-created":
                    {
                        var conversation = JsonConvert.DeserializeObject <Conversation>(push.Body);

                        var conversationEventPayload = new ConversationEventPayload
                        {
                            EventType        = ConversationEventPayload.ConversationEventType.Created,
                            ConversationItem = conversation
                        };

                        ConversationEvent?.Invoke(this, conversationEventPayload);
                        break;
                    }

                    case "conversation-updated":
                    {
                        var conversation = JsonConvert.DeserializeObject <Conversation>(push.Body);

                        var conversationEventPayload = new ConversationEventPayload
                        {
                            EventType        = ConversationEventPayload.ConversationEventType.Updated,
                            ConversationItem = conversation
                        };

                        ConversationEvent?.Invoke(this, conversationEventPayload);
                        break;
                    }

                    case "contact-created":
                    {
                        var contact = JsonConvert.DeserializeObject <Contact>(push.Body);
                        var payload = new ContactUpdatedPayload
                        {
                            Contact    = contact,
                            UpdateType = ContactUpdatedPayload.UpdateTypes.Created
                        };
                        ContactUpdatedEvent?.Invoke(this, payload);
                        break;
                    }

                    case "contact-updated":
                    {
                        var contact = JsonConvert.DeserializeObject <Contact>(push.Body);
                        var payload = new ContactUpdatedPayload
                        {
                            Contact    = contact,
                            UpdateType = ContactUpdatedPayload.UpdateTypes.Updated
                        };
                        ContactUpdatedEvent?.Invoke(this, payload);
                        break;
                    }
                    }
                }
            }
        }