示例#1
0
 public static async Task <bool> CheckForLogin()
 {
     try
     {
         do
         {
             Core.Api.Entity.AccessToken = SettingHelper.GetListSetting <string>(SettingNames.AccessToken, isThrowException: true).ToList()[Settings.SelectedUserIndex];
             if (string.IsNullOrEmpty(Core.Api.Entity.AccessToken))
             {
                 throw new Core.Exception.InvalidAccessTokenException();
             }
             if (string.IsNullOrEmpty((await Core.Api.User.Account.GetLimitStatus()).Error))
             {
                 break;
             }
             var list = SettingHelper.GetListSetting <string>(SettingNames.AccessToken, isThrowException: true).ToList();
             list.RemoveAt(Settings.SelectedUserIndex);
             Settings.SelectedUserIndex = 0;
             SettingHelper.SetListSetting(SettingNames.AccessToken, list);
             if (list.Count == 0)
             {
                 return(false);
             }
         } while (true);
         return(true);
     }
     catch (Exception e)// when (e is Core.Exception.InvalidAccessTokenException || e is SettingException)
     {
         return(false);
     }
 }
示例#2
0
 private bool CheckForLogin()
 {
     try
     {
         Core.Api.Entity.AccessToken = SettingHelper.GetListSetting <string>(SettingNames.AccessToken, isThrowException: true).ToList()[Settings.SelectedUserIndex];
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#3
0
        protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
        {
            var frame = Window.Current.Content as Frame ?? new Frame();

            Window.Current.Content = frame;
            if (Core.Api.Entity.AccessToken == null)
            {
                Core.Api.Entity.AccessToken = SettingHelper.GetListSetting <string>(SettingNames.AccessToken).ToList()[Settings.SelectedUserIndex];
            }
            if (StaticResource.Emotions == null)
            {
                await StaticResource.InitEmotion();
            }
            frame.Navigate(typeof(PostWeiboPage), new Common.Entities.PostWeibo());
            //ShareOperation shareOperation = args.ShareOperation;
            //if (shareOperation.Data.Contains(StandardDataFormats.Text))
            //{
            //    string text = await shareOperation.Data.GetTextAsync();
            //    frame.Navigate(typeof(PostWeiboPage), new Common.Entities.SharedPostWeibo() { Data = text, Operation = shareOperation });
            //    shareOperation.ReportDataRetrieved();
            //}
            //else if (shareOperation.Data.Contains(StandardDataFormats.Bitmap))
            //{
            //    var bitmap = await shareOperation.Data.GetBitmapAsync();
            //    using (var stream = await bitmap.OpenReadAsync())
            //    {
            //        byte[] bytes = new byte[stream.Size];
            //        var buffer = await stream.ReadAsync(bytes.AsBuffer(), (uint)stream.Size, InputStreamOptions.None);
            //        bytes = buffer.ToArray();
            //        frame.Navigate(typeof(PostWeiboPage), new Common.Entities.SharedPostWeibo() { ImageData = bytes, Operation = shareOperation });
            //    }
            //    shareOperation.ReportDataRetrieved();
            //}
            //else if (shareOperation.Data.Contains(StandardDataFormats.StorageItems))
            //{
            //    var files = await shareOperation.Data.GetStorageItemsAsync();
            //    frame.Navigate(typeof(PostWeiboPage), new Common.Entities.SharedPostWeibo() { Operation = shareOperation, ImageFiles = files });
            //}
            Window.Current.Activate();
        }
示例#4
0
        private async Task <bool> CheckForLogin()
        {
            try
            {
                do
                {
                    var account = Settings.Account[Settings.SelectedUserIndex];
                    if (string.IsNullOrEmpty(account.AccessToken))
                    {
                        throw new ArgumentNullException();
                    }
                    var accountModel = await Mastodon.Api.Accounts.VerifyCredentials(account.Domain, account.AccessToken);

                    if (accountModel != null)
                    {
                        Settings.CurrentAccountModel = accountModel;
                        break;
                    }
                    var list = SettingHelper.GetListSetting <string>(nameof(Settings.Account), isThrowException: true).ToList();
                    list.RemoveAt(Settings.SelectedUserIndex);
                    Settings.SelectedUserIndex = 0;
                    SettingHelper.SetListSetting(nameof(Settings.Account), list);
                    if (list.Count == 0)
                    {
                        return(false);
                    }
                } while (true);
                return(true);
            }
            catch (Exception e) when(e is WebException || e is HttpRequestException)
            {
                return(false);
            }
            catch (Exception e)// when (e is SettingException)
            {
                return(false);
            }
        }