/// <inheritdoc/> protected override void ProcessRecordInternal() { var imageStoreCopyDescription = new ImageStoreCopyDescription( remoteSource: this.RemoteSource, remoteDestination: this.RemoteDestination, skipFiles: this.SkipFiles, checkMarkFile: this.CheckMarkFile); this.ServiceFabricClient.ImageStore.CopyImageStoreContentAsync( imageStoreCopyDescription: imageStoreCopyDescription, serverTimeout: this.ServerTimeout, cancellationToken: this.CancellationToken).GetAwaiter().GetResult(); Console.WriteLine("Success!"); }
/// <summary> /// Serializes the object to JSON. /// </summary> /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param> /// <param name="obj">The object to serialize to JSON.</param> internal static void Serialize(JsonWriter writer, ImageStoreCopyDescription obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); writer.WriteProperty(obj.RemoteSource, "RemoteSource", JsonWriterExtensions.WriteStringValue); writer.WriteProperty(obj.RemoteDestination, "RemoteDestination", JsonWriterExtensions.WriteStringValue); if (obj.SkipFiles != null) { writer.WriteEnumerableProperty(obj.SkipFiles, "SkipFiles", (w, v) => writer.WriteStringValue(v)); } if (obj.CheckMarkFile != null) { writer.WriteProperty(obj.CheckMarkFile, "CheckMarkFile", JsonWriterExtensions.WriteBoolValue); } writer.WriteEndObject(); }
/// <inheritdoc /> public Task CopyImageStoreContentAsync( ImageStoreCopyDescription imageStoreCopyDescription, long?serverTimeout = 60, CancellationToken cancellationToken = default(CancellationToken)) { imageStoreCopyDescription.ThrowIfNull(nameof(imageStoreCopyDescription)); serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295); var requestId = Guid.NewGuid().ToString(); var url = "ImageStore/$/Copy"; var queryParams = new List <string>(); // Append to queryParams if not null. serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}"); queryParams.Add("api-version=6.0"); url += "?" + string.Join("&", queryParams); string content; using (var sw = new StringWriter()) { ImageStoreCopyDescriptionConverter.Serialize(new JsonTextWriter(sw), imageStoreCopyDescription); content = sw.ToString(); } HttpRequestMessage RequestFunc() { var request = new HttpRequestMessage() { Method = HttpMethod.Post, Content = new StringContent(content, Encoding.UTF8), }; request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); return(request); } return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken)); }
/// <inheritdoc /> public async Task CopyImageStoreContentAsync( ImageStoreCopyDescription imageStoreCopyDescription, long?serverTimeout = 60, CancellationToken cancellationToken = default(CancellationToken)) { imageStoreCopyDescription.ThrowIfNull(nameof(imageStoreCopyDescription)); await this.LoadImageStoreConnectionString(); if (this.isLocalStore) { var source = Path.Combine(this.imageStorePath, imageStoreCopyDescription.RemoteSource); var destination = Path.Combine(this.imageStorePath, imageStoreCopyDescription.RemoteDestination); FileAttributes attr = File.GetAttributes(source); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { var files = Directory.EnumerateFiles(source, "*", SearchOption.AllDirectories) .Select(file => new System.IO.FileInfo(file)); foreach (var file in files) { var targetPath = Path.Combine(this.imageStorePath, Path.Combine(destination, file.FullName.Substring(source.Length + 1))); if (!Directory.Exists(Path.GetDirectoryName(targetPath))) { Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); } File.Copy(file.FullName, targetPath, true); } } else { File.Copy(source, destination, true); } } else { serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295); var requestId = Guid.NewGuid().ToString(); var url = "ImageStore/$/Copy"; var queryParams = new List <string>(); // Append to queryParams if not null. serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}"); queryParams.Add("api-version=6.0"); url += "?" + string.Join("&", queryParams); string content; using (var sw = new StringWriter()) { ImageStoreCopyDescriptionConverter.Serialize(new JsonTextWriter(sw), imageStoreCopyDescription); content = sw.ToString(); } HttpRequestMessage RequestFunc() { var request = new HttpRequestMessage() { Method = HttpMethod.Post, Content = new StringContent(content, Encoding.UTF8), }; request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); return(request); } await this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken); } }