Exemplo n.º 1
0
 private static void SetAPISkills()
 {
     if (_apiSkills.Items.Count == 0)
     {
         string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
                       + "/Content/SkillList.json";
         if (File.Exists(path))
         {
             if (new FileInfo(path).Length != 0)
             {
                 Console.WriteLine("Reading Skilllist");
                 using (var reader = new StreamReader(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
                                                      + "/Content/SkillList.json"))
                 {
                     var serializer = new JsonSerializer()
                     {
                         ContractResolver = DefaultJsonContractResolver
                     };
                     var skillList = (List <GW2APISkill>)serializer.Deserialize(reader, typeof(List <GW2APISkill>));
                     _apiSkills = new APISkills(skillList);
                     reader.Close();
                 }
             }
         }
     }
     return;
 }
Exemplo n.º 2
0
        public static List <int> WriteAPISkillsToFile()
        {
            FileStream fcreate = File.Open(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
                                           + "/Content/SkillList.json", FileMode.Create);

            fcreate.Close();


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

            var skillList = new List <GW2APISkill>();
            HttpResponseMessage response = APIClient.GetAsync(new Uri("/v2/skills", UriKind.Relative)).Result;
            var failedList = new List <int>();

            if (response.IsSuccessStatusCode)
            {
                // Get Skill ID list
                skillList.AddRange(GetGW2APISkills());
                var writer = new StreamWriter(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
                                              + "/Content/SkillList.json");
                var serializer = new JsonSerializer
                {
                    NullValueHandling    = NullValueHandling.Ignore,
                    Formatting           = Formatting.None,
                    DefaultValueHandling = DefaultValueHandling.Ignore,
                    ContractResolver     = DefaultJsonContractResolver
                };
                serializer.Serialize(writer, skillList);
                writer.Close();
            }
            _apiSkills = new APISkills(skillList);
            return(failedList);
        }