コード例 #1
0
ファイル: SaveVnDataToDb.cs プロジェクト: micah686/VnManager
        /// <summary>
        /// Save Vn Characters to db
        /// </summary>
        /// <param name="characters"></param>
        /// <param name="vnid"></param>
        public static void SaveVnCharacters(ICollection <Character> characters, uint vnid)
        {
            try
            {
                if (characters == null || characters.Count < 1)
                {
                    return;
                }
                var cred = CredentialManager.GetCredentials(App.CredDb);
                if (cred == null || cred.UserName.Length < 1)
                {
                    return;
                }
                using (var db = new LiteDatabase($"{App.GetDbStringWithoutPass}'{cred.Password}'"))
                {
                    var dbCharInfo = db.GetCollection <VnCharacterInfo>(DbVnCharacter.VnCharacter.ToString());
                    ILiteCollection <VnCharacterTraits> dbCharTraits = db.GetCollection <VnCharacterTraits>(DbVnCharacter.VnCharacter_Traits.ToString());

                    if (characters.Count > 0)
                    {
                        List <VnCharacterInfo>   vnCharactersList      = new List <VnCharacterInfo>();
                        List <VnCharacterTraits> vnCharacterTraitsList = new List <VnCharacterTraits>();
                        foreach (Character vnCharacter in characters)
                        {
                            var prevVnCharacter = dbCharInfo.Query().Where(x => x.CharacterId == vnCharacter.Id);
                            var character       = prevVnCharacter.FirstOrDefault() ?? new VnCharacterInfo();

                            character.VnId        = vnid;
                            character.CharacterId = vnCharacter.Id;
                            character.Name        = vnCharacter.Name;
                            character.Original    = vnCharacter.OriginalName;
                            character.Gender      = vnCharacter.Gender.ToString();
                            character.BloodType   = vnCharacter.BloodType.ToString();
                            character.Age         = vnCharacter.Age.ToString();
                            character.Birthday    = SimpleDateConverter.ConvertSimpleDate(vnCharacter.Birthday);
                            character.Aliases     = CsvConverter.ConvertToCsv(vnCharacter.Aliases);
                            character.Description = vnCharacter.Description;
                            character.ImageLink   = !string.IsNullOrEmpty(vnCharacter.Image) ? vnCharacter.Image : string.Empty;
                            character.ImageRating = vnCharacter.ImageRating;
                            character.Bust        = Convert.ToInt32(vnCharacter.Bust, CultureInfo.InvariantCulture);
                            character.Waist       = Convert.ToInt32(vnCharacter.Waist, CultureInfo.InvariantCulture);
                            character.Hip         = Convert.ToInt32(vnCharacter.Hip, CultureInfo.InvariantCulture);
                            character.Height      = Convert.ToInt32(vnCharacter.Height, CultureInfo.InvariantCulture);
                            character.Weight      = Convert.ToInt32(vnCharacter.Weight, CultureInfo.InvariantCulture);
                            vnCharactersList.Add(character);

                            vnCharacterTraitsList.AddRange(FormatVnCharacterTraits(vnCharacter, dbCharTraits));
                        }

                        dbCharInfo.Upsert(vnCharactersList);
                        dbCharTraits.Upsert(vnCharacterTraitsList);
                    }
                }
            }
            catch (Exception e)
            {
                App.Logger.Error(e, "Failed to save VnCharacters");
                SentryHelper.SendException(e, null, SentryLevel.Error);
            }
        }
コード例 #2
0
ファイル: FrmSnapshotTable.cs プロジェクト: zhiqiang-hu/scada
        /// <summary>
        /// Exports data to CSV.
        /// </summary>
        private void ExportToCsv()
        {
            try
            {
                sfdCsv.FileName = Path.GetFileNameWithoutExtension(FileName) + ".csv";

                if (sfdCsv.ShowDialog() == DialogResult.OK)
                {
                    CsvConverter csvConverter = new CsvConverter(sfdCsv.FileName);
                    csvConverter.ConvertToCsv(srezTable);
                }
            }
            catch (Exception ex)
            {
                errLog.WriteException(ex, ServerShellPhrases.ExportToCsvError);
                ScadaUiUtils.ShowError(ServerShellPhrases.ExportToCsvError + ": " + ex.Message);
            }
        }
コード例 #3
0
ファイル: SaveVnDataToDb.cs プロジェクト: micah686/VnManager
        /// <summary>
        /// Save the Main VnInfo to the database
        /// </summary>
        /// <param name="visualNovel"></param>
        public static void SaveVnInfo(VisualNovel visualNovel)
        {
            if (visualNovel == null)
            {
                return;
            }
            try
            {
                var cred = CredentialManager.GetCredentials(App.CredDb);
                if (cred == null || cred.UserName.Length < 1)
                {
                    return;
                }
                using (var db = new LiteDatabase($"{App.GetDbStringWithoutPass}'{cred.Password}'"))
                {
                    var dbVnInfo      = db.GetCollection <VnInfo>(DbVnInfo.VnInfo.ToString());
                    var dbVnInfoLinks = db.GetCollection <VnInfoLinks>(DbVnInfo.VnInfo_Links.ToString());
                    ILiteCollection <VnInfoScreens>   dbVnInfoScreens   = db.GetCollection <VnInfoScreens>(DbVnInfo.VnInfo_Screens.ToString());
                    ILiteCollection <VnInfoRelations> dbVnInfoRelations = db.GetCollection <VnInfoRelations>(DbVnInfo.VnInfo_Relations.ToString());
                    ILiteCollection <VnInfoTags>      dbVnInfoTags      = db.GetCollection <VnInfoTags>(DbVnInfo.VnInfo_Tags.ToString());

                    var prevVnInfo      = dbVnInfo.Query().Where(x => x.VnId == visualNovel.Id).FirstOrDefault();
                    var prevVnInfoLinks = dbVnInfoLinks.Query().Where(x => x.VnId == visualNovel.Id).FirstOrDefault();

                    List <VnInfoTags>      vnTags       = new List <VnInfoTags>();
                    List <VnInfoRelations> vnRelations  = new List <VnInfoRelations>();
                    List <VnInfoScreens>   vnScreenshot = new List <VnInfoScreens>();

                    var vn = prevVnInfo ?? new VnInfo();

                    vn.VnId              = visualNovel.Id;
                    vn.Title             = visualNovel.Name;
                    vn.Original          = visualNovel.OriginalName;
                    vn.Released          = visualNovel.Released?.ToString();
                    vn.Languages         = CsvConverter.ConvertToCsv(visualNovel.Languages);
                    vn.OriginalLanguages = CsvConverter.ConvertToCsv(visualNovel.OriginalLanguages);
                    vn.Platforms         = CsvConverter.ConvertToCsv(visualNovel.Platforms);
                    vn.Aliases           = CsvConverter.ConvertToCsv(visualNovel.Aliases);
                    vn.Length            = visualNovel.Length?.ToString();
                    vn.Description       = visualNovel.Description;
                    vn.ImageLink         = !string.IsNullOrEmpty(visualNovel.Image) ? visualNovel.Image : string.Empty;
                    vn.ImageRating       = visualNovel.ImageRating;
                    vn.Popularity        = visualNovel.Popularity;
                    vn.Rating            = visualNovel.Rating;


                    //links
                    VnInfoLinks vnLinks = prevVnInfoLinks ?? new VnInfoLinks();
                    vnLinks.VnId     = visualNovel.Id;
                    vnLinks.Wikidata = visualNovel.VisualNovelLinks.Wikidata;

                    //screenshot
                    vnScreenshot.AddRange(FormatVnInfoScreens(visualNovel, dbVnInfoScreens));

                    //relations
                    vnRelations.AddRange(FormatVnInfoRelations(visualNovel, dbVnInfoRelations));


                    //tags
                    vnTags.AddRange(FormatVnInfoTags(visualNovel, dbVnInfoTags));

                    dbVnInfo.Upsert(vn);
                    dbVnInfoLinks.Upsert(vnLinks);
                    dbVnInfoScreens.Upsert(vnScreenshot);
                    dbVnInfoRelations.Upsert(vnRelations);
                    dbVnInfoTags.Upsert(vnTags);
                }
            }
            catch (IOException e)
            {
                App.Logger.Error(e, "an I/O exception occurred");
                SentryHelper.SendException(e, null, SentryLevel.Error);
            }
            catch (Exception e)
            {
                App.Logger.Error(e, "Failed to save VnInfo");
                SentryHelper.SendException(e, null, SentryLevel.Error);
            }
        }