Пример #1
0
        public virtual void OnNoticeReceived(AVIMNotice notice)
        {
            var response = new PlayResponse(notice.RawData);

            if (response.IsSuccessful)
            {
                if (Done != null)
                {
                    Done(Command, response);
                }
            }
            //Play.LogCommand(Command, null, Play.CommandType.WebSocket);
            //Play.LogCommand(null, response, Play.CommandType.WebSocket);
            if (EventCode != PlayEventCode.None)
            {
                var next = PlayStateMachine.Next(EventCode, response);
                if (response.IsSuccessful)
                {
                    Play.InvokeEvent(next);
                }
                else
                {
                    Play.InvokeEvent(next, response.ErrorCode, response.ErrorReason);
                }
            }
            Play.UnsubscribeNoticeReceived(this);
        }
Пример #2
0
        internal static void RunHttpCommand(PlayCommand command, PlayEventCode eventCode = PlayEventCode.None, Action <PlayCommand, PlayResponse> done = null)
        {
            if (eventCode != PlayEventCode.None)
            {
                Play.InvokeEvent(eventCode);
            }
            var httpRequest = command.HttpEncode;

            Play.ExecuteHttp(httpRequest, (tuple =>
            {
                int statusCode = (int)HttpStatusCode.BadRequest;
                IDictionary <string, object> body = new Dictionary <string, object>();
                try
                {
                    body = Json.Parse(tuple.Item2) as IDictionary <string, object>;
                    statusCode = (int)tuple.Item1;
                }
                catch
                {
                }
                var response = new PlayResponse()
                {
                    Body = body as IDictionary <string, object>,
                    StatusCode = (int)tuple.Item1
                };

                if (response.IsSuccessful)
                {
                    LogCommand(command, response);
                    if (done != null)
                    {
                        done(command, response);
                    }
                }
                else
                {
                    LogCommand(command, response, printer: ErrorLogger);
                }

                if (eventCode != PlayEventCode.None)
                {
                    var next = PlayStateMachine.Next(eventCode, response);
                    if (response.IsSuccessful)
                    {
                        Play.InvokeEvent(next);
                    }
                    else
                    {
                        Play.InvokeEvent(next, response.ErrorCode, response.ErrorReason);
                    }
                }
            }));
        }