示例#1
0
        public void Connect(string _username)
        {
            Connection = new HubConnection(BASE_URL, new Dictionary <string, string>
            {
                { "username", _username }
            });

            Proxy = Connection.CreateHubProxy("ChatHub");

            Proxy.On <string, string>("GetMessage", (username, message) =>
            {
                OnGetMessage?.Invoke(username, message);
            });

            Proxy.On <string>("GetMe", (message) =>
            {
                OnGetMyMessage?.Invoke(message);
            });


            Proxy.On <string>("GetInfo", (info) =>
            {
                OnGetInfo?.Invoke(info);
            });

            Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    ConnectionErrorOcurned?.Invoke();
                }
            });
        }
示例#2
0
 protected void NotifyListener(string message)
 {
     if (message != string.Empty)
     {
         OnGetMessage?.Invoke(message);
     }
 }
示例#3
0
        void OnSocketMessage(object sender, MessageEventArgs e)
        {
            var parser  = new MessageParser(e.Data);
            var message = parser.GetObject();

            // All events are fired from the main thread
            Dispatcher.Enqueue(() => {
                OnGetMessage.TryInvoke(message);
                switch (parser.Path.ToLower())
                {
                case "turn.start":
                    OnTurnStart.TryInvoke(message as TurnStartMessage);
                    break;

                case "turn.end":
                    m_Socket.Send(BingUtils.TurnEndAcknowledgement());
                    m_Buffer = new byte[0];
                    OnTurnEnd.TryInvoke(message as TurnEndMessage);

                    Status = BingStatus.Disconnecting;
                    m_Socket.CloseAsync(() => {
                        Connect();
                    });
                    break;

                case "speech.enddetected":
                    OnSpeechEndDetected.TryInvoke(message as SpeechEndDetectedMessage);
                    break;

                case "speech.phrase":
                    OnSpeechPhrase.TryInvoke(message as SpeechPhraseMessage);
                    break;

                case "speech.hypothesis":
                    OnSpeechHypothesis.TryInvoke(message as SpeechHypothesisMessage);
                    break;

                case "speech.startdetected":
                    OnSpeechStartDetected.TryInvoke(message as SpeechStartDetectedMessage);
                    break;

                case "speech.fragment":
                    OnSpeechFragment.TryInvoke(message as SpeechFragmentMessage);
                    break;
                }
            });
        }
示例#4
0
文件: Client.cs 项目: liorkatiy/Chat
        //Gets Called When The Server Send Status.Message
        void GetMessage(Message msg)
        {
            switch (msg.Type)
            {
            case MessageType.Global:
                OnGetMessage?.Invoke(msg);
                break;

            case MessageType.Private:
                PrivateChat.GetMessage((Message <int>)msg);
                break;

            case MessageType.Group:
                GroupChat.GetMessage((Message <Guid>)msg);
                break;
            }
        }
        public void Execute(OnGetMessage pipelineEvent)
        {
            var state = pipelineEvent.Pipeline.State;
            var queue = state.GetWorkQueue();

            Guard.AgainstNull(queue, nameof(queue));

            var receivedMessage = queue.GetMessage();

            // Abort the pipeline if there is no message on the queue
            if (receivedMessage == null)
            {
                _events.OnQueueEmpty(this, new QueueEmptyEventArgs(pipelineEvent, queue));
                pipelineEvent.Pipeline.Abort();
            }
            else
            {
                state.SetProcessingStatus(ProcessingStatus.Active);
                state.SetWorking();
                state.SetReceivedMessage(receivedMessage);
            }
        }
示例#6
0
 private void MessageSender_OnRead(object sender, string e)
 {
     OnGetMessage?.Invoke(sender, e);
 }