public List <SniperInfo> FindAll()
        {
            TrackemonSession session = FindSessionId();

            if (session == null || !session.validate())
            {
                session = FindSessionId();
                if (session == null)
                {
                    Log.Debug("Trackemon: No valid session found!");
                    return(null);
                }
            }
            List <SniperInfo> list = new List <SniperInfo>();

            IEnumerable <List <PokemonId> > pokemonTypeIdPartitions = Partitioner.Partition(pokemonIdsToFind, 5);

            foreach (List <PokemonId> partition in pokemonTypeIdPartitions)
            {
                List <SniperInfo> resultList = findSubSetOfPokemon(partition, session);
                if (resultList != null)
                {
                    list.AddRange(resultList);
                }
            }

            return(list);
        }
Beispiel #2
0
        private List <SniperInfo> findSubSetOfPokemon(List <PokemonId> pokemomnIds, TrackemonSession session)
        {
            String            pokemonTypeIds = buildPokemonTypeIds(pokemomnIds);
            List <SniperInfo> list           = new List <SniperInfo>();

            string URL = $"https://www.trackemon.com/fetch/rare?pokedexTypeId={pokemonTypeIds}&sessionId={session.sessionId}";

            try
            {
                var request = WebRequest.CreateHttp(URL);
                request.Accept  = "*/*";
                request.Method  = "GET";
                request.Timeout = timeout;
                request.Headers.Add("Cookie:" + session.cookieHeader);
                using (var response = request.GetResponse())
                {
                    Thread.Sleep(3 * 1000);
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        List <TrackemonResult> resultList = JsonConvert.DeserializeObject <List <TrackemonResult> >(reader.ReadToEnd());
                        foreach (TrackemonResult result in resultList)
                        {
                            SniperInfo sniperInfo = map(result);
                            if (sniperInfo != null)
                            {
                                list.Add(sniperInfo);
                            }
                        }
                    }

                    return(list);
                }
            }
            catch (Exception e)
            {
                Log.Debug("Trackemon API error: {0}", e.Message);
                return(null);
            }
        }
Beispiel #3
0
        public TrackemonSession FindSessionId()
        {
            var trackemonSession = new TrackemonSession();

            try
            {
                var          cookieContainer = new CookieContainer();
                const string homepageUrl     = "https://www.trackemon.com";
                var          request         = WebRequest.CreateHttp(homepageUrl);
                request.Method          = "GET";
                request.Timeout         = Timeout;
                request.CookieContainer = cookieContainer;
                using (var response = request.GetResponse())
                {
                    var cookieHeader = cookieContainer.GetCookieHeader(new Uri("https://www.trackemon.com"));
                    trackemonSession.cookieHeader = cookieHeader;
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        string line;

                        while ((line = reader.ReadLine()) != null)
                        {
                            var match = Regex.Match(line, @"var\s+sessionId\s*=\s*\'(1?.*)\'\s*;");
                            if (match.Success)
                            {
                                trackemonSession.sessionId = match.Groups[1].Value;
                                return(trackemonSession);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Debug("Error trying to get a sessionId for Trackemon: {0}", e.Message);
            }
            return(null);
        }
        public TrackemonSession FindSessionId()
        {
            var trackemonSession = new TrackemonSession();
            try
            {
                var cookieContainer = new CookieContainer();
                const string homepageUrl = "https://www.trackemon.com";
                var request = WebRequest.CreateHttp(homepageUrl);
                request.Method = "GET";
                request.Timeout = Timeout;
                request.CookieContainer = cookieContainer;
                using (var response = request.GetResponse())
                {
                    var cookieHeader = cookieContainer.GetCookieHeader(new Uri("https://www.trackemon.com"));
                    trackemonSession.cookieHeader = cookieHeader;
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        string line;

                        while ((line = reader.ReadLine()) != null)
                        {
                            var match = Regex.Match(line, @"var\s+sessionId\s*=\s*\'(1?.*)\'\s*;");
                            if (match.Success)
                            {
                                trackemonSession.sessionId = match.Groups[1].Value;
                                return trackemonSession;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Debug("Error trying to get a sessionId for Trackemon: {0}", e.Message);
            }
            return null;
        }
        private List<SniperInfo> findSubSetOfPokemon(List<PokemonId> pokemomnIds, TrackemonSession session)
        {
            String pokemonTypeIds = buildPokemonTypeIds(pokemomnIds);
            List<SniperInfo> list = new List<SniperInfo>();

            string URL = $"https://www.trackemon.com/fetch/rare?pokedexTypeId={pokemonTypeIds}&sessionId={session.sessionId}";
            try
            {
                var request = WebRequest.CreateHttp(URL);
                request.Accept = "*/*";
                request.Method = "GET";
                request.Timeout = timeout;
                request.Headers.Add("Cookie:" + session.cookieHeader);
                using (var response = request.GetResponse())
                {
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        List<TrackemonResult> resultList = JsonConvert.DeserializeObject<List<TrackemonResult>>(reader.ReadToEnd());
                        foreach (TrackemonResult result in resultList)
                        {
                            SniperInfo sniperInfo = map(result);
                            if (sniperInfo != null)
                            {
                                list.Add(sniperInfo);
                            }
                        }
                    }

                    return list;
                }
            }
            catch (Exception e)
            {
                Log.Debug("Trackemon API error: {0}", e.Message);
                return null;
            }
        }