2using System.Diagnostics;
24 #region Extension Methods
25 #region Asynchronous Invocations
47 parameters.OnError?.Invoke(
ex);
73 parameters.OnError?.Invoke(
ex);
77 #endregion Asynchronous Invocations
79 #region Synchronous Invocations
117 #endregion Synchronous Invocations
118 #endregion Extension Methods
120 #region Segmented Upload Implementation
140 if (
Utils.EnableDebugLogging)
142 Debug.WriteLine(
$"{start.ToString(API.DebugTimeFormat)} " +
143 $"{dataEndpoint.Owner.GetType().NiceTypeName()} Large File Upload Initiated " +
144 $"({(fileSize.HasValue ? fileSize + " bytes)
" : "unknown size)
")}");
150 Debug.WriteLine(
$"{now.ToString(API.DebugTimeFormat)} Upload Progress Update. " +
151 $"Time Elapsed: {(now - start).TotalMilliseconds}ms, " +
152 $"Status: {s.status} ({s.status.ToAPIString()}), " +
153 $"Uploaded: {s.bytes_uploaded} of {s.total_bytes?.ToString() ?? "(
unknown)
"}" +
154 $"{(s.commit_progress.HasValue ? $",
Commit: {
s.commit_progress}
" : "")}" +
155 $"{(String.IsNullOrEmpty(s.commit_error) ? "" : $", Error: {
s.commit_error}
")}");
167#pragma warning disable 618
176 if (
Utils.EnableDebugLogging)
177 Debug.WriteLine(
$"{DateTime.UtcNow.ToString(API.DebugTimeFormat)} - LFU " +
178 $"binary YELTLossSet detected, file size ignored.");
180#pragma warning restore 618
195 if (
Utils.EnableDebugLogging)
196 Debug.WriteLine(
$"{DateTime.UtcNow.ToString(API.DebugTimeFormat)} - " +
197 $"LFU ignored the first {bytesToSkip.Value} bytes of the stream's " +
198 $"{fileSize} total bytes in order to resume a previous upload.");
203 if (
Utils.EnableDebugLogging)
206 Debug.WriteLine(
$"{now.ToString(API.DebugTimeFormat)} Upload Complete: " +
207 $"{(now - start).TotalMilliseconds}ms");
215 if (
Utils.EnableDebugLogging)
216 Debug.WriteLine(
$"{DateTime.UtcNow.ToString(API.DebugTimeFormat)} - LFU ignored all " +
217 $"{fileSize?.ToString() ?? "(
unknown length)
"} bytes of the stream in order to " +
218 $"resume monitoring the status of a previous upload that has already been committed.");
231 if (
Utils.EnableDebugLogging)
234 Debug.WriteLine(
$"{now.ToString(API.DebugTimeFormat)} Commit Complete. " +
235 $"Total Large file upload time: {(now - start).TotalMilliseconds}ms");
245 return dataStream.CanSeek ? dataStream.Length -
dataStreamStart : (
long?)
null;
258 return dataStream.Position +=
bytes;
273 $"bytes, but the stream ended after reading {streamPosition} bytes.");
286 if (
Utils.EnableDebugLogging)
288 Debug.WriteLine(
$"{start.ToString(API.DebugTimeFormat)} - LFU " +
289 $"starting from stream position of {streamPosition} bytes out of " +
290 $"{(streamLength.HasValue ? streamLength + " bytes.
" : "(unknown size).
")}");
309#pragma warning disable 618
320#pragma warning restore 618
330 if (
Utils.EnableDebugLogging)
333 Debug.WriteLine(
$"{now.ToString(API.DebugTimeFormat)} - LFU " +
334 $"time to setup: {(now - checkpoint).TotalSeconds}s");
347 Utils.CheckForCancellation(parameters);
367 $"but the end of the data source was reached after {streamPosition} bytes.");
377 if (
Utils.EnableDebugLogging)
382 megabytes = nextChunk.LengthFilled / 1048580
d;
383 Debug.WriteLine(
$"{now.ToString(API.DebugTimeFormat)} - LFU chunk " +
384 $"{currentChunkNumber} size: {nextChunk.LengthFilled} bytes ({megabytes:0.00} MiB)");
385 Debug.WriteLine(
$"{now.ToString(API.DebugTimeFormat)} - LFU time to " +
386 $"produce chunk {currentChunkNumber}: {elapsedSeconds}s (" +
392 if (
Utils.EnableDebugLogging)
397 Debug.WriteLine(
$"{now.ToString(API.DebugTimeFormat)} - LFU time " +
398 $"to upload chunk {currentChunkNumber}: {elapsedSeconds}s " +
399 $"({megabytes / elapsedSeconds:0.0} MiBps)");
408 Debug.WriteLine(
$"Compressed a total of {sourceAsGZipProducer.TotalBytesIn} bytes " +
409 $"into {sourceAsGZipProducer.TotalBytesOut} bytes (" +
410 $"{sourceAsGZipProducer.TotalBytesOut / (double)sourceAsGZipProducer.TotalBytesIn:P2} the original size).");
413 if (
Utils.EnableDebugLogging)
420 Debug.WriteLine(
$"{now.ToString(API.DebugTimeFormat)} - LFU " +
421 $"total upload time: {total_elapsed}s for {total_bytes} bytes " +
422 $"({total_megabytes:0.0} MiB - {total_megabytes / total_elapsed:0.0} MiBps)");
433 Utils.CheckForCancellation(parameters);
462 if (!status.
status.IsBusy() && !status.
status.IsProcessingComplete())
468 if (status ==
null || status.
status.IsBusy())
473 else if (status.
status.IsError())
477 $"The data endpoint entered an unexpected state \"{status.status}\" " +
478 $"while attempting to commit the upload. Server status is: {status.status}"));
487 Name =
"Content-Encoding",
507 catch (TimeoutException)
523 if (!status.status.IsBusy() && !status.status.IsProcessingComplete())
528 Utils.CheckForCancellation(parameters);
561 "because existing data has already been successfully uploaded.");
566 "of this data upload process. Cannot continue.");
575 "being processed and cannot be deleted. Please wait until processing is " +
576 "of the file is complete.");
592 throw new Exception(
$"Internal error. Unexpected status: {state}");
603 $"Attempted to resume an existing upload session with a file of different size. " +
604 $"Prior file size: {status.total_bytes.Value} This file size: {fileSize}");
619 "Server status response was missing the expected bytes_uploaded value.");
623 $"{status.bytes_uploaded} which exceeds this file's size of: {fileSize}");
629 #endregion Segmented Upload Implementation
A custom exception class that includes the RestSharp.IRestResponse that generated the exception,...
Describes an endpoint off of some types of resources from which an associated "large data file" can b...
Describes a collection of resources which can be listed.
Parameters to be used in a Large Upload operation.
Action< StatusResponse > OnProgressUpdate
Action to invoke every time a chunk is uploaded. Callback is supplied with a double indicating progre...
Action< StatusResponse > OnSuccess
Action to invoke upon successful completion of the large upload.
Action< Exception > OnError
Action to invoke upon failure of the large upload. If this is supplied, it will be called when an err...
Converts a YELT CSV data into a specified format.
Produces a BlockingCollection of buffered bytes asynchronously which can be consumed on some other th...
Exception raised when the commit process fails.
Converts buffered bytes to strings.
Parameters to be used in a Large Data Upload operation.
PollingOptions commit_polling_options
Determines how the system polls the status of the data file while waiting for the data to be processe...
int chunk_timeout
The timeout (in milliseconds) for a single chunk upload to complete. Default: 60,000 ms (1 minute).
HandleUploadInSessionStrategy handle_existing_upload_strategy
The HandleUploadInSessionStrategy to employ of an existing upload session is already in progress....
BinaryYELTUploadOptions
Options for controlling whether to automatically convert a binary YELTLossSet's data to the binary fo...
bool enable_compression
Whether to compress (gzip) the data during upload. (Default: False) Set to true if the files you're u...
int max_chunk_size
The maximum size of a single uploaded chunk in bytes. Default: 2^24 bytes (16 Megabytes).
int min_chunk_size
The minimum size of a single uploaded chunk in bytes. Set this larger if there is enough latency betw...
BinaryYELTUploadOptions binary_yelt_options
Options for controlling whether to automatically convert a binary YELTLossSet's data to the binary fo...
int max_retries_per_chunk
The maximum number of retries for a failed chunk upload before an error is thrown....
Indicates the status of a data endpoint.
TaskStatus status
The state of the data upload, as an enumeration.
string commit_error
If the processing of the file failed, the error message reported by the server.
long? bytes_uploaded
The number of bytes that have been uploaded by the client so far.
long? total_bytes
Total number of bytes in the file to be uploaded.
Indicates that a large upload could not take place because an existing large upload session is alread...
Large Data Upload Utilities.
Representation of a loss set with an associated year-event-loss table.
DataType
The format of the data uploaded against this YELT.
CancellationToken? CancellationToken
A cancellation token (if available) supplied to the polling method to allow the polling task to be ca...
int MaxPollTotalTime
The maximum time (in milliseconds) to poll the request before raising a NotWaitingException....
Helper class which makes it easier to build a set of request parameters.
HandleUploadInSessionStrategy
Behaviour to use if an existing upload is already in progress for an endpoint.
The structure containing an array of bytes and integer indicating the number of bytes in the array th...
TaskStatus
The status of a data upload which may be in progress.