public async Task <SynchronizationReport> PushChangesAsync(CancellationToken token)
        {
            token.Register(() => { });//request.Abort() TODO: check this

            token.ThrowIfCancellationRequested();

            if (sourceStream.CanRead == false)
            {
                throw new Exception("Stream does not support reading");
            }

            var baseUrl     = synchronizationServerClient.BaseUrl;
            var credentials = synchronizationServerClient.Credentials;
            var conventions = synchronizationServerClient.Conventions;

            var requestParams = new CreateHttpJsonRequestParams(this, baseUrl + "/synchronization/MultipartProceed", "POST", credentials, conventions, timeout: TimeSpan.FromHours(12))
            {
                DisableRequestCompression = true
            };

            using (var request = synchronizationServerClient.RequestFactory.CreateHttpJsonRequest(requestParams))
            {
                request.AddHeaders(sourceMetadata);
                request.AddHeader("Content-Type", "multipart/form-data; boundary=" + syncingBoundary);
                request.AddHeader("If-None-Match", "\"" + sourceMetadata.Value <string>(Constants.MetadataEtagField) + "\"");

                request.AddHeader(SyncingMultipartConstants.FileName, fileName);
                request.AddHeader(SyncingMultipartConstants.SourceFileSystemInfo, fileSystemInfo.AsJson());

                try
                {
                    await request.WriteAsync(PrepareMultipartContent(token)).ConfigureAwait(false);

                    var response = await request.ReadResponseJsonAsync().ConfigureAwait(false);

                    return(JsonExtensions.CreateDefaultJsonSerializer().Deserialize <SynchronizationReport>(new RavenJTokenReader(response)));
                }
                catch (Exception exception)
                {
                    if (token.IsCancellationRequested)
                    {
                        throw new OperationCanceledException(token);
                    }

                    var webException = exception as ErrorResponseException;

                    if (webException != null)
                    {
                        webException.SimplifyException();
                    }

                    throw;
                }
            }
        }
Beispiel #2
0
        public async Task <SynchronizationReport> UpdateMetadataAsync(string fileName, RavenJObject metadata, FileSystemInfo sourceFileSystem)
        {
            using (var request = RequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(this, baseUrl + "/synchronization/UpdateMetadata/" + Uri.EscapeDataString(fileName), HttpMethod.Post, Credentials, Conventions)).AddOperationHeaders(OperationsHeaders))
            {
                request.AddHeaders(metadata);
                request.AddHeader(SyncingMultipartConstants.SourceFileSystemInfo, sourceFileSystem.AsJson());
                AsyncFilesServerClientExtension.AddEtagHeader(request, Etag.Parse(metadata.Value <string>(Constants.MetadataEtagField)));

                try
                {
                    var response = (RavenJObject)await request.ReadResponseJsonAsync().ConfigureAwait(false);

                    return(response.JsonDeserialization <SynchronizationReport>());
                }
                catch (ErrorResponseException exception)
                {
                    throw exception.SimplifyException();
                }
            }
        }
        public async Task<SynchronizationReport> RenameAsync(string currentName, string newName, RavenJObject metadata, FileSystemInfo sourceFileSystem)
        {
            using (var request = RequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(this, baseUrl + "/synchronization/rename?filename=" + Uri.EscapeDataString(currentName) + "&rename=" + Uri.EscapeDataString(newName), "PATCH", Credentials, Conventions)).AddOperationHeaders(OperationsHeaders))
            {
                request.AddHeaders(metadata);
                request.AddHeader(SyncingMultipartConstants.SourceFileSystemInfo, sourceFileSystem.AsJson());
                AsyncFilesServerClientExtension.AddEtagHeader(request, Etag.Parse(metadata.Value<string>(Constants.MetadataEtagField)));

                try
                {
                    var response = (RavenJObject)await request.ReadResponseJsonAsync().ConfigureAwait(false);
                    return response.JsonDeserialization<SynchronizationReport>();
                }
                catch (ErrorResponseException exception)
                {
                    throw exception.SimplifyException();
                }
            }
        }