public void Load_Content() { var index = App.Global.Book_ViewModel.chapter_link.FindIndex(e => e.Contains(_Current_Chapter.link)); var contents_dir = App.Global.Book_Directory + "\\content"; var chapter_dir = App.Global.Book_Directory + "\\content\\" + index + ".json"; if (File.Exists(chapter_dir)) { Console.WriteLine(1); using (StreamReader file = File.OpenText(chapter_dir)) { JsonSerializer serializer = new JsonSerializer(); _Current_Chapter_Content = (Chapter_Content)serializer.Deserialize(file, typeof(Chapter_Content)); } } else { int count = 0; // Console.WriteLine(App.Global.Book_Directory + "\\content\\" + index + ".json"); while (true) { try { var json = new WebClient().DownloadString(App.Global.API_URL_Primary + "/api/chapters?url=" + _Current_Chapter.link); _Current_Chapter_Content = JsonConvert.DeserializeObject <Chapter_Content>(json); if (!Directory.Exists(contents_dir)) { Directory.CreateDirectory(contents_dir); } File.WriteAllText(chapter_dir, json); App.Global.Book_ViewModel.Downloaded_Chapters_index.Add(index); return; } catch (Exception e) { count++; if (count > 3) { _Current_Chapter_Content = new Chapter_Content() { content = "" }; MessageBox.Show("Error while processing, please try again later!"); return; } } } } }
public Chapter_ViewModel() { _Chapter = new List <Chapter>(); _Current_Chapter_Content = new Chapter_Content(); _Current_Chapter = new Chapter(); }