Beispiel #1
0
        /// <summary>
        /// Handles Vndb API errors, writes the error message to a file, then resets the statusbar
        /// </summary>
        /// <param name="error">Vndb Error</param>
        public static void HandleErrors(IVndbError error)
        {
            if (error == null)
            {
                return;
            }
            switch (error)
            {
            case MissingError missing:
                Debug.WriteLine($"A Missing Error occurred, the field {missing.Field} was missing.");
                App.Logger.Warning($"A Missing Error occurred, the field {missing.Field} was missing.");
                break;

            case BadArgumentError badArg:
                Debug.WriteLine($"A BadArgument Error occurred, the field {badArg.Field} is invalid.");
                App.Logger.Warning($"A BadArgument Error occurred, the field {badArg.Field} is invalid.");
                break;

            case ThrottledError throttled:
                Debug.WriteLine($"A Throttled Error occurred, use the ThrottledWaitAsync() method to wait for the {throttled.MinimumWait.Second} seconds needed.");
                App.Logger.Warning($"A Throttled Error occurred, use the ThrottledWaitAsync() method to wait for the {throttled.MinimumWait.Second} seconds needed.");
                break;

            case GetInfoError getInfo:
                Debug.WriteLine($"A GetInfo Error occurred, the flag {getInfo.Flag} is not valid on the issued command.");
                App.Logger.Warning($"A GetInfo Error occurred, the flag {getInfo.Flag} is not valid on the issued command.");
                break;

            case InvalidFilterError invalidFilter:
                Debug.WriteLine($"A InvalidFilter Error occurred, the filter combination of {invalidFilter.Field}, {invalidFilter.Operator}, {invalidFilter.Value} is not a valid combination.");
                App.Logger.Warning($"A InvalidFilter Error occurred, the filter combination of {invalidFilter.Field}, {invalidFilter.Operator}, {invalidFilter.Value} is not a valid combination.");
                break;

            case BadAuthenticationError badAuthentication:
                Debug.WriteLine($"A BadAuthenticationError occurred. This is caused by an incorrect username or password.\nMessage: {badAuthentication.Message}");
                App.Logger.Warning($"A BadAuthenticationError occurred. This is caused by an incorrect username or password.\nMessage: {badAuthentication.Message}");
                break;

            default:
                Debug.WriteLine($"A {error.Type} Error occurred.\nMessage: {error.Message}");
                App.Logger.Warning($"A {error.Type} Error occurred.\nMessage: {error.Message}");
                break;
            }
            StatusBarViewModel.ResetValues();
        }
Beispiel #2
0
        /// <summary>
        /// Download main Vndb Data
        /// </summary>
        /// <param name="gameId"></param>
        /// <param name="isRepairing"></param>
        /// <returns></returns>
        public async Task GetDataAsync(int gameId, bool isRepairing)
        {
            uint vnId = (uint)gameId;

            try
            {
                const int max = 100;
                const int countWithTagTrait    = 9;
                const int countWithoutTagTrait = 7;
                double    increment;
                if (isRepairing || !App.DidDownloadTagTraitDump)
                {
                    increment = (double)max / countWithTagTrait;
                }
                else
                {
                    increment = (double)max / countWithoutTagTrait;
                }

                using (var client = new VndbSharp.Vndb(true))
                {
                    RootViewModel.StatusBarPage.IsWorking    = true;
                    RootViewModel.StatusBarPage.StatusString = App.ResMan.GetString("Working");
                    double current = increment;

                    RootViewModel.StatusBarPage.IsProgressBarVisible  = true;
                    RootViewModel.StatusBarPage.ProgressBarValue      = 0;
                    RootViewModel.StatusBarPage.IsProgressBarInfinite = false;

                    RequestOptions ro = new RequestOptions {
                        Count = 25
                    };
                    stopwatch.Start();
                    RootViewModel.StatusBarPage.InfoText = App.ResMan.GetString("DownVnInfo");
                    var visualNovel = await GetVisualNovelAsync(client, vnId);

                    current += increment;
                    RootViewModel.StatusBarPage.ProgressBarValue = current;



                    RootViewModel.StatusBarPage.InfoText = App.ResMan.GetString("DownCharacterInfo");
                    var characters = await GetCharactersAsync(client, vnId, ro);

                    current += increment;
                    RootViewModel.StatusBarPage.ProgressBarValue = current;

                    stopwatch.Stop();
                    stopwatch.Reset();


                    if (_didErrorOccur)
                    {
                        App.Logger.Error("Failed to get all of the Vndb Info from the API, one of the items was null");
                        //stop the progressbar here, and force it to show an error icon
                        RootViewModel.StatusBarPage.IsWorking = false;
                        RootViewModel.StatusBarPage.InfoText  = "";
                    }
                    else
                    {
                        //run code to add info to database

                        await SaveVnDataToDb.SortVnInfoAsync(visualNovel, characters, increment, current, isRepairing);
                    }
                }
            }
            catch (Exception ex)
            {
                App.Logger.Error(ex, "An error occurred when trying to get the vndb data from the API");
                SentryHelper.SendException(ex, null, SentryLevel.Warning);
                StatusBarViewModel.ResetValues();
                throw;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Sort all of the VnInfo and save it to the database
        /// </summary>
        /// <param name="vn"></param>
        /// <param name="character"></param>
        /// <param name="increment"></param>
        /// <param name="currentProgress"></param>
        /// <param name="isRepairing"></param>
        /// <returns></returns>
        public static async Task SortVnInfoAsync(VisualNovel vn, ICollection <Character> character, double increment, double currentProgress, bool isRepairing)
        {
            if (vn == null)
            {
                StatusBarViewModel.ResetValues();
                return;
            }

            try
            {
                var currentValue = currentProgress;

                SaveVnInfo(vn);
                currentValue += increment;
                RootViewModel.StatusBarPage.ProgressBarValue = currentValue;

                SaveVnCharacters(character, vn.Id);
                currentValue += increment;
                RootViewModel.StatusBarPage.ProgressBarValue = currentValue;

                await DownloadVndbContent.DownloadCoverImageAsync(vn.Id);

                currentValue += increment;
                RootViewModel.StatusBarPage.ProgressBarValue = currentValue;

                await DownloadVndbContent.DownloadCharacterImagesAsync(vn.Id);

                currentValue += increment;
                RootViewModel.StatusBarPage.ProgressBarValue = currentValue;
                await DownloadVndbContent.DownloadScreenshotsAsync(vn.Id);

                currentValue += increment;

                RootViewModel.StatusBarPage.ProgressBarValue  = currentValue;
                RootViewModel.StatusBarPage.IsFileDownloading = false;

                if (isRepairing || !App.DidDownloadTagTraitDump)
                {
                    RootViewModel.StatusBarPage.IsDatabaseProcessing = true;
                    await DownloadVndbContent.GetAndSaveTagDumpAsync();

                    currentValue += increment;
                    RootViewModel.StatusBarPage.ProgressBarValue = currentValue;

                    await DownloadVndbContent.GetAndSaveTraitDumpAsync();

                    currentValue += increment;
                    RootViewModel.StatusBarPage.ProgressBarValue = currentValue;
                }
            }
            catch (Exception e)
            {
                App.Logger.Error(e, "Failed to Sort VnInfo");
                SentryHelper.SendException(e, null, SentryLevel.Warning);
                StatusBarViewModel.ResetValues();
            }
            finally
            {
                StatusBarViewModel.ResetValues();
            }
        }