Beispiel #1
0
        public List <int> WriteSpecListToFile()
        {
            FileStream fcreate = File.Open(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
                                           + "/Content/SpecList.json", FileMode.Create);

            fcreate.Close();


            Console.WriteLine("Getting APi");
            //Get list from API
            GetAPIClient();

            _listofSpecs = new SpecList();
            HttpResponseMessage response = APIClient.GetAsync("/v2/specializations").Result;

            int[]      idArray;
            List <int> failedList = new List <int>();

            if (response.IsSuccessStatusCode)
            {
                // Get Skill ID list
                idArray = response.Content.ReadAsAsync <int[]>().Result;

                foreach (int id in idArray)
                {
                    GW2APISpec curSpec = new GW2APISpec();
                    curSpec = GetGW2APISpec("/v2/specializations/" + id);
                    if (curSpec != null)
                    {
                        _listofSpecs.Items.Add(curSpec);
                    }
                    else
                    {
                        Console.WriteLine("Fail to get response");//fail to retrieve
                        failedList.Add(id);
                    }
                }
                StreamWriter writer = new StreamWriter(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
                                                       + "/Content/SpecList.json");

                var serializer = new JsonSerializer
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    Formatting        = Newtonsoft.Json.Formatting.Indented,
                    ContractResolver  = new DefaultContractResolver()
                    {
                        NamingStrategy = new CamelCaseNamingStrategy()
                    }
                };
                serializer.Serialize(writer, _listofSpecs.Items);
                writer.Close();
            }
            return(failedList);
        }
Beispiel #2
0
        public List <int> WriteSpecListToFile()
        {
            //used for writing new XMLs
            FileStream fcreate = File.Open(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
                                           + "/Content/SpecList.txt", FileMode.Create);

            fcreate.Close();


            Console.WriteLine("Getting APi");
            //Get list from API
            GetAPIClient();

            _listofSpecs = new SpecList();
            HttpResponseMessage response = APIClient.GetAsync("/v2/specializations").Result;

            int[]      idArray;
            List <int> failedList = new List <int>();

            if (response.IsSuccessStatusCode)
            {
                // Get Skill ID list
                idArray = response.Content.ReadAsAsync <int[]>().Result;

                foreach (int id in idArray)
                {
                    GW2APISpec curSpec = new GW2APISpec();
                    curSpec = GetGW2APISpec("/v2/specializations/" + id);
                    if (curSpec != null)
                    {
                        _listofSpecs.Items.Add(curSpec);
                    }
                    else
                    {
                        Console.WriteLine("Fail to get response");//fail to retrieve
                        failedList.Add(id);
                    }
                }
                Stream stream = System.IO.File.OpenWrite(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
                                                         + "/Content/SpecList.txt");
                Type[] tyList = { typeof(List <GW2APISpec>) };

                XmlSerializer xmlSer = new XmlSerializer(typeof(List <GW2APISpec>), tyList);
                xmlSer.Serialize(stream, _listofSpecs.Items);
                stream.Close();
            }
            return(failedList);
        }
Beispiel #3
0
        //-----------------------------------------------------------------------------
        private GW2APISpec GetGW2APISpec(string path)
        {
            if (APIClient == null)
            {
                GetAPIClient();
            }
            System.Threading.Thread.Sleep(100);
            GW2APISpec spec = null;
            //path = "/v2/specializations/" + isElite
            HttpResponseMessage response = APIClient.GetAsync(path).Result;

            if (response.IsSuccessStatusCode)
            {
                spec = response.Content.ReadAsAsync <GW2APISpec>().Result;
            }
            return(spec);
        }
Beispiel #4
0
        public GW2APISpec GetSpec(int id)
        {
            GW2APISpec spec = GetSpecList().Items.FirstOrDefault(x => x.id == id);

            return(spec);
        }
Beispiel #5
0
        public string GetAgentProfString(uint prof, uint elite)
        {
            // non player
            if (elite == 0xFFFFFFFF)
            {
                if ((prof & 0xffff0000) == 0xffff0000)
                {
                    return("GDG");
                }
                else
                {
                    return("NPC");
                }
            }
            // base profession
            else if (elite == 0)
            {
                switch (prof)
                {
                case 1:
                    return("Guardian");

                case 2:
                    return("Warrior");

                case 3:
                    return("Engineer");

                case 4:
                    return("Ranger");

                case 5:
                    return("Thief");

                case 6:
                    return("Elementalist");

                case 7:
                    return("Mesmer");

                case 8:
                    return("Necromancer");

                case 9:
                    return("Revenant");
                }
            }
            // old elite
            else if (elite == 1)
            {
                switch (prof)
                {
                case 1:
                    return("Dragonhunter");

                case 2:
                    return("Berserker");

                case 3:
                    return("Scrapper");

                case 4:
                    return("Druid");

                case 5:
                    return("Daredevil");

                case 6:
                    return("Tempest");

                case 7:
                    return("Chronomancer");

                case 8:
                    return("Reaper");

                case 9:
                    return("Herald");
                }
            }
            // new way
            else
            {
                GW2APISpec spec = GetSpec((int)elite);
                if (spec.Elite)
                {
                    return(spec.Name);
                }
                else
                {
                    return(spec.Profession);
                }
            }
            throw new InvalidDataException("Unknown profession");
        }