예제 #1
0
        public IStorageProvider GetProviderByAccount(AccountConfiguration account)
        {
            if (account == null) throw new ArgumentNullException("account");

            var descriptor = StorageRegistry.Descriptors.FirstOrDefault(_ => _.Type == account.Type);
            if (descriptor == null)
                throw new NotImplementedException(string.Format("A provider for type '{0}' is not implemented.",
                    account.Type));

            var provider = descriptor.ProviderFactory(account);

            return provider;
        }
예제 #2
0
        public static async Task<BoxClient> GetClient(AccountConfiguration account)
        {
            if (Cache.ContainsKey(account.Id)) return Cache[account.Id];

            var session = new OAuthSession(null, account.Secret, 0, "bearer");

            var client = GetClient(session);
            client.Auth.SessionAuthenticated += (sender, args) => account.Secret = args.Session.RefreshToken;

            session = await client.Auth.RefreshAccessTokenAsync(account.Secret);
            Cache.Add(account.Id, client);

            return client;
        }
예제 #3
0
        public static AmazonS3Client GetApi(AccountConfiguration account)
        {
            var credentials = new BasicAWSCredentials(account.Id, account.Secret);

            var region = RegionEndpoint.USWest1;
            if (account.AdditionalSettings != null && account.AdditionalSettings.ContainsKey("AWSRegion"))
            {
                var regionName = account.AdditionalSettings["AWSRegion"];
                region = RegionEndpoint.GetBySystemName(regionName);
            }

            var api = GetApi(credentials, region);

            return api;
        }
        public async Task<AccountConfiguration> CreateAccount()
        {
            var isOk = OAuth2Flow.TryAuthenticate(this);

            if (!isOk) return null;

            var hubicAccount = await HubiCHelper.GetAccountAsync(_token.AccessToken);

            var account = new AccountConfiguration()
            {
                Type = StorageType.HubiC,
                Id = hubicAccount.EMail,
                Name = string.Format("{0} {1}", hubicAccount.FirstName, hubicAccount.LastName),
                Secret = _token.RefreshToken,
            };
            
            return account;
        }
        public async Task<AccountConfiguration> CreateAccount()
        {
            var isOk = OAuth2Flow.TryAuthenticate(this);

            if (!isOk) return null;

            var profile = await _api.Profile.GetProfile();

            var account = new AccountConfiguration()
            {
                Id = profile.user_id,
                Name = profile.name,
                Type = StorageType.AmazonDrive,
                Secret = _token.RefreshToken,
            };

            return account;
        }
        public async Task<AccountConfiguration> CreateAccount()
        {
            var account = new AccountConfiguration()
            {
                Type = StorageType.GoogleDrive
            };

            var api = await GoogleDriveHelper.GetClient(account);

            var query = api.About.Get();
            query.Fields = "user";
            var about = await query.ExecuteAsync();

            account.Id = about.User.PermissionId;
            account.Name = about.User.DisplayName;
          
            return account;
        }
        public async Task<AccountConfiguration> CreateAccount()
        {
            var isOk = OAuth2Flow.TryAuthenticate(this);

            if (!isOk) return null;

            var api = DropboxHelper.GetApi(_oauthResponse.AccessToken);
            var owner = await api.Users.GetCurrentAccountAsync();

            var account = new AccountConfiguration()
            {
                Id = owner.AccountId,
                Name = owner.Name.DisplayName,
                Type = _isAccessRestricted ? StorageType.DropboxRestricted : StorageType.Dropbox,
                Secret = _oauthResponse.AccessToken,
            };

            return account;
        }
        public async Task<AccountConfiguration> CreateAccount()
        {
            _api = new OneDriveConsumerApi(OneDriveHelper.OneDriveClientId, OneDriveHelper.OneDriveClientSecret);

            var isOk = OAuth2Flow.TryAuthenticate(this);
            if (!isOk) return null;

            var drive = await _api.GetDrive();

            var account = new AccountConfiguration
            {
                Type = StorageType.OneDrive,
                Name = drive.Owner.User.DisplayName,
                Id = drive.Id,
                Secret = _api.AccessToken.RefreshToken
            };


            return account;
        }
        public async Task<AccountConfiguration> CreateAccount()
        {
            _oAuthHelper = new OAuthHelper();

            var isOk = OAuth2Flow.TryAuthenticate(this);
            if (!isOk) return null;

            var api = await OneDriveHelper.GetApi(_accountSession);
            var drive = await api.Drive.Request().GetAsync().ConfigureAwait(false);

            var account = new AccountConfiguration
            {
                Type = StorageType.OneDrive,
                Name = drive.Owner.User.DisplayName,
                Id = drive.Owner.User.Id,
                Secret = _accountSession.RefreshToken
            };


            return account;
        }
        public async Task<AccountConfiguration> CreateAccount()
        {
            var isOk = OAuth2Flow.TryAuthenticate(this);
            if (!isOk) return null;

            var api = await GoogleDriveHelper.GetClient(_token);

            var query = api.About.Get();
            query.Fields = "user";
            var about = await query.ExecuteAsync();

            var account = new AccountConfiguration()
            {
                Type = StorageType.GoogleDrive,
                Id = about.User.PermissionId,
                Name = about.User.DisplayName,
                Secret = _token.RefreshToken
            };

          
            return account;
        }
예제 #11
0
        public async Task CheckOrUpdateAccount(AccountConfiguration account)
        {
            var provider = _storageService.GetProviderByAccount(account);
            if (provider == null) return;

            try
            {
                var root = await provider.GetRootItem();
                var result = await provider.GetChildrenByParentItem(root);
                if (result != null)
                {
                    MessageService.ShowInfo("Connecting to this account succeeded.");
                    return;
                }

                MessageService.ShowWarning("Connecting to this account failed!", "Root folder could not be read.", "Try to re-authorize in next step.");
            }
            catch (Exception ex)
            {
                MessageService.ShowWarning("Connecting to this account failed!", ex, "Try to re-authorize in next step.");

            }

            var newAccount = await _storageService.CreateAccount(account.Type);
            if (newAccount == null)
            {
                MessageService.ShowWarning("Re-Authorization failed or cancelled by user!");
            }
            else if (newAccount.Id != account.Id)
            {
                MessageService.ShowWarning("Re-Authorization failed!", "The entered credentials do not belong to this account.");
            }
            else
            {
                account.Secret = newAccount.Secret;
                MessageService.ShowInfo("Re-Authorization succeeded!");
            }
        }
        public async Task<AccountConfiguration> CreateAccount()
        {
            var isOk = OAuth2Flow.TryAuthenticate(this);

            if (!isOk) return null;

            var client = HiDriveHelper.GetClient(_authenticator);
            //var fields = new[]
            //{
            //    User.Fields.Account, User.Fields.Alias, User.Fields.Description, User.Fields.Protocols, User.Fields.IsAdmin,
            //    User.Fields.EMail, User.Fields.IsEncrypted, User.Fields.Home, User.Fields.HomeId, User.Fields.IsOwner, User.Fields.Language, 
            //};
            var user = await client.User.Me.Get().ExecuteAsync();
            
            var account = new AccountConfiguration()
            {
                Type = StorageType.HiDrive,
                Id = user.Account,
                Name = user.Alias,
                Secret = _authenticator.Token.RefreshToken,
            };

            return account;
        }
예제 #13
0
 public BoxStorageProvider(AccountConfiguration account)
 {
     _account = account;
 }
예제 #14
0
 public OneDriveStorageProvider(AccountConfiguration account)
 {
     if (account == null) throw new ArgumentNullException("account");
     _account = account;
 }
예제 #15
0
 public AmazonS3StorageProvider(AccountConfiguration account)
 {
     _account = account;
 }
예제 #16
0
 public DropboxStorageProvider(AccountConfiguration account)
 {
     this.account = account;
 }
예제 #17
0
 public HubiCStorageProvider(AccountConfiguration account)
 {
     if (account == null) throw new ArgumentNullException("account");
     this._account = account;
 }
예제 #18
0
 public static async Task<DriveService> GetClient(AccountConfiguration account)
 {
     return await GetClient(new TokenResponse { RefreshToken = account.Secret } );
 }
예제 #19
0
 public static async Task<IHiDriveClient> GetClient(AccountConfiguration account)
 {
     return await GetClient(account.Secret);
 }
 public AmazonDriveStorageProvider(AccountConfiguration account)
 {
     this.account = account;
 }