public async Task <SyncedFileInfo> SendFile(Stream stream, string[] pathParts, SyncTarget target, IProgress <double> progress, CancellationToken cancellationToken)
        {
            _logger.Debug("Sending file {0} to {1}", string.Join("/", pathParts), target.Name);

            var syncAccount = _configurationRetriever.GetSyncAccount(target.Id);

            var googleCredentials = GetGoogleCredentials(target);

            var file = await _googleDriveService.UploadFile(stream, pathParts, syncAccount.FolderId, googleCredentials, progress, cancellationToken);

            return(new SyncedFileInfo
            {
                Path = file.Item2,
                Protocol = MediaProtocol.Http,
                Id = file.Item1
            });
        }
        public async Task <SyncedFileInfo> SendFile(Stream stream, string[] pathParts, SyncTarget target, IProgress <double> progress, CancellationToken cancellationToken)
        {
            var path = GetFullPath(pathParts, target);

            _logger.Debug("Sending file {0} to {1}", path, target.Name);

            var syncAccount = _configurationRetriever.GetSyncAccount(target.Id);

            await UploadFile(path, stream, syncAccount.AccessToken, cancellationToken);

            return(new SyncedFileInfo
            {
                Id = path,
                Path = path,
                Protocol = MediaProtocol.Http
            });
        }
        public OneDriveCredentials(IConfigurationRetriever configurationRetriever, ILiveAuthenticationApi liveAuthenticationApi, SyncTarget target)
        {
            _configurationRetriever = configurationRetriever;
            _liveAuthenticationApi = liveAuthenticationApi;
            _syncAccountId = target.Id;

            var syncAccount = configurationRetriever.GetSyncAccount(target.Id);
            _accessToken = syncAccount.AccessToken;
        }
        public OneDriveCredentials(IConfigurationRetriever configurationRetriever, ILiveAuthenticationApi liveAuthenticationApi, SyncTarget target)
        {
            _configurationRetriever = configurationRetriever;
            _liveAuthenticationApi  = liveAuthenticationApi;
            _syncAccountId          = target.Id;

            var syncAccount = configurationRetriever.GetSyncAccount(target.Id);

            _accessToken = syncAccount.AccessToken;
        }
        private async Task RefreshToken(CancellationToken cancellationToken)
        {
            var config       = _configurationRetriever.GetGeneralConfiguration();
            var now          = DateTime.UtcNow;
            var refreshToken = await _liveAuthenticationApi.RefreshToken(_accessToken.RefresToken, Constants.OneDriveRedirectUrl, config.OneDriveClientId, config.OneDriveClientSecret, cancellationToken);

            _accessToken.AccessToken = refreshToken.access_token;
            _accessToken.ExpiresAt   = now.AddSeconds(refreshToken.expires_in);
            _accessToken.RefresToken = refreshToken.refresh_token;

            var syncAccount = _configurationRetriever.GetSyncAccount(_syncAccountId);

            syncAccount.AccessToken = _accessToken;

            _configurationRetriever.AddSyncAccount(syncAccount);
        }
Example #6
0
 public GoogleDriveSyncAccount Get(GetSyncTarget request)
 {
     return(_configurationRetriever.GetSyncAccount(request.Id));
 }
 public DropboxSyncAccount Get(GetSyncTarget request)
 {
     return(_configurationRetriever.GetSyncAccount(request.Id));
 }