public void OnException(SmugglerException exception) { }
/// <summary> /// Export counter data to specified destination (a file or a stream) /// </summary> /// <param name="exportOptions">options to specify the source and destination of the export</param> /// <exception cref="UnauthorizedAccessException">The caller does not have the required permission.-or- specified a file that is read-only. </exception> /// <exception cref="DirectoryNotFoundException">The specified path is invalid (for example, it is on an unmapped drive). </exception> /// <exception cref="IOException">An I/O error occurred while creating the file. </exception> /// <exception cref="SmugglerException">Encapsulates exception that happens when actually exporting data. See InnerException for details.</exception> public async Task <CounterOperationState> ExportData(SmugglerExportOptions <CounterConnectionStringOptions> exportOptions) { if (exportOptions.From == null) { throw new ArgumentNullException("exportOptions.From"); } if (String.IsNullOrWhiteSpace(exportOptions.ToFile) && exportOptions.ToStream == null) { throw new ArgumentException("ToFile or ToStream property in options must be non-null"); } var result = new CounterOperationState(); var exportFolder = String.Empty; if (Options.Incremental) { ShowProgress("Starting incremental export.."); exportFolder = CalculateExportFile(exportOptions, exportFolder); } else { ShowProgress("Starting full export..."); } SmugglerException lastException = null; var ownedStream = exportOptions.ToStream == null; var stream = exportOptions.ToStream ?? File.Create(exportOptions.ToFile); if (ownedStream) { ShowProgress("Export to dump file " + exportOptions.ToFile); } try { using (var counterStore = new CounterStore { Url = exportOptions.From.Url, Name = exportOptions.From.CounterStoreId, Credentials = new OperationCredentials(exportOptions.From.ApiKey, exportOptions.From.Credentials) }) using (var gZipStream = new GZipStream(stream, CompressionMode.Compress, leaveOpen: true)) using (var streamWriter = new StreamWriter(gZipStream)) { counterStore.Initialize(); var jsonWriter = new JsonTextWriter(streamWriter) { Formatting = Formatting.Indented }; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName(Options.Incremental ? "CountersDeltas" : "CounterSnapshots"); //also for human readability jsonWriter.WriteStartArray(); try { if (Options.Incremental) { await ExportIncrementalData(counterStore, exportFolder, jsonWriter).WithCancellation(CancellationToken).ConfigureAwait(false); } else { await ExportFullData(counterStore, jsonWriter).WithCancellation(CancellationToken).ConfigureAwait(false); } } catch (SmugglerException e) { Debug.Assert(e.Data.Keys.Cast <string>().Contains("LastEtag")); result.LastWrittenEtag = (long)e.Data["LastEtag"]; lastException = e; var operation = Options.Incremental ? "Incremental" : "Full"; ShowProgress($"{operation} Export failed. {e}"); } jsonWriter.WriteEndArray(); jsonWriter.WriteEndObject(); streamWriter.Flush(); } if (lastException != null) { throw lastException; } return(result); } finally { if (ownedStream && stream != null) { stream.Flush(); stream.Dispose(); ShowProgress("Finished export and closed file..."); } else { ShowProgress("Finished export..."); } } }
public virtual void OnException(SmugglerException exception) { }
public void OnException(SmugglerException exception) { exception.File = path; }
public override void OnException(SmugglerException exception) { exception.File = _outputFilePath; base.OnException(exception); }