Ejemplo n.º 1
0
        private BetfairServerResponse <T> ToResponse <T>(JsonResponse <T> response, DateTime requestStart, DateTime lastByteStamp, long latency)
        {
            BetfairServerResponse <T> r = new BetfairServerResponse <T>();

            r.Error        = BetfairServerException.ToClientException(response.Error);
            r.HasError     = response.HasError;
            r.Response     = response.Result;
            r.LastByte     = lastByteStamp;
            r.RequestStart = requestStart;
            return(r);
        }
Ejemplo n.º 2
0
        public BetfairServerResponse <KeepAliveResponse> KeepAliveSynchronous()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://identitysso.betfair.com/api/keepAlive");

            request.UseDefaultCredentials = true;
            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Headers.Add("X-Application", this.AppKey);
            request.Headers.Add("X-Authentication", this.SessionToken);
            request.Accept = "application/json";
            if (this.Proxy != null)
            {
                request.Proxy = this.Proxy;
            }

            TraceSource.TraceInformation("KeepAlive");
            DateTime  requestStart = DateTime.Now;
            Stopwatch watch        = new Stopwatch();

            watch.Start();

            using Stream stream       = ((HttpWebResponse)request.GetResponse()).GetResponseStream();
            using StreamReader reader = new StreamReader(stream, Encoding.Default);
            var lastByte = DateTime.Now;
            var response = JsonConvert.Deserialize <KeepAliveResponse>(reader.ReadToEnd());

            watch.Stop();
            TraceSource.TraceInformation("KeepAlive finish: {0}ms", watch.ElapsedMilliseconds);
            BetfairServerResponse <KeepAliveResponse> r = new BetfairServerResponse <KeepAliveResponse>
            {
                HasError     = !string.IsNullOrWhiteSpace(response.Error),
                Response     = response,
                LastByte     = lastByte,
                RequestStart = requestStart
            };

            return(r);
        }