async Task BindReleasesExecute() { _releasesItems.Clear(); var relationlist = new List <string>(); await Task.Run(() => { relationlist = LoadRelations().Result; }); //for (int i = 0; i < relationlist.Count; i++) //{ // _releasesItems.Add(new ReleasesViewModelCollection // { // ReleasesModel = new ReleasesModel // { // Title = relationlist[i] // } // }); //} List <string> relList = new List <string>(); for (int i = 0; i < relationlist.Count; i++) { relList.Add(relationlist[i]); } _releasesItems.AddRange(relList); }
async Task BindCharacterDataExecute() { try { if (StaticClass.Vnid > 0) { PreviousButtonEnabled = true; NextButtonEnabled = true; } var charData = new List <List <string[]> >(); var TraitList = new List <string[]>(); if (File.Exists(StaticClass.CurrentDirectory + @"\config.json")) { var jsonString = File.ReadAllText(StaticClass.CurrentDirectory + @"\config.json"); var jsonData = JsonConvert.DeserializeObject <ConfigRootObject>(jsonString); foreach (var vn in jsonData.unique) { if (vn.VnId == StaticClass.Vnid) { StaticClass.CharacterSpoilerLevel = vn.CharacterSpoilerLevel; break; } } } await Task.Run(() => { charData = LoadMainCharacterData().Result; }); if (Convert.ToInt32(charData[CurrentCharacterCount][0][14]) > StaticClass.CharacterSpoilerLevel) { await NextCharacterDataExecute(); //loads the next image if the first character is a spoiler } CurrentCharacterId = charData[CurrentCharacterCount][0][0]; ConvertRichTextDocument convRTD = new ConvertRichTextDocument(); CharacterModel.Description = convRTD.ConvertToFlowDocument(charData[CurrentCharacterCount][0][7]); CharacterModel.Name = charData[CurrentCharacterCount][0][1]; CharacterModel.Original = charData[CurrentCharacterCount][0][2]; CharacterModel.Gender = charData[CurrentCharacterCount][0][3]; CharacterModel.BloodType = charData[CurrentCharacterCount][0][4]; CharacterModel.Birthday = charData[CurrentCharacterCount][0][5]; CharacterModel.Aliases = charData[CurrentCharacterCount][0][6]; //CharacterModel.Description = charData[CurrentCharacterCount][0][7]; CharacterModel.Bust = charData[CurrentCharacterCount][0][9]; CharacterModel.Waist = charData[CurrentCharacterCount][0][10]; CharacterModel.Hips = charData[CurrentCharacterCount][0][11]; CharacterModel.Height = charData[CurrentCharacterCount][0][12]; CharacterModel.Weight = charData[CurrentCharacterCount][0][13]; if (!Directory.Exists(StaticClass.CurrentDirectory + @"\data\character\" + StaticClass.Vnid)) { Directory.CreateDirectory(StaticClass.CurrentDirectory + @"\data\character\" + StaticClass.Vnid); } string charimg = StaticClass.CurrentDirectory + @"\data\character\" + StaticClass.Vnid + @"\" + charData[CurrentCharacterCount][0][0] + ".jpg"; if (File.Exists(charimg)) { var source = new BitmapImage(); source.BeginInit(); source.UriSource = new Uri(charimg, UriKind.RelativeOrAbsolute); source.CacheOption = BitmapCacheOption.OnLoad; source.EndInit(); CharacterModel.CharImage = source; } else { WebClient client = new WebClient(); client.DownloadFile(new Uri(charData[CurrentCharacterCount][0][8]), StaticClass.CurrentDirectory + @"\data\character\" + StaticClass.Vnid + @"\" + CurrentCharacterId + ".jpg"); string path = StaticClass.CurrentDirectory + @"\data\character\" + StaticClass.Vnid + @"\" + CurrentCharacterId + ".jpg"; var source = new BitmapImage(); source.BeginInit(); source.UriSource = new Uri(charimg, UriKind.RelativeOrAbsolute); source.CacheOption = BitmapCacheOption.OnLoad; source.EndInit(); CharacterModel.CharImage = source; } await Task.Run(() => { TraitList = LoadTraits(charData[CurrentCharacterCount][0][0]).Result; }); if (_charTraits != null) { List <string> traitList = new List <string>(); _charTraits.Clear(); for (int i = 0; i < TraitList.Count; (i)++) { if (Convert.ToInt32(TraitList[i][1]) <= StaticClass.CharacterSpoilerLevel) { traitList.Add(TraitList[i][0]); } } CharacterViewModelTraits.AddRange(traitList); } if (CurrentCharacterCount == 0) { PreviousButtonEnabled = false; } else if (CurrentCharacterCount == CharacterCountMax) { NextButtonEnabled = false; } } catch (Exception ex) { using (StreamWriter sw = File.AppendText(StaticClass.CurrentDirectory + @"\debug.log")) { sw.WriteLine(DateTime.Now); sw.WriteLine("Exception Found:\tType: {0}", ex.GetType().FullName); sw.WriteLine("Class File: CharacterViewModel.cs"); sw.WriteLine("Method Name: BindCharacterDataExecute"); sw.WriteLine("\nMessage: {0}", ex.Message); sw.WriteLine("Source: {0}", ex.Source); sw.WriteLine("StackTrace: {0}", ex.StackTrace); sw.WriteLine("Target Site: {0}", ex.TargetSite); sw.WriteLine("\n\n"); } throw; } }
async Task BindVnDataExecute() { try { if (StaticClass.Vnid > 0) { string[] VnApiData = { }; string[] TimePlayed = { }; string[] Developers = { }; var Taglist = new List <string[]>(); var RelationItems = new List <string[]>(); if (File.Exists(StaticClass.CurrentDirectory + @"\config.json")) { var jsonString = File.ReadAllText(StaticClass.CurrentDirectory + @"\config.json"); var jsonData = JsonConvert.DeserializeObject <ConfigRootObject>(jsonString); foreach (var vn in jsonData.unique) { if (vn.VnId == StaticClass.Vnid) { StaticClass.VnSpoilerLevel = vn.VnSpoilerLevel; break; } } } await Task.Run(() => { VnApiData = LoadNovelSQLData(11, new string[] { "VnId", "title", "original", "aliases", "released", "length", "description", "popularity", "rating", "image", "image_nsfw" }, "SELECT * FROM VnAPI WHERE VnId=").Result; TimePlayed = LoadNovelSQLData(2, new[] { "PlayTime", "LastPlayed" }, "Select * FROM NovelPath WHERE VnId=").Result; Developers = LoadNovelSQLData(1, new[] { "ProducerName" }, "SELECT * FROM ReleaseAPI WHERE ProducerDeveloper='True' AND VnId=").Result; }); ConvertRichTextDocument convRTD = new ConvertRichTextDocument(); VnInfoModel.VnDescription = convRTD.ConvertToFlowDocument(VnApiData[6]); //VisualNovelsInformation.vndesc.Document = convRTD.ConvertToFlowDocument(VnApiData[6]); //var flowdocument = new FlowDocument(); //var paragraph= new Paragraph(); //flowdocument.Blocks.Add(paragraph); //paragraph.Inlines.Add(new Run("no tag selected")); VnInfoModel.Name = VnApiData[1]; VnInfoModel.Original = VnApiData[2]; VnInfoModel.Aliases = VnApiData[3]; VnInfoModel.Released = VnApiData[4]; VnInfoModel.Length = VnApiData[5]; //VnInfoModel.VnDescription = VnApiData[6]; VnInfoModel.Popularity = VnApiData[7]; VnInfoModel.Rating = VnApiData[8]; //VnInfoModel.TagDescription = "no tag selected"; VnInfoModel.Developers = Developers[0]; #region playtime var tmpSplitPlayTime = TimePlayed[0].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List <int> timecount = new List <int>(); for (int i = 0; i < tmpSplitPlayTime.Count(); i++) { timecount.Add(new int()); timecount[i] = Convert.ToInt32(tmpSplitPlayTime[i]); } TimeSpan timeSpan = new TimeSpan(timecount[0], timecount[1], timecount[2], timecount[3]); if (timeSpan.Days == 0 && timeSpan.Hours == 0 && timeSpan.Minutes == 0) { VnInfoModel.PlayTime = "< 1 minute"; } else { string formatted = string.Format("{0}{1}{2}", timeSpan.Duration().Days > 0 ? string.Format("{0:0} day{1}, ", timeSpan.Days, timeSpan.Days == 1 ? String.Empty : "s") : string.Empty, timeSpan.Duration().Hours > 0 ? string.Format("{0:0} hour{1}, ", timeSpan.Hours, timeSpan.Hours == 1 ? String.Empty : "s") : string.Empty, timeSpan.Duration().Minutes > 0 ? string.Format("{0:0} minute{1} ", timeSpan.Minutes, timeSpan.Minutes == 1 ? String.Empty : "s") : string.Empty); VnInfoModel.PlayTime = formatted; } if (TimePlayed[1] == "") { VnInfoModel.LastPlayed = "Never"; } else { if ((Convert.ToDateTime(TimePlayed[1]) - DateTime.Today).Days > -7)//need to set to negative, for the difference in days { if (Convert.ToDateTime(TimePlayed[1]) == DateTime.Today) { VnInfoModel.LastPlayed = "Today"; } else if ((Convert.ToDateTime(TimePlayed[1]) - DateTime.Today).Days > -2 && (Convert.ToDateTime(TimePlayed[1]) - DateTime.Today).Days < 0) { VnInfoModel.LastPlayed = "Yesterday"; } else { VnInfoModel.LastPlayed = Convert.ToDateTime(TimePlayed[1]).DayOfWeek.ToString(); } } else { VnInfoModel.LastPlayed = TimePlayed[1]; } } #endregion #region nsfw if (VnApiData[10] == "True") { if (StaticClass.NsfwEnabled == false) { string path = StaticClass.CurrentDirectory + @"\res\nsfw\cover.jpg"; var source = new BitmapImage(); source.BeginInit(); source.UriSource = new Uri(path, UriKind.RelativeOrAbsolute); source.CacheOption = BitmapCacheOption.OnLoad; source.EndInit(); VnInfoModel.VnImage = source; } else { if (File.Exists(StaticClass.CurrentDirectory + @"\data\cover\" + VnApiData[0])) { string path = StaticClass.CurrentDirectory + @"\data\cover\" + VnApiData[0]; var source = new BitmapImage(); source.BeginInit(); source.UriSource = new Uri(path, UriKind.RelativeOrAbsolute); source.CacheOption = BitmapCacheOption.OnLoad; source.EndInit(); VnInfoModel.VnImage = source; } else { WebClient client = new WebClient(); client.DownloadFile(new Uri(VnApiData[9]), StaticClass.CurrentDirectory + @"\data\cover\" + VnApiData[0]); string path = StaticClass.CurrentDirectory + @"\data\cover\" + VnApiData[0]; var source = new BitmapImage(); source.BeginInit(); source.UriSource = new Uri(path, UriKind.RelativeOrAbsolute); source.CacheOption = BitmapCacheOption.OnLoad; source.EndInit(); VnInfoModel.VnImage = source; } } } else { if (File.Exists(StaticClass.CurrentDirectory + @"\data\cover\" + VnApiData[0] + ".jpg")) { string path = StaticClass.CurrentDirectory + @"\data\cover\" + VnApiData[0] + ".jpg"; var source = new BitmapImage(); source.BeginInit(); source.UriSource = new Uri(path, UriKind.RelativeOrAbsolute); source.CacheOption = BitmapCacheOption.OnLoad; source.EndInit(); VnInfoModel.VnImage = source; } else { WebClient client = new WebClient(); client.DownloadFile(new Uri(VnApiData[9]), StaticClass.CurrentDirectory + @"\data\cover\" + VnApiData[0] + ".jpg"); string path = StaticClass.CurrentDirectory + @"\data\cover\" + VnApiData[0] + ".jpg"; var source = new BitmapImage(); source.BeginInit(); source.UriSource = new Uri(path, UriKind.RelativeOrAbsolute); source.CacheOption = BitmapCacheOption.OnLoad; source.EndInit(); VnInfoModel.VnImage = source; } } #endregion await Task.Run(() => { Taglist = LoadTags().Result; RelationItems = LoadRelations().Result; }); if (_vnInfoTags != null) { List <string> tgList = new List <string>(); _vnInfoTags.Clear();//clears observable collection so the new items don't add to existing list for (int i = 0; i < Taglist.Count; (i)++) { if (Convert.ToInt32(Taglist[i][1]) <= StaticClass.VnSpoilerLevel) { tgList.Add(Taglist[i][0]); } } VnInfoViewModelTags.AddRange(tgList); } if (_vnInfoRelations != null) { List <string> relList = new List <string>(); _vnInfoRelations.Clear(); for (int i = 0; i < RelationItems.Count; i++) { relList.Add(RelationItems[i][0] + ", " + RelationItems[i][1] + ", " + RelationItems[i][2]); } VnInfoViewModelRelations.AddRange(relList); } } else { } } catch (Exception ex) { using (StreamWriter sw = File.AppendText(StaticClass.CurrentDirectory + @"\debug.log")) { sw.WriteLine(DateTime.Now); sw.WriteLine("Exception Found:\tType: {0}", ex.GetType().FullName); sw.WriteLine("Class File: VnInfoViewModel.cs"); sw.WriteLine("Method Name: BindVnDataExecute"); sw.WriteLine("\nMessage: {0}", ex.Message); sw.WriteLine("Source: {0}", ex.Source); sw.WriteLine("StackTrace: {0}", ex.StackTrace); sw.WriteLine("Target Site: {0}", ex.TargetSite); sw.WriteLine("\n\n"); } throw; } }