internal static async Task<Stream> DownloadAsyncImpl(IHoldProfilingInformation self, HttpJsonRequestFactory requestFactory, FilesConvention conventions, NameValueCollection operationsHeaders, string path, string filename, Reference<RavenJObject> metadataRef, long? @from, long? to, string baseUrl, OperationCredentials credentials) { var request = requestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(self, baseUrl + path + Uri.EscapeDataString(filename), "GET", credentials, conventions)).AddOperationHeaders(operationsHeaders); if (@from != null) { if (to != null) request.AddRange(@from.Value, to.Value); else request.AddRange(@from.Value); } try { var response = await request.ExecuteRawResponseAsync().ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.NotFound) throw new FileNotFoundException("The file requested does not exists on the file system.", baseUrl + path + filename); await response.AssertNotFailingResponse().ConfigureAwait(false); if (metadataRef != null) metadataRef.Value = response.HeadersToObject(); return new DisposableStream(await response.GetResponseStreamWithHttpDecompression().ConfigureAwait(false), request.Dispose); } catch (Exception e) { throw e.SimplifyException(); } }
internal static async Task<RavenJObject> GetMetadataForAsyncImpl(IHoldProfilingInformation self, HttpJsonRequestFactory requestFactory, FilesConvention conventions, NameValueCollection operationsHeaders, string filename, string baseUrl, OperationCredentials credentials) { using (var request = requestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(self, baseUrl + "/files?name=" + Uri.EscapeDataString(filename), "HEAD", credentials, conventions)).AddOperationHeaders(operationsHeaders)) { try { await request.ExecuteRequestAsync().ConfigureAwait(false); var response = request.Response; var metadata = response.HeadersToObject(); metadata[Constants.MetadataEtagField] = metadata[Constants.MetadataEtagField].Value<string>().Trim('\"'); return metadata; } catch (Exception e) { try { throw e.SimplifyException(); } catch (FileNotFoundException) { return null; } } } }
public FilesChangesClient(string url, string apiKey, ICredentials credentials, HttpJsonRequestFactory jsonRequestFactory, FilesConvention conventions, IReplicationInformerBase replicationInformer, Action onDispose) : base(url, apiKey, credentials, jsonRequestFactory, conventions, replicationInformer, onDispose) { }
public FilesChangesClient(string url, string apiKey, ICredentials credentials, HttpJsonRequestFactory jsonRequestFactory, FilesConvention conventions, IReplicationInformerBase replicationInformer, Func <string, FileHeader, string, Action, Task <bool> > tryResolveConflictByUsingRegisteredConflictListenersAsync, Action onDispose) : base(url, apiKey, credentials, jsonRequestFactory, conventions, replicationInformer, onDispose) { this.tryResolveConflictByUsingRegisteredConflictListenersAsync = tryResolveConflictByUsingRegisteredConflictListenersAsync; }
public async Task <SynchronizationReport> SynchronizeFileToAsync(string fileName, SynchronizationDestination destination) { ICredentials credentials = null; if (string.IsNullOrEmpty(destination.Username) == false) { credentials = string.IsNullOrEmpty(destination.Domain) ? new NetworkCredential(destination.Username, destination.Password) : new NetworkCredential(destination.Username, destination.Password, destination.Domain); } var conventions = new FilesConvention(); if (string.IsNullOrEmpty(destination.AuthenticationScheme) == false) { conventions.AuthenticationScheme = destination.AuthenticationScheme; } var destinationClient = new SynchronizationServerClient(destination.ServerUrl, destination.FileSystem, convention: conventions, apiKey: destination.ApiKey, credentials: credentials); RavenJObject destinationMetadata; try { destinationMetadata = await destinationClient.GetMetadataForAsync(fileName).ConfigureAwait(false); } catch (Exception ex) { var exceptionMessage = "Could not get metadata details for " + fileName + " from " + destination.Url; Log.WarnException(exceptionMessage, ex); return(new SynchronizationReport(fileName, Guid.Empty, SynchronizationType.Unknown) { Exception = new SynchronizationException(exceptionMessage, ex) }); } RavenJObject localMetadata = GetLocalMetadata(fileName); NoSyncReason reason; SynchronizationWorkItem work = synchronizationStrategy.DetermineWork(fileName, localMetadata, destinationMetadata, FileSystemUrl, out reason); if (work == null) { Log.Debug("File '{0}' was not synchronized to {1}. {2}", fileName, destination.Url, reason.GetDescription()); return(new SynchronizationReport(fileName, Guid.Empty, SynchronizationType.Unknown) { Exception = new SynchronizationException(reason.GetDescription()) }); } return(await PerformSynchronizationAsync(destinationClient, work).ConfigureAwait(false)); }
public RegionMetadataBasedResolutionStrategy(IList <string> shardIds, ShardStrategy.ModifyFileNameFunc modifyFileName, FilesConvention conventions) { this.shardIds = shardIds; this.modifyFileName = modifyFileName; this.conventions = conventions; }
public RegionMetadataBasedResolutionStrategy(IList<string> shardIds, ShardStrategy.ModifyFileNameFunc modifyFileName, FilesConvention conventions) { this.shardIds = shardIds; this.modifyFileName = modifyFileName; this.conventions = conventions; }
internal static async Task <Stream> DownloadAsyncImpl(IHoldProfilingInformation self, HttpJsonRequestFactory requestFactory, FilesConvention conventions, NameValueCollection operationsHeaders, string path, string filename, Reference <RavenJObject> metadataRef, long? @from, long?to, string baseUrl, OperationCredentials credentials) { var request = requestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(self, baseUrl + path + Uri.EscapeDataString(filename), "GET", credentials, conventions)).AddOperationHeaders(operationsHeaders); if (@from != null) { if (to != null) { request.AddRange(@from.Value, to.Value); } else { request.AddRange(@from.Value); } } try { var response = await request.ExecuteRawResponseAsync().ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.NotFound) { throw new FileNotFoundException("The file requested does not exists on the file system.", baseUrl + path + filename); } await response.AssertNotFailingResponse().ConfigureAwait(false); if (metadataRef != null) { metadataRef.Value = response.HeadersToObject(); } return(new DisposableStream(await response.GetResponseStreamWithHttpDecompression().ConfigureAwait(false), request.Dispose)); } catch (Exception e) { throw e.SimplifyException(); } }
internal static async Task <RavenJObject> GetMetadataForAsyncImpl(IHoldProfilingInformation self, HttpJsonRequestFactory requestFactory, FilesConvention conventions, NameValueCollection operationsHeaders, string filename, string baseUrl, OperationCredentials credentials) { using (var request = requestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(self, baseUrl + "/files?name=" + Uri.EscapeDataString(filename), "HEAD", credentials, conventions)).AddOperationHeaders(operationsHeaders)) { try { await request.ExecuteRequestAsync().ConfigureAwait(false); var response = request.Response; var metadata = response.HeadersToObject(); metadata[Constants.MetadataEtagField] = metadata[Constants.MetadataEtagField].Value <string>().Trim('\"'); return(metadata); } catch (Exception e) { try { throw e.SimplifyException(); } catch (FileNotFoundException) { return(null); } } } }
public FilesReplicationInformer(FilesConvention conventions, HttpJsonRequestFactory requestFactory) : base(conventions, requestFactory) { }
public CountryResolutionStrategy(IList <string> shardIds, ShardStrategy.ModifyFileNameFunc modifyFileName, FilesConvention conventions) { this.shardIds = shardIds; this.modifyFileName = modifyFileName; this.conventions = conventions; }