private static void SetAPITraits() { if (_apiTraits.Items.Count == 0) { string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/Content/TraitList.json"; if (File.Exists(path)) { if (new FileInfo(path).Length != 0) { Console.WriteLine("Reading Traitlist"); using (var reader = new StreamReader(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/Content/TraitList.json")) { var serializer = new JsonSerializer() { ContractResolver = DefaultJsonContractResolver }; var traitList = (List <GW2APITrait>)serializer.Deserialize(reader, typeof(List <GW2APITrait>)); _apiTraits = new APITraits(traitList); reader.Close(); } } } } return; }
public static List <int> WriteAPITraitsToFile() { FileStream fcreate = File.Open(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/Content/TraitList.json", FileMode.Create); fcreate.Close(); Console.WriteLine("Getting API"); //Get list from API GetAPIClient(); var traitList = new List <GW2APITrait>(); HttpResponseMessage response = APIClient.GetAsync(new Uri("/v2/traits", UriKind.Relative)).Result; var failedList = new List <int>(); if (response.IsSuccessStatusCode) { // Get Skill ID list traitList.AddRange(GetListGW2APITraits()); var writer = new StreamWriter(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/Content/TraitList.json"); var serializer = new JsonSerializer { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None, DefaultValueHandling = DefaultValueHandling.Ignore, ContractResolver = DefaultJsonContractResolver }; serializer.Serialize(writer, traitList); writer.Close(); } _apiTraits = new APITraits(traitList); return(failedList); }