Exemplo n.º 1
0
        public async Task <bool> IsValid()
        {
            if (!(DataContext is ImgurPreset preset))
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(preset.Title))
            {
                StatusBand.Warning(LocalizationHelper.Get("S.Options.Upload.Preset.Warning.Title"));
                return(false);
            }

            if (UserSettings.All.UploadPresets.OfType <UploadPreset>().Any(a => a.Title != _originalTitle && a.Title == preset.Title.Trim()))
            {
                StatusBand.Warning(LocalizationHelper.Get("S.Options.Upload.Preset.Warning.Repeated"));
                return(false);
            }

            if (!preset.IsAnonymous && !await Imgur.IsAuthorized(preset))
            {
                StatusBand.Warning(LocalizationHelper.Get("S.Options.Upload.Preset.Warning.Authenticate"));
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
    public static async Task <ValidatedEventArgs> IsValid(ImgurPreset preset)
    {
        if (!preset.IsAnonymous && !await Imgur.IsAuthorized(preset))
        {
            return(new ValidatedEventArgs("S.SaveAs.Warning.Upload.NotAuthorized", StatusReasons.UploadServiceUnauthorized, () => App.MainViewModel.OpenOptions.Execute(Options.UploadIndex)));
        }

        return(await preset.IsValid());
    }
Exemplo n.º 3
0
        private async void UpdateAlbumList(bool offline = false)
        {
            try
            {
                ThisPanel.IsEnabled = false;

                if (!(DataContext is ImgurPreset preset))
                {
                    return;
                }

                if (!offline && !await Imgur.IsAuthorized(preset))
                {
                    return;
                }

                var list = offline && preset.Albums != null?preset.Albums.Cast <ImgurAlbum>().ToList() : offline ? null : await Imgur.GetAlbums(preset);

                if (list == null)
                {
                    list = new List <ImgurAlbum>();

                    if (!offline)
                    {
                        StatusBand.Error(LocalizationHelper.Get("S.Options.Upload.Preset.Warning.AlbumLoad"));
                    }
                }

                if (!offline || list.All(a => a.Id != "♥♦♣♠"))
                {
                    list.Insert(0, new ImgurAlbum {
                        Id = "♥♦♣♠", Title = LocalizationHelper.Get("S.Options.Upload.Preset.Imgur.AskMe")
                    });
                }

                AlbumComboBox.ItemsSource = list;

                if (AlbumComboBox.SelectedIndex == -1)
                {
                    AlbumComboBox.SelectedIndex = 0;
                }
            }
            finally
            {
                ThisPanel.IsEnabled = true;
            }
        }