Esempio n. 1
0
 public DownloadJobRunner(Credentials credentials, StorageSettings storageSettings)
 {
     _credentials = credentials;
    
     _httpClient = new ExHttpClient();
     
     _downloader = new FileDownloader();
     _storageAllocator = new StorageAllocator(storageSettings);
 }
Esempio n. 2
0
        private static async Task DeleteObjectAsync(long objectId, Credentials credentials)
        {
            var httpClient = new ExHttpClient();
            var cookies = httpClient.GetCookiesAsync(credentials).Result;

            await httpClient.DeleteObjectAsync(objectId, cookies);

            Debug.WriteLine("Deleted object #{0}", objectId);
        }
Esempio n. 3
0
        public async Task UploadFileAsync(string path, long objectId, Credentials credentials)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("path");
            }

            var fileInfo = new FileInfo(path);
            await UploadInternal(fileInfo.Name, fileInfo.Length, objectId, credentials, new FileStream(path, FileMode.Open));
        }
        public void should_return_response_with_new_token_on_signin(Credentials credentials, User user, string token)
        {
            userService.GetUserByLogin(credentials.Login).Returns(user);
            cryptographyService.CheckPassword(user.PasswordHash, user.PasswordSalt, credentials.Password).Returns(true);
            tokenService.CreateToken(user.Id, user.Login).Returns(token);

            var result = controller.Post(credentials);
            var response = result as TokenResponse;

            response.Token.Should().Be(token);
            response.Id.Should().Be(user.Id);
            response.Login.Should().Be(credentials.Login);
        }
Esempio n. 5
0
        private async Task UploadInternal(string fileName, long fileSize, long objectId, Credentials credentials, Stream stream)
        {
            var fileTime = DateTime.Now;    //doesn't matter;
            var loginResult = await _apiClient.Login(credentials);
            
            var initResult = await _apiClient.InitUpload(loginResult.FsId,
                    fileName,
                    fileSize,
                    fileTime);

            var offset = 0;
            var blockId = 0;

            using (stream)
            {
                var buffer = new byte[_blockSize];
                int bytesRead;
                while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    var takeBytes = ((bytesRead < _blockSize) ? bytesRead : _blockSize);

                    var block = new Block
                    {
                        Offset = offset,
                        Length = takeBytes,
                        Content = buffer.Take(takeBytes).ToArray(),
                        BlockId = blockId
                    };

                    offset += _blockSize;
                    blockId++;

                    var writeResult = _apiClient.FWrite(loginResult.FsId, initResult.Fid, block.Offset, block.Length, block.Content).Result;
                    Console.WriteLine("#{0} {1}", block.BlockId, writeResult.OriginalResult);
                }

                stream.Position = 0;

                FDoneResult doneResult = _apiClient.FDone(
                    loginResult.FsId,
                    initResult.Fid,
                    fileName,
                    fileTime,
                    fileSize,
                    stream.CalculateMd5Hash(), 
                    credentials,
                    objectId).Result;

                Console.WriteLine(doneResult.MD5);
            }
        }
Esempio n. 6
0
        private static async Task<long> GetNewObjectIdAsync(Credentials credentials)
        {
            var httpClient = new ExHttpClient();
            var cookies = httpClient.GetCookiesAsync(credentials).Result;

            var url = await httpClient.GetNewObjectUriAsync(cookies);

            long newId = long.Parse(url.Segments.Last());

            await httpClient.SaveObjectAsync(newId, "Test object created", "test content", cookies);
            
            Debug.WriteLine("Created object #{0}", newId);

            return await Task.FromResult(newId);
        }
 public object Post(Credentials credentials)
 {
     var user = userService.GetUserByLogin(credentials.Login);
     if (user != null &&
         cryptographyService.CheckPassword(user.PasswordHash, user.PasswordSalt, credentials.Password))
     {
         var token = tokenService.CreateToken(user.Id, user.Login);
         var response = new TokenResponse
         {
             Id = user.Id,
             Login = credentials.Login,
             Token = token,
         };
         return response;
     }
     var message = new HttpResponseMessage(HttpStatusCode.BadRequest)
     {
         ReasonPhrase = UnknownUserMessage
     };
     return message;
 }
Esempio n. 8
0
 public async Task UploadBytesAsync(byte[] bytes, string fileName, long objectId, Credentials credentials)
 {
     await UploadInternal(fileName, bytes.Length, objectId, credentials, new MemoryStream(bytes));
 }
Esempio n. 9
0
 public Runner(Credentials credentials)
 {
     _credentials = credentials;
 }
        public void should_return_unknown_user_when_user_is_found_but_password_not_recognized_on_signin(Credentials credentials, User user)
        {
            userService.GetUserByLogin(credentials.Login).Returns(user);
            cryptographyService.CheckPassword(user.PasswordHash, user.PasswordSalt, credentials.Password).Returns(false);

            var result = controller.Post(credentials);
            var message = result as HttpResponseMessage;

            message.ReasonPhrase.Should().Be(AuthorizationController.UnknownUserMessage);
        }
        public void should_return_unknown_user_when_user_is_not_found_on_signin(Credentials credentials)
        {
            User user = null;
            userService.GetUserByLogin(credentials.Login).Returns(user);

            var result = controller.Post(credentials);
            var message = result as HttpResponseMessage;

            message.ReasonPhrase.Should().Be(AuthorizationController.UnknownUserMessage);
        }
Esempio n. 12
0
 public SyncJobManager(Credentials credentials)
 {
     this._runner = new Runner(credentials);
 }