Ejemplo n.º 1
0
        private bool SubscriptionHandler(SocketSubscription subscription, JToken data)
        {
            var evnt = subscription.GetWaitingEvent(SubscriptionEvent);

            if (evnt == null)
            {
                return(false);
            }

            if (((int?)data["id"])?.ToString() != evnt.WaitingId)
            {
                return(false);
            }

            var authResponse = Deserialize <CoinExSocketRequestResponse <CoinExSocketRequestResponseMessage> >(data, false);

            if (!authResponse.Success)
            {
                log.Write(LogVerbosity.Warning, "Subscription failed: " + authResponse.Error);
                subscription.SetEventById(evnt.WaitingId, false, authResponse.Error);
                return(true);
            }

            if (authResponse.Data.Error != null)
            {
                log.Write(LogVerbosity.Debug, $"Failed to subscribe: {authResponse.Data.Error.Code} {authResponse.Data.Error.Message}");
                subscription.SetEventById(evnt.WaitingId, false, new ServerError(authResponse.Data.Error.Code, authResponse.Data.Error.Message));
                return(true);
            }

            log.Write(LogVerbosity.Debug, "Subscription completed");
            subscription.SetEventById(evnt.WaitingId, true, null);
            return(true);
        }
Ejemplo n.º 2
0
        private bool DataHandlerQuery(SocketSubscription subscription, JToken data, Action <JToken[]> handler)
        {
            var evnt = subscription.GetWaitingEvent(DataEvent);

            if (evnt == null)
            {
                return(false);
            }

            if (((int?)data["id"])?.ToString() != evnt.WaitingId)
            {
                return(false);
            }

            if (data["result"].Type == JTokenType.Null)
            {
                subscription.SetEventById(evnt.WaitingId, false, new ServerError((int)data["error"]["code"], (string)data["error"]["message"]));
            }
            else
            {
                handler(new[] { data["result"] });
                subscription.SetEventById(evnt.WaitingId, true, null);
            }
            return(true);
        }