示例#1
0
        public async static Task ImgurSetup()
        {
            ApiSettings settings = GetApiLogin();

            Client = new ImgurClient(settings.ClientId, settings.ClientSecret);
            var          endpoint = new OAuth2Endpoint(Client);
            IOAuth2Token token    = null;

            while (token == null)
            {
                try
                {
                    token = await endpoint.GetTokenByRefreshTokenAsync(settings.RefreshToken);
                } catch (Exception ex)
                {
                    token = null;
                    Console.WriteLine(ex.Message);
                    await Task.Delay(5000);
                }
                break;
            }

            Client.SetOAuth2Token(token);

            Console.WriteLine("Imgur Ready.");
        }
示例#2
0
        /// <summary>
        ///     Initializes a new instance of the ApiClientBase class.
        /// </summary>
        /// <param name="clientId">The Imgur app's ClientId. </param>
        /// <param name="clientSecret">The Imgur app's ClientSecret.</param>
        /// <param name="oAuth2Token">OAuth2 credentials.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        protected ApiClientBase(string clientId, string clientSecret, IOAuth2Token oAuth2Token)
            : this(clientId, clientSecret)
        {
            if (oAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(oAuth2Token));
            }

            if (oAuth2Token.AccessToken == null)
            {
                throw new ArgumentException(nameof(oAuth2Token.AccessToken));
            }

            if (oAuth2Token.RefreshToken == null)
            {
                throw new ArgumentException(nameof(oAuth2Token.RefreshToken));
            }

            if (oAuth2Token.TokenType == null)
            {
                throw new ArgumentException(nameof(oAuth2Token.TokenType));
            }

            if (oAuth2Token.AccountId == null)
            {
                throw new ArgumentException(nameof(oAuth2Token.AccountId));
            }

            if (oAuth2Token.AccountUsername == null)
            {
                throw new ArgumentException(nameof(oAuth2Token.AccountUsername));
            }

            OAuth2Token = oAuth2Token;
        }
示例#3
0
 /// <summary>
 ///     Initializes a new instance of the ApiClientBase class.
 /// </summary>
 /// <param name="clientId">The Imgur app's ClientId. </param>
 /// <param name="oAuth2Token">OAuth2 credentials.</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///     Thrown when a null reference is passed to a method that does not accept it as a
 ///     valid argument.
 /// </exception>
 protected ApiClientBase(string clientId, IOAuth2Token oAuth2Token)
     : this(clientId)
 {
     if (oAuth2Token == null)
     {
         throw new ArgumentNullException(nameof(oAuth2Token));
     }
     if (oAuth2Token.AccessToken == null)
     {
         throw new ArgumentNullException("AccessToken");
     }
     if (oAuth2Token.RefreshToken == null)
     {
         throw new ArgumentNullException("RefreshToken");
     }
     if (oAuth2Token.TokenType == null)
     {
         throw new ArgumentNullException("TokenType");
     }
     if (oAuth2Token.AccountId == null)
     {
         throw new ArgumentNullException("AccountId");
     }
     if (oAuth2Token.AccountUsername == null)
     {
         throw new ArgumentNullException("AccountUsername");
     }
     this.OAuth2Token = oAuth2Token;
 }
示例#4
0
        private void GetAndSetOAuth2Token()
        {
            var apiClient      = GetApiClientWithKeyAndSecret();
            var oAuth2Endpoint = new OAuth2Endpoint(apiClient, new HttpClient());

            _oAuth2Token = Task.Run(() => oAuth2Endpoint.GetTokenAsync(_refreshToken)).Result;
        }
示例#5
0
        public static async Task <IOAuth2Token> GetToken()
        {
            OAuth2Endpoint auth  = new OAuth2Endpoint(new ImgurClient(Properties.Settings.Default.ClientId, Properties.Settings.Default.ClientSecret));
            IOAuth2Token   token = null;

            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.Token))
            {
                token = JsonConvert.DeserializeObject <OAuth2Token>(Properties.Settings.Default.Token);
                if (token != null)
                {
                    if (token.ExpiresIn > 0)
                    {
                        return(token);
                    }
                    token = await auth.GetTokenByRefreshTokenAsync(token.RefreshToken);

                    Properties.Settings.Default.Token = JsonConvert.SerializeObject(token);
                    Properties.Settings.Default.Save();
                }
            }
            Process.Start(auth.GetAuthorizationUrl(Imgur.API.Enums.OAuth2ResponseType.Pin));
            string pin = await DialogCoordinator.Instance.ShowInputAsync(Context, "Enter Imgur Pin", "");

            token = await auth.GetTokenByPinAsync(pin);

            Properties.Settings.Default.Token = JsonConvert.SerializeObject(token);
            Properties.Settings.Default.Save();
            return(token);
        }
示例#6
0
 /// <summary>Sets the oAuth2Token to be used.</summary>
 /// <param name="oAuth2Token">See <see cref="T:Imgur.API.Models.IOAuth2Token" />.</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///     Thrown when a null reference is passed to a method that does not accept it as a
 ///     valid argument.
 /// </exception>
 public virtual void SetOAuth2Token(IOAuth2Token oAuth2Token)
 {
     if (oAuth2Token == null)
     {
         this.OAuth2Token = (IOAuth2Token)null;
     }
     else
     {
         if (oAuth2Token.AccessToken == null)
         {
             throw new ArgumentNullException("AccessToken");
         }
         if (oAuth2Token.RefreshToken == null)
         {
             throw new ArgumentNullException("RefreshToken");
         }
         if (oAuth2Token.TokenType == null)
         {
             throw new ArgumentNullException("TokenType");
         }
         if (oAuth2Token.AccountId == null)
         {
             throw new ArgumentNullException("AccountId");
         }
         if (oAuth2Token.AccountUsername == null)
         {
             throw new ArgumentNullException("AccountUsername");
         }
         this.OAuth2Token = oAuth2Token;
     }
 }
示例#7
0
        /// <summary>
        ///     Initializes a new instance of the ApiClientBase class.
        /// </summary>
        /// <param name="clientId">The Imgur app's ClientId. </param>
        /// <param name="clientSecret">The Imgur app's ClientSecret.</param>
        /// <param name="oAuth2Token">OAuth2 credentials.</param>
        /// <exception cref="ArgumentNullException"></exception>
        protected ApiClientBase(string clientId, string clientSecret, IOAuth2Token oAuth2Token)
        {
            if (string.IsNullOrWhiteSpace(clientId))
                throw new ArgumentNullException(nameof(clientId));

            if (string.IsNullOrWhiteSpace(clientSecret))
                throw new ArgumentNullException(nameof(clientSecret));

            if (oAuth2Token == null)
                throw new ArgumentNullException(nameof(oAuth2Token));

            if (oAuth2Token.AccessToken == null)
                throw new ArgumentNullException(nameof(oAuth2Token.AccessToken));

            if (oAuth2Token.AccountId == null)
                throw new ArgumentNullException(nameof(oAuth2Token.AccountId));

            if (oAuth2Token.RefreshToken == null)
                throw new ArgumentNullException(nameof(oAuth2Token.RefreshToken));

            if (oAuth2Token.TokenType == null)
                throw new ArgumentNullException(nameof(oAuth2Token.TokenType));

            ClientId = clientId;
            ClientSecret = clientSecret;
            OAuth2Token = oAuth2Token;
        }
示例#8
0
        /// <summary>
        ///     Sets the oAuth2Token to be used.
        /// </summary>
        /// <param name="token">See <see cref="IOAuth2Token" />.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        public virtual void SetOAuth2Token(IOAuth2Token token)
        {
            if (token == null)
            {
                OAuth2Token = null;
                return;
            }

            if (token.AccessToken == null)
            {
                throw new ArgumentException(nameof(token.AccessToken));
            }

            if (token.RefreshToken == null)
            {
                throw new ArgumentException(nameof(token.RefreshToken));
            }

            if (token.TokenType == null)
            {
                throw new ArgumentException(nameof(token.TokenType));
            }

            if (token.AccountId == null)
            {
                throw new ArgumentException(nameof(token.AccountId));
            }

            if (token.AccountUsername == null)
            {
                throw new ArgumentException(nameof(token.AccountUsername));
            }

            OAuth2Token = token;
        }
示例#9
0
        private static async Task InitiateClient(bool getPin = true)
        {
            if (disable)
            {
                return;
            }
            var data = File.OpenText(Program.DataPath("imgflip pins", "txt")).ReadToEnd().Split('|');

            client = new ImgurClient($"{data[0]}", $"{data[1]}");
            end    = new OAuth2Endpoint(client);
            string g = end.GetAuthorizationUrl(Imgur.API.Enums.OAuth2ResponseType.Token);

            //System.Net.WebClient wc = new System.Net.WebClient();
            //byte[] raw = wc.DownloadData(g);

            //string webData = System.Text.Encoding.UTF8.GetString(raw);
            //Console.WriteLine(g);
            //ExtensionMethods.WriteToLog(ExtensionMethods.LogType.CustomMessage, null, g + "\n\n\n" + webData);
            if (getPin)
            {
                token = await end.GetTokenByPinAsync($"{data[2]}");

                client.SetOAuth2Token(token);
            }
            endpoint = new ImageEndpoint(client);
            disable  = true;
        }
示例#10
0
        /// <summary>
        ///     Initializes a new instance of the MashapeClient class.
        /// </summary>
        /// <param name="clientId">The Imgur app's ClientId. </param>
        /// <param name="clientSecret">The Imgur app's ClientSecret.</param>
        /// <param name="mashapeKey">The Mashape Key. </param>
        /// <param name="oAuth2Token">An OAuth2 Token used for actions against a user's account.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        public MashapeClient(string clientId, string clientSecret, string mashapeKey, IOAuth2Token oAuth2Token)
            : base(clientId, clientSecret, oAuth2Token)
        {
            if (string.IsNullOrWhiteSpace(mashapeKey))
                throw new ArgumentNullException(nameof(mashapeKey));

            MashapeKey = mashapeKey;
        }
示例#11
0
        public static async Task <ImgurClient> GetClient()
        {
            IOAuth2Token token = await GetToken();

            ImgurClient client = new ImgurClient(Properties.Settings.Default.ClientId, Properties.Settings.Default.ClientSecret, token);

            return(client);
        }
示例#12
0
 /// <summary>
 ///     Initializes a new instance of the MashapeClient class.
 /// </summary>
 /// <param name="clientId">The Imgur app's ClientId. </param>
 /// <param name="mashapeKey">The Mashape Key. </param>
 /// <param name="oAuth2Token">An OAuth2 Token used for actions against a user's account.</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///     Thrown when a null reference is passed to a method that does not accept it as a
 ///     valid argument.
 /// </exception>
 public MashapeClient(string clientId, string mashapeKey, IOAuth2Token oAuth2Token)
     : base(clientId, oAuth2Token)
 {
     if (string.IsNullOrWhiteSpace(mashapeKey))
     {
         throw new ArgumentNullException(nameof(mashapeKey));
     }
     this.MashapeKey = mashapeKey;
 }
示例#13
0
        /// <summary>
        /// Test if the access token is expired
        /// </summary>
        /// <param name="oAuth2Token">IOAuth2Token</param>
        /// <returns>True if the token is expired</returns>
        public static bool IsAccessTokenExpired(this IOAuth2Token oAuth2Token)
        {
            if (string.IsNullOrEmpty(oAuth2Token.OAuth2AccessToken) || oAuth2Token.OAuth2AccessTokenExpires == default)
            {
                return(false);
            }

            return(DateTimeOffset.Now.AddSeconds(HttpExtensionsGlobals.OAuth2ExpireOffset) > oAuth2Token.OAuth2AccessTokenExpires);
        }
示例#14
0
        private IOAuth2Token GetOAuth2Token()
        {
            if (_token != null)
                return _token;

            var authentication = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new OAuth2Endpoint(authentication);
            _token = endpoint.GetTokenByRefreshTokenAsync(RefreshToken).Result;
            return _token;
        }
示例#15
0
        /**
         * Get the token that give access to the account.
         *
         * @param code code to obtain user information.
         */
        public static async Task <bool> GetTokenFromCode(string code)
        {
            var imgurApi = new ImgurApi();

            if (code != null)
            {
                token = await imgurApi.oAuth2Endpoint.GetTokenByCodeAsync(code);
            }
            return(true);
        }
示例#16
0
        public async Task <string> LoggedInUser(string refreshToken)
        {
            string username = null;

            try {
                IOAuth2Token token = await _endpoint.GetTokenByRefreshTokenAsync(refreshToken);

                username = token.AccountUsername;
            } catch { }

            return(username);
        }
 private async void ConnectUser_SavedToken(object sender, IOAuth2Token e)
 {
     userToken                = e;
     ImageGrid.Visibility     = Visibility.Visible;
     commandBar.Visibility    = Visibility.Visible;
     research.Visibility      = Visibility.Visible;
     textReasearch.Visibility = Visibility.Visible;
     textFilter.Visibility    = Visibility.Visible;
     filter.Visibility        = Visibility.Visible;
     ConnectUser.Visibility   = Visibility.Collapsed;
     await GetGallery();
 }
        public async Task SaveNewImgurUserAuthorizationToken(IOAuth2Token AuthorizationToken)
        {
            XDocument WholeDocument = await XMLDataFileHandler.LoadFile(FileAccess.ReadWrite, FileShare.Read);

            XElement OAuthElement = WholeDocument.Root.Elements(xmlns + "Configuration").Elements(xmlns + "Imgur").Elements(xmlns + "OAuthToken").First();

            OAuthElement.SetAttributeValue("AccessToken", AuthorizationToken.AccessToken);
            OAuthElement.SetAttributeValue("RefreshToken", AuthorizationToken.RefreshToken);
            OAuthElement.SetAttributeValue("TokenType", AuthorizationToken.TokenType);
            OAuthElement.SetAttributeValue("ExpiresAt", AuthorizationToken.ExpiresAt);
            await XMLDataFileHandler.Save(WholeDocument, SavingOptions);
        }
示例#19
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    _oAuth2Token = null;
                }

                _disposed = true;
            }
        }
示例#20
0
        //Login to Imgur Account
        private async void Login()
        {
            try {
                OAuth2Endpoint endpoint = new OAuth2Endpoint(_client);

                string       refreshToken = FileIO.ReadRefreshToken();
                IOAuth2Token token        = await endpoint.GetTokenByRefreshTokenAsync(refreshToken);

                _client.SetOAuth2Token(token);
            } catch {
                // ignored
            }
        }
示例#21
0
        private IOAuth2Token GetOAuth2Token()
        {
            if (_token != null)
            {
                return(_token);
            }

            var authentication = new ImgurClient(ClientId, ClientSecret);
            var endpoint       = new OAuth2Endpoint(authentication);

            _token = endpoint.GetTokenByRefreshTokenAsync(RefreshToken).Result;
            return(_token);
        }
示例#22
0
        public async Task <string> LoggedInUser(string refreshToken)
        {
            string username = null;

            try {
                IOAuth2Token token = await _endpoint.GetTokenByRefreshTokenAsync(refreshToken);

                username = token.AccountUsername;
            }
            catch {}

            UserUrl = $"http://{username}.imgur.com/all/";

            return(username);
        }
示例#23
0
        private IOAuth2Token GetToken()
        {
            if (_token != null)
            {
                return(_token);
            }

            var endpoint = new MockEndpoint(new ImgurClient("a", "b"));
            var response = new HttpResponseMessage
            {
                Content = new StringContent(MockOAuth2EndpointResponses.GetTokenByCode)
            };

            _token = endpoint.ProcessEndpointResponse <OAuth2Token>(response);
            return(_token);
        }
示例#24
0
        public bool ValidateToken(string code)
        {
            var endpoint = new OAuth2Endpoint(Imgur);
            var token    = endpoint.GetTokenByPinAsync(code);

            token.Wait();
            accessToken = token.Result;
            Managers.Instance.user.UserName  = accessToken.AccountUsername;
            Managers.Instance.user.Token     = accessToken.AccessToken;
            Managers.Instance.user.Connected = true;
            MessageBox.Show("Successfully authenticated as " + accessToken.AccountUsername);
            var token_ = new OAuth2Token(accessToken.AccessToken, accessToken.RefreshToken, accessToken.TokenType,
                                         accessToken.AccountId, accessToken.AccountUsername, accessToken.ExpiresIn);

            Imgur = new ImgurClient(id, secretId, token_);
            return(true);
        }
示例#25
0
        //Login to Imgur Account
        public async Task Login()
        {
            try {
                string refreshToken = ConfigHelper.ReadRefreshToken();
                if (string.IsNullOrWhiteSpace(refreshToken))
                {
                    return;
                }

                OAuth2Endpoint endpoint = new OAuth2Endpoint(_client);
                IOAuth2Token   token    = await endpoint.GetTokenByRefreshTokenAsync(refreshToken);

                _client.SetOAuth2Token(token);
            } catch {
                // ignored
            }
        }
示例#26
0
        public async Task <bool> Login(string pin)
        {
            try {
                IOAuth2Token token = await _endpoint.GetTokenByPinAsync(pin);

                _client.SetOAuth2Token(token);

                FileIO.WriteRefreshToken(token.RefreshToken);

                User = token.AccountUsername;
                success.Show("Successfully logged in! Hi, " + User + "!", TimeSpan.FromSeconds(2));
                return(true);
            } catch (Exception ex) {
                error.Show("Wrong PIN? Could not login to Imgur! (" + ex.Message + ")", TimeSpan.FromSeconds(2));
                return(false);
            }
        }
示例#27
0
        public async Task <bool> Login(string pin)
        {
            try {
                IOAuth2Token token = await _endpoint.GetTokenByPinAsync(pin);

                _client.SetOAuth2Token(token);

                ConfigHelper.WriteRefreshToken(token.RefreshToken);

                User    = token.AccountUsername;
                UserUrl = $"http://{User}.imgur.com/all/";

                _success.Show(string.Format(strings.loggedIn, User), TimeSpan.FromSeconds(2));
                return(true);
            } catch (Exception ex) {
                _error.Show(string.Format(strings.wrongPin, ex.Message), TimeSpan.FromSeconds(2));
                return(false);
            }
        }
        /// <summary>
        ///     Initializes a new instance of the ApiClientBase class.
        /// </summary>
        /// <param name="clientId">The Imgur app's ClientId. </param>
        /// <param name="clientSecret">The Imgur app's ClientSecret.</param>
        /// <param name="oAuth2Token">OAuth2 credentials.</param>
        /// <exception cref="ArgumentNullException"></exception>
        protected ApiClientBase(string clientId, string clientSecret, IOAuth2Token oAuth2Token)
        {
            if (string.IsNullOrWhiteSpace(clientId))
            {
                throw new ArgumentNullException(nameof(clientId));
            }

            if (string.IsNullOrWhiteSpace(clientSecret))
            {
                throw new ArgumentNullException(nameof(clientSecret));
            }

            if (oAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(oAuth2Token));
            }

            if (oAuth2Token.AccessToken == null)
            {
                throw new ArgumentNullException(nameof(oAuth2Token.AccessToken));
            }

            if (oAuth2Token.AccountId == null)
            {
                throw new ArgumentNullException(nameof(oAuth2Token.AccountId));
            }

            if (oAuth2Token.RefreshToken == null)
            {
                throw new ArgumentNullException(nameof(oAuth2Token.RefreshToken));
            }

            if (oAuth2Token.TokenType == null)
            {
                throw new ArgumentNullException(nameof(oAuth2Token.TokenType));
            }

            ClientId     = clientId;
            ClientSecret = clientSecret;
            OAuth2Token  = oAuth2Token;
        }
示例#29
0
 public async Task uploadURLImage(IOAuth2Token token, string url)
 {
     try
     {
         var client = new ImgurClient(_clientId, _clientSecret, token);
         var endpoint = new ImageEndpoint(client);
         var image = await endpoint.UploadImageUrlAsync(url);
         Debug.Write("Image uploaded. Image Url: " + image.Link);
         sendToken();
     }
     catch (ImgurException imgurEx)
     {
         Debug.Write("An error occurred uploading an image to Imgur.");
         Debug.Write(imgurEx.Message);
     }
     catch (System.ArgumentNullException e)
     {
         Debug.Write("An error occurred uploading an image to Imgur.");
         Debug.Write(e.Message);
     }
 }
示例#30
0
        /// <summary>
        /// Sets the OAuth2Token to be used for authentication.
        /// </summary>
        /// <param name="token"></param>
        public virtual void SetOAuth2Token(IOAuth2Token token)
        {
            if (token == null)
            {
                OAuth2Token = null;
                return;
            }

            if (token.AccessToken == null)
            {
                throw new ArgumentNullException(nameof(token), "token.AccessToken property not set.");
            }

            if (token.RefreshToken == null)
            {
                throw new ArgumentNullException(nameof(token), "token.RefreshToken property not set.");
            }

            if (token.TokenType == null)
            {
                throw new ArgumentNullException(nameof(token), "token.TokenType property not set.");
            }

            if (token.AccountId == 0)
            {
                throw new ArgumentNullException(nameof(token), "token.AccountId property not set.");
            }

            if (token.AccountUsername == null)
            {
                throw new ArgumentNullException(nameof(token), "token.AccountUsername property not set.");
            }

            if (token.ExpiresIn == 0)
            {
                throw new ArgumentNullException(nameof(token), "token.ExpiresIn property not set.");
            }

            OAuth2Token = token;
        }
示例#31
0
        //Login to Imgur Account
        public async Task Login()
        {
            try {
                if (_token != null && _token.ExpiresIn > 60)
                {
                    return; // More than 60 seconds left; we don't need to login
                }
                string refreshToken = ConfigHelper.ReadRefreshToken();
                if (string.IsNullOrWhiteSpace(refreshToken)) // No refresh token found; exit
                {
                    throw new Exception("No refresh-token found!");
                }

                // Refresh access token
                OAuth2Endpoint endpoint = new OAuth2Endpoint(_client);
                _token = await endpoint.GetTokenByRefreshTokenAsync(refreshToken);

                _client.SetOAuth2Token(_token);
            } catch {
                // ignored
            }
        }
示例#32
0
        /// <summary>
        ///     Initializes a new instance of the ApiClientBase class.
        /// </summary>
        /// <param name="clientId">The Imgur app's ClientId. </param>
        /// <param name="oAuth2Token">OAuth2 credentials.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        protected ApiClientBase(string clientId, IOAuth2Token oAuth2Token) : this(clientId)
        {
            if (oAuth2Token == null)
                throw new ArgumentNullException(nameof(oAuth2Token));

            if (oAuth2Token.AccessToken == null)
                throw new ArgumentNullException(nameof(oAuth2Token.AccessToken));

            if (oAuth2Token.RefreshToken == null)
                throw new ArgumentNullException(nameof(oAuth2Token.RefreshToken));

            if (oAuth2Token.TokenType == null)
                throw new ArgumentNullException(nameof(oAuth2Token.TokenType));

            if (oAuth2Token.AccountId == null)
                throw new ArgumentNullException(nameof(oAuth2Token.AccountId));

            if (oAuth2Token.AccountUsername == null)
                throw new ArgumentNullException(nameof(oAuth2Token.AccountUsername));

            OAuth2Token = oAuth2Token;
        }
示例#33
0
        protected override async Task DoSync(ProgressDialogController pdc)
        {
            if (Me?.Name == null)
            {
                if (User.Exists(Properties.Settings.Default.MeRoot))
                {
                    Me = User.Get(Properties.Settings.Default.MeRoot);
                }
                if (Me?.Name == null)
                {
                    IOAuth2Token token = await ImgurHelper.GetToken();

                    Me = User.Create(Properties.Settings.Default.MeRoot, token.AccountUsername, token.AccountId);
                }
            }
            if (Me?.Name != null)
            {
                IsLoading = true;
                try
                {
                    pdc.SetMessage(string.Format("synchronizing account\n\n{0}\n{1}", Me.Name, Me.Root));
                    await Me.Sync(this);
                }
                catch (Exception ex)
                {
                    List <string> msgs = new List <string>();
                    while (ex != null)
                    {
                        msgs.Add(ex.Message);
                        ex = ex.InnerException;
                    }
                    await DialogCoordinator.Instance.ShowMessageAsync(this, "Failed to synchronize albums", string.Join("\n\n", msgs));
                }
                IsLoading = false;
            }
        }
示例#34
0
 public MockApiClient(string clientId, IOAuth2Token oAuth2Token) : base(clientId, oAuth2Token)
 {
 }
示例#35
0
 /// <summary>
 /// Login to Imgur with OAuth2
 /// </summary>
 public ImgurUploader()
 {
     _client = new ImgurClient(ClientId, ClientSecret);
     _token  = null;
 }
示例#36
0
        /// <summary>
        ///     Sets the oAuth2Token to be used.
        /// </summary>
        /// <param name="oAuth2Token">See <see cref="IOAuth2Token" />.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        public virtual void SetOAuth2Token(IOAuth2Token oAuth2Token)
        {
            if (oAuth2Token == null)
            {
                OAuth2Token = null;
                return;
            }

            if (oAuth2Token.AccessToken == null)
                throw new ArgumentNullException(nameof(oAuth2Token.AccessToken));

            if (oAuth2Token.RefreshToken == null)
                throw new ArgumentNullException(nameof(oAuth2Token.RefreshToken));

            if (oAuth2Token.TokenType == null)
                throw new ArgumentNullException(nameof(oAuth2Token.TokenType));

            if (oAuth2Token.AccountId == null)
                throw new ArgumentNullException(nameof(oAuth2Token.AccountId));

            if (oAuth2Token.AccountUsername == null)
                throw new ArgumentNullException(nameof(oAuth2Token.AccountUsername));

            OAuth2Token = oAuth2Token;
        }
示例#37
0
 /// <summary>
 ///     Initializes a new instance of the ImgurClient class.
 /// </summary>
 /// <param name="clientId">The Imgur app's ClientId. </param>
 /// <param name="oAuth2Token">An OAuth2 Token used for actions against a user's account.</param>
 public ImgurClient(string clientId, IOAuth2Token oAuth2Token)
     : base(clientId, oAuth2Token)
 {
 }
示例#38
0
 /// <summary>
 ///     Initializes a new instance of the ImgurClient class.
 /// </summary>
 /// <param name="clientId">The Imgur app's ClientId. </param>
 /// <param name="clientSecret">The Imgur app's ClientSecret.</param>
 /// <param name="oAuth2Token">An OAuth2 Token used for actions against a user's account.</param>
 public ImgurClient(string clientId, string clientSecret, IOAuth2Token oAuth2Token)
     : base(clientId, clientSecret, oAuth2Token)
 {
 }
示例#39
0
 public MockApiClient(string clientId, string clientSecret, IOAuth2Token oAuth2Token)
     : base(clientId, clientSecret, oAuth2Token)
 {
 }