Exemple #1
0
        public static ESIResponse <List <T> > ESIImportCrawl <T>(string route, ESI.CharacterEnum type = ESI.CharacterEnum.None, Dictionary <string, object> parms = null, int pageSize = 1000)
        {
            if (parms == null)
            {
                parms = new Dictionary <string, object>();
            }

            int page = 1;
            ESIResponse <List <T> > response = null, result = null;

            do
            {
                var myparms = new Dictionary <string, object>(parms);
                myparms.Add("page", page);
                response = StaticInfo.GetESIResponse <List <T> >(route, type, myparms);

                if (result == null)
                {
                    result = response;
                }
                else
                {
                    result.Result.AddRange(response.Result);
                }

                page++;
            }while (response.Result.Count >= pageSize);

            return(result);
        }
Exemple #2
0
        public static ESIResponse <T> GetESIResponse <T>(string route, ESI.CharacterEnum typeenum = ESI.CharacterEnum.None, Dictionary <string, object> parms = null, string version = null)
        {
            if (version == null)
            {
                version = "latest";
            }

            route = SetPathParameters(route, typeenum, parms);

            string token = null;

            switch (typeenum)
            {
            case ESI.CharacterEnum.BuildCorp:
                token = db.Settings.BuildCorpAccessToken;
                break;

            case ESI.CharacterEnum.EmpireDonkey:
                token = db.Settings.EmpireDonkeyAccessToken;
                break;
            }

            var url = db.Settings.ESIURL
                      .AppendPathSegments(version, route);

            if (parms != null && parms.Count > 0)
            {
                url.SetQueryParams(parms);
            }

            int retry = 0;

            while (retry < 3)
            {
                try
                {
                    HttpResponseMessage result;
                    // If we got a token, use it
                    if (!string.IsNullOrEmpty(token))
                    {
                        result = url.WithOAuthBearerToken(token).GetAsync().Result;
                    }
                    else // Otherwise just query directly
                    {
                        result = url.GetAsync().Result;
                    }

                    var json = result.Content.ReadAsStringAsync().Result;

                    var response = new ESIResponse <T>()
                    {
                        CachedUntil = result.Content.Headers?.Expires?.UtcDateTime.AddSeconds(10),
                        Result      = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(json)
                    };

                    return(response);
                }
                catch (Exception ex)
                {
                    if (ex is AggregateException e)
                    {
                        ex = e.InnerException;
                    }

                    retry++;
                    Console.WriteLine("Caught an error accesing (#" + retry + ")" + url);
                    Console.WriteLine("Exception: " + ex.GetType().Name + " - " + ex.Message);
                }
            }
            Console.WriteLine("Failed to call ESI");
            Console.ReadKey();
            throw new Exception("Dead");
        }