private async Task <FlowDocument> LoadTraitDescription(string charid)
        {
            try
            {
                string traitDescription = "";
                int    traitindex       = SelectedTraitIndex;
                if (traitindex < 0)
                {
                    //return "trait index was -1";
                }



                List <int> TraitListArray = new List <int>();


                using (SQLiteConnection con = new SQLiteConnection(@"Data Source=|DataDirectory|\Database.db"))
                {
                    con.Open();



                    SQLiteCommand traitdesccmd = new SQLiteCommand("SELECT * FROM CharacterTraits WHERE VnId=@VnId AND CharacterId=@CharacterId AND SpoilerLevel<=@SpoilerLevel", con);
                    traitdesccmd.Parameters.AddWithValue("@VnId", StaticClass.Vnid);
                    traitdesccmd.Parameters.AddWithValue("@CharacterId", charid);
                    traitdesccmd.Parameters.AddWithValue("@SpoilerLevel", StaticClass.CharacterSpoilerLevel);
                    SQLiteDataReader traitdescreader = traitdesccmd.ExecuteReader();
                    while (traitdescreader.Read())
                    {
                        TraitListArray.Add((int)traitdescreader["TraitId"]);
                    }
                    con.Close();
                }


                foreach (var tmp2 in StaticClass.PlainTraits)
                {
                    if (!TraitListArray.Any())
                    {
                        //return "";
                    }
                    else if (TraitListArray[traitindex] == tmp2.id)
                    {
                        traitDescription = tmp2.description;
                    }
                }


                ConvertRichTextDocument convRTD = new ConvertRichTextDocument();
                return(convRTD.ConvertToFlowDocument(traitDescription));



                //return traitDescription;
            }
            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: LoadTraitDescription");
                    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;
            }
        }
Beispiel #2
0
        private async Task <FlowDocument> LoadTagDescription()
        {
            try
            {
                string tagdescription = "";
                int    tagidx         = SelectedTagIndex;
                if (tagidx < 0)
                {
                    //return "tag index was -1";
                    return(null);
                }

                int        vnSpoiler    = StaticClass.VnSpoilerLevel;
                List <int> TagListArray = new List <int>();
                using (SQLiteConnection con = new SQLiteConnection(@"Data Source=|DataDirectory|\Database.db"))
                {
                    con.Open();
                    SQLiteCommand    tagdesccmd    = new SQLiteCommand("SELECT * FROM VnTags WHERE VnId=" + StaticClass.Vnid + " AND Spoiler<=" + vnSpoiler, con);
                    SQLiteDataReader tagdescreader = tagdesccmd.ExecuteReader();
                    while (tagdescreader.Read())
                    {
                        TagListArray.Add((int)tagdescreader["TagId"]);
                    }
                    con.Close();
                }


                foreach (WrittenTagsRootObject tmp2 in StaticClass.PlainTags)
                {
                    if (!TagListArray.Any())
                    {
                        //return "";
                    }
                    else if (TagListArray[tagidx] == tmp2.id)
                    {
                        tagdescription = tmp2.description;
                    }
                }
                //return tagdescription;
                ConvertRichTextDocument convRTD = new ConvertRichTextDocument();
                return(convRTD.ConvertToFlowDocument(tagdescription));
                //return "not supossed to happen";
            }
            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: LoadTagDescription");
                    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 NextCharacterDataExecute()
        {
            try
            {
                if (CurrentCharacterCount == 0)
                {
                    PreviousButtonEnabled = false;
                }
                else if (CurrentCharacterCount > 0)
                {
                    PreviousButtonEnabled = true;
                }
                if (CurrentCharacterCount == CharacterCountMax)
                {
                    NextButtonEnabled = false;
                    return;
                }

                CurrentCharacterCount++;

                var charData  = new List <List <string[]> >();
                var TraitList = new List <string[]>();

                await Task.Run(() =>
                {
                    charData = LoadMainCharacterData().Result;
                });


                if (Convert.ToInt32(charData[CurrentCharacterCount][0][14]) > StaticClass.CharacterSpoilerLevel)
                {
                    if (CurrentCharacterCount == CharacterCountMax)
                    {
                        NextButtonEnabled = false;
                    }
                    if (CurrentCharacterCount == 0)
                    {
                        PreviousButtonEnabled = false;
                    }

                    if (CurrentCharacterCount < CharacterCountMax)
                    {
                        NextButtonEnabled = true;
                        NextCharacterDataCommand.Execute(null);
                    }

                    else if (CurrentCharacterCount > 0)
                    {
                        PreviousButtonEnabled = true;
                        PreviousCharacterDataCommand.Execute(null);
                    }

                    //loads the next non spoiler image
                }
                else
                {
                    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];



                    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;
                    }
                    if (CurrentCharacterCount > 0)
                    {
                        PreviousButtonEnabled = true;
                    }
                    if (CurrentCharacterCount == CharacterCountMax)
                    {
                        NextButtonEnabled = false;
                    }
                    if (CurrentCharacterCount < CharacterCountMax)
                    {
                        NextButtonEnabled = true;
                    }
                }
            }
            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: NextCharacterDataExecute");
                    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;
            }
        }
Beispiel #4
0
        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;
            }
        }