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); }
public static List <int> WriteSpecListToFile() { FileStream fcreate = File.Open(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(new Uri("/v2/specializations", UriKind.Relative)).Result; int[] idArray; var failedList = new List <int>(); if (response.IsSuccessStatusCode) { // Get Skill ID list idArray = JsonConvert.DeserializeObject <int[]>(response.Content.ReadAsStringAsync().Result); foreach (int id in idArray) { var curSpec = new GW2APISpec(); curSpec = GetGW2APISpec("/v2/specializations/" + id); if (curSpec != null) { _listofSpecs.Items.Add(curSpec); } else { Console.WriteLine("Failed to get response");//fail to retrieve failedList.Add(id); } } var writer = new StreamWriter(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/Content/SpecList.json"); var serializer = new JsonSerializer { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None, ContractResolver = GeneralHelper.ContractResolver }; serializer.Serialize(writer, _listofSpecs.Items); writer.Close(); } return(failedList); }
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); }