示例#1
0
        private static void Dispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
#if RELEASE
            switch (e.Exception)
            {
            case QueryNotRespondingException _:
                MessageQueue.Enqueue(AkaI18N.QueryNotResponding);
                break;

            case ApiException apiException:
                if (apiException.StatusCode == HttpStatusCode.BadRequest)
                {
                    MessageQueue.Enqueue(AkaI18N.QueryNotResponding);
                }
                break;

            case HttpRequestException _: break;

            default:
                ExceptionDumper.WriteException(e.Exception);
                break;
            }

            e.Handled = true;
#endif
        }
示例#2
0
        private static void DispatcherOnUnhandledException(Exception e)
        {
#if RELEASE
            switch (e)
            {
            case OperationCanceledException _:
                return;

            case var exception when exception is WebException || exception is HttpRequestException:
                var reason = new StringBuilder(exception.Message);
                if (exception.InnerException != null)
                {
                    reason.Append(":").Append(exception.InnerException.Message);
                }
                UI.MainWindow.MessageQueue.Enqueue(reason.ToString());
                return;

            case AuthenticateFailedException _:
                MessageDialog.Warning(UI.MainWindow.Instance.WarningDialog, Pixeval.Resources.Resources.AppApiAuthenticateTimeout);
                break;
            }
            ExceptionDumper.WriteException(e);
#elif DEBUG
            Debug.WriteLine(e.ToString());
#endif
        }
        private async void Login_OnClick(object sender, RoutedEventArgs e)
        {
            if (Email.Text.IsNullOrEmpty() || Password.Password.IsNullOrEmpty())
            {
                ErrorMessage.Text = AkaI18N.EmptyEmailOrPasswordIsNotAllowed;
                return;
            }

            Login.Disable();

            try
            {
                await Task.WhenAll(Authentication.AppApiAuthenticate(Email.Text, Password.Password),
                                   Authentication.WebApiAuthenticate(Email.Text, Password.Password));
            }
            catch (Exception exception)
            {
                SetErrorHint(exception);
                ExceptionDumper.WriteException(exception);
                Login.Enable();
                return;
            }

            var mainWindow = new MainWindow();

            mainWindow.Show();

            Close();
        }
示例#4
0
        public static async Task <Illustration> IllustrationInfo(string id)
        {
            SingleWorkResponse.Illust response;
            try
            {
                response = (await HttpClientFactory.AppApiService.GetSingle(id)).IllustInfo;
            }
            catch (ApiException e)
            {
                ExceptionDumper.WriteException(e);
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }

            var illust = new Illustration
            {
                Bookmark = (int)response.TotalBookmarks,
                Id       = response.Id.ToString(),
                IsLiked  = response.IsBookmarked,
                IsManga  = response.PageCount != 1,
                IsUgoira = response.Type == "ugoira",
                Origin   = response.ImageUrls.Original ?? response.MetaSinglePage.OriginalImageUrl,
                Large    = response.ImageUrls.Large,
                Tags     = response.Tags.Select(t => new Tag {
                    Name = t.Name, TranslatedName = t.TranslatedName
                }),
                Thumbnail   = response.ImageUrls.Medium,
                Title       = response.Title,
                UserName    = response.User.Name,
                UserId      = response.User.Id.ToString(),
                ViewCount   = (int)response.TotalView,
                Comments    = (int)response.TotalComments,
                Resolution  = $"{response.Width}x{response.Height}",
                PublishDate = response.CreateDate,
            };

            if (illust.IsManga && response.MetaPages != null)
            {
                illust.MangaMetadata = response.MetaPages.Select(p =>
                {
                    var page       = (Illustration)illust.Clone();
                    page.Thumbnail = p.ImageUrls.Medium;
                    page.Origin    = p.ImageUrls.Original;
                    page.Large     = p.ImageUrls.Large;
                    return(page);
                }).ToArray();
                illust.PageCount = illust.MangaMetadata.Length;

                foreach (var illustration in illust.MangaMetadata)
                {
                    illustration.MangaMetadata = illust.MangaMetadata;
                }
            }

            return(illust);
        }
示例#5
0
        private static void DispatcherOnUnhandledException(Exception e)
        {
#if RELEASE
            ExceptionDumper.WriteException(e);
#elif DEBUG
            throw e;
#endif
        }
示例#6
0
        private static void DispatcherOnUnhandledException(Exception e)
        {
#if RELEASE
            ExceptionDumper.WriteException(e);
#elif DEBUG
            MessageBox.Show(e.ToString());
#endif
        }
示例#7
0
        private static void DispatcherOnUnhandledException(Exception e)
        {
#if RELEASE
            ExceptionDumper.WriteException(e);
#elif DEBUG
            if (e is ApiException apiException)
            {
                MessageBox.Show(apiException.Content);
            }
#endif
        }
        private async void SignIn_OnInitialized(object sender, EventArgs e)
        {
            if (Session.ConfExists())
            {
                try
                {
                    DialogHost.OpenControl();
                    await Session.RefreshIfRequired();
                }
                catch (Exception exception)
                {
                    SetErrorHint(exception);
                    ExceptionDumper.WriteException(exception);
                    DialogHost.CurrentSession.Close();
                    return;
                }

                DialogHost.CurrentSession.Close();

                var mainWindow = new MainWindow();
                mainWindow.Show();
                Close();
            }
        }