Beispiel #1
0
        private async void Client1_OnReceivedMessage(object sender, CustomEventHandler e)
        {
            switch (e.Category)
            {
            case EnumNetworkCategory.None:     //this means client did not find host
                await _thisOpen !.HostNotFoundAsync(this);
                break;

            case EnumNetworkCategory.Hosting:
                IsEnabled = false;
                await _thisOpen !.HostConnectedAsync(this);
                break;

            case EnumNetworkCategory.Client:
                IsEnabled = false;

                await _thisOpen !.ConnectedToHostAsync(this, e.Message);    //i think
                break;

            case EnumNetworkCategory.CloseAll:
                throw new BasicBlankException("I don't think we will close all here.  If I am wrong, rethink");

            case EnumNetworkCategory.Message:
                SentMessage ThisData = await js.DeserializeObjectAsync <SentMessage>(e.Message);
                await ProcessDataAsync(ThisData);

                break;

            case EnumNetworkCategory.Error:
                IsEnabled = false;
                await _thisMessage.ProcessErrorAsync(e.Message);

                break;

            default:
                break;
            }
        }
Beispiel #2
0
        public async Task ProcessDataAsync(SentMessage thisData) //done.
        {
            if (IsEnabled == false)                              //no more bypass.
            {
                lock (_synLock)
                    _messages.Enqueue(thisData);
                return;
            }
            IsEnabled = false;
            if (thisData.Status == "Connection Error")
            {
                await _thisMessage.ProcessErrorAsync(thisData.Body);

                return;
            }
            if (thisData.Status == "hosting")
            {
                var open = _resolver.Resolve <IOpeningMessenger>();
                await open.HostConnectedAsync(this);

                return;
            }
            if (thisData.Status == "clienthost")
            {
                var open = _resolver.Resolve <IOpeningMessenger>();
                if (thisData.Body != "")
                {
                    await open.ConnectedToHostAsync(this, thisData.Body);

                    return;
                }
                await open.HostNotFoundAsync(this);

                return;
            }
            await _thisMessage.ProcessMessageAsync(thisData);
        }