private BaseExporter GetExporter() { BaseExporter exporter; switch (SelectedExporter) { case TextExporter: exporter = new TextExporter(); break; default: throw new Exception("Exporter not supported: " + selectedExporter); } return(exporter); }
public async Task Run() { Console.WriteLine("EXPORT TEXT INTO TEI FILES\n"); Console.ResetColor(); Console.WriteLine( $"Database: {_database}\n" + $"Output dir: {_outputDir}\n" + $"Comments: {_comments}\n" + $"Dry: {_dry}\n" + $"Group IDs: {string.Join(", ", _groupIds)}"); ILoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddSerilog(Log.Logger); Log.Logger.Information("EXPORT TEXT INTO TEI FILES"); ICadmusRepository repository = _repositoryProvider.CreateRepository(_database); TextExporter exporter = new TextExporter(repository) { Logger = loggerFactory.CreateLogger("export"), IncludeComments = _comments, IsDryModeEnabled = _dry }; foreach (string id in _groupIds) { exporter.SelectedGroupIds.Add(id); } using (var bar = new ProgressBar(100, "Exporting...", new ProgressBarOptions { ProgressCharacter = '.', ProgressBarOnBottom = true, DisplayTimeInRealTime = false })) { await exporter.ExportAsync(_outputDir, new Progress <ProgressReport>( r => bar.Tick(r.Percent, r.Message))); } }
private IExportable CreateExporter(string extension) { IExportable exporter = null; if (extension == ".xlsx") { exporter = new ExcelExporter(); } else if (extension == ".json") { exporter = new JsonExporter(); } else if (extension == ".txt") { exporter = new TextExporter(); } return(exporter); }
static void Main(string[] args) { // import -> from Excel to DB // export from DB to Excell // Default values string path = string.Empty; TranslationType transType = TranslationType.OriginalText; ActionType importExport = ActionType.Import; if (args.Length > 0) { //(Type) Enum.Parse(typeof(Type), value); //Get excel file from args path = args[0]; transType = (TranslationType)Enum.Parse(typeof(TranslationType), args[0]); importExport = (ActionType)Enum.Parse(typeof(ActionType), args[1]); } else { path = @"C:\Users\Valdis.Logins\Desktop\eService_Original_text_translation.xlsx"; //eService_Original_text_translation.xlsx"; //Kopio eService_Original_text_translation.xlsx"; //path = @"C:\Users\Valdis.Logins\Desktop\WebElementTranslation.xlsx"; transType = TranslationType.OriginalText; importExport = ActionType.Import; } // validate file path FileInfo ff = new FileInfo(path); if (!ff.Exists) { throw new ArgumentException("File does not exist"); } switch (transType) { case TranslationType.OriginalText: switch (importExport) { case ActionType.Import: TextImporter pp = new TextImporter(); pp.ExtractFromExcel(path); break; case ActionType.Export: TextExporter exp = new TextExporter(); exp.ExtractFromDB(path); break; } break; case TranslationType.WebElement: switch (importExport) { case ActionType.Import: WebElementImporter pp2 = new WebElementImporter(); pp2.ExtractFromExcel(path); break; case ActionType.Export: WebElementExporter exp = new WebElementExporter(); exp.ExtractFromDB(path); break; } break; } Console.WriteLine("Done!:::"); Console.ReadLine(); }
protected override TimeSpan OnProcess() { if (_settings.ExportType == ExportTypes.Sql && _settings.Connection == null) { this.AddErrorLog(LocalizedStrings.Str3768); return(TimeSpan.MaxValue); } var allSecurity = this.GetAllSecurity(); var supportedDataTypes = (allSecurity == null ? Enumerable.Empty <Type>() : SupportedMarketDataTypes.Intersect(allSecurity.MarketDataTypes) ).ToArray(); this.AddInfoLog(LocalizedStrings.Str2306Params.Put(_settings.StartFrom)); Func <int, bool> isCancelled = count => !CanProcess(); var hasSecurities = false; foreach (var security in GetWorkingSecurities()) { hasSecurities = true; if (!CanProcess()) { break; } var path = _settings.ExportFolder; if (path.IsEmpty()) { path = DriveCache.Instance.DefaultDrive.Path; } foreach (var t in (allSecurity == null ? security.MarketDataTypes : supportedDataTypes)) { if (!CanProcess()) { break; } var arg = _settings.CandleSettings.Arg; var dataType = t.ToMessageType(ref arg); this.AddInfoLog(LocalizedStrings.Str3769Params.Put(security.Security.Id, dataType.Name, _settings.ExportType)); var fromStorage = StorageRegistry.GetStorage(security.Security, dataType, arg, _settings.Drive, _settings.StorageFormat); var from = fromStorage.GetFromDate(); var to = fromStorage.GetToDate(); if (from == null || to == null) { this.AddWarningLog(LocalizedStrings.Str3770); continue; } from = _settings.StartFrom.Max(from.Value); to = (DateTime.Today - TimeSpan.FromDays(_settings.Offset)).Min(to.Value); if (from > to) { continue; } BaseExporter exporter; if (_settings.ExportType == ExportTypes.Sql) { exporter = new DatabaseExporter(security.Security, arg, isCancelled, _settings.Connection) { BatchSize = _settings.BatchSize, CheckUnique = _settings.CheckUnique, }; } else { var fileName = Path.Combine(path, security.Security.GetFileName( dataType, arg, from.Value, to.Value, _settings.ExportType)); switch (_settings.ExportType) { case ExportTypes.Excel: exporter = new ExcelExporter(security.Security, arg, isCancelled, fileName, () => this.AddErrorLog(LocalizedStrings.Str3771)); break; case ExportTypes.Xml: exporter = new XmlExporter(security.Security, arg, isCancelled, fileName); break; case ExportTypes.Txt: exporter = new TextExporter(security.Security, arg, isCancelled, fileName, GetTxtTemplate(dataType, arg), _settings.Header); break; case ExportTypes.Bin: exporter = new BinExporter(security.Security, arg, isCancelled, DriveCache.Instance.GetDrive(path)); break; default: throw new ArgumentOutOfRangeException(); } } foreach (var date in from.Value.Range(to.Value, TimeSpan.FromDays(1))) { if (!CanProcess()) { break; } try { this.AddInfoLog(LocalizedStrings.Str3772Params.Put(security.Security.Id, dataType.Name, _settings.ExportType, date)); exporter.Export(dataType, fromStorage.Load(date)); } catch (Exception ex) { HandleError(ex); } } } } if (!hasSecurities) { this.AddWarningLog(LocalizedStrings.Str2292); return(TimeSpan.MaxValue); } if (CanProcess()) { this.AddInfoLog(LocalizedStrings.Str2300); _settings.StartFrom = DateTime.Today - TimeSpan.FromDays(_settings.Offset); SaveSettings(); } return(base.OnProcess()); }
protected override TimeSpan OnProcess() { if (_settings.ExportType == ExportTypes.Sql && _settings.Connection == null) { this.AddErrorLog(LocalizedStrings.Str3768); return TimeSpan.MaxValue; } var allSecurity = this.GetAllSecurity(); var supportedDataTypes = (allSecurity == null ? Enumerable.Empty<DataType>() : SupportedDataTypes.Intersect(allSecurity.DataTypes) ).ToArray(); this.AddInfoLog(LocalizedStrings.Str2306Params.Put(_settings.StartFrom)); Func<int, bool> isCancelled = count => !CanProcess(); var hasSecurities = false; foreach (var security in GetWorkingSecurities()) { hasSecurities = true; if (!CanProcess()) break; foreach (var t in (allSecurity == null ? security.DataTypes : supportedDataTypes)) { if (!CanProcess()) break; var dataType = t.MessageType; var arg = t.Arg; this.AddInfoLog(LocalizedStrings.Str3769Params.Put(security.Security.Id, dataType.Name, _settings.ExportType)); var fromStorage = StorageRegistry.GetStorage(security.Security, dataType, arg, _settings.Drive, _settings.StorageFormat); var from = fromStorage.GetFromDate(); var to = fromStorage.GetToDate(); if (from == null || to == null) { this.AddWarningLog(LocalizedStrings.Str3770); continue; } from = _settings.StartFrom.Max(from.Value); to = (DateTime.Today - TimeSpan.FromDays(_settings.Offset)).Min(to.Value); if (from > to) continue; BaseExporter exporter; if (_settings.ExportType == ExportTypes.Sql) { exporter = new DatabaseExporter(security.Security, arg, isCancelled, _settings.Connection) { BatchSize = _settings.BatchSize, CheckUnique = _settings.CheckUnique, }; } else { var path = _settings.ExportFolder; if (path.IsEmpty()) path = DriveCache.Instance.DefaultDrive.Path; var fileName = Path.Combine(path, security.Security.GetFileName( dataType, arg, from.Value, to.Value, _settings.ExportType)); switch (_settings.ExportType) { case ExportTypes.Excel: exporter = new ExcelExporter(security.Security, arg, isCancelled, fileName, () => this.AddErrorLog(LocalizedStrings.Str3771)); break; case ExportTypes.Xml: exporter = new XmlExporter(security.Security, arg, isCancelled, fileName); break; case ExportTypes.Txt: exporter = new TextExporter(security.Security, arg, isCancelled, fileName, GetTxtTemplate(dataType, arg), _settings.Header); break; case ExportTypes.Bin: exporter = new BinExporter(security.Security, arg, isCancelled, DriveCache.Instance.GetDrive(path)); break; default: throw new ArgumentOutOfRangeException(); } } foreach (var date in from.Value.Range(to.Value, TimeSpan.FromDays(1))) { if (!CanProcess()) break; try { this.AddInfoLog(LocalizedStrings.Str3772Params.Put(security.Security.Id, dataType.Name, _settings.ExportType, date)); exporter.Export(dataType, fromStorage.Load(date)); } catch (Exception ex) { HandleError(ex); } } } } if (!hasSecurities) { this.AddWarningLog(LocalizedStrings.Str2292); return TimeSpan.MaxValue; } if (CanProcess()) { this.AddInfoLog(LocalizedStrings.Str2300); _settings.StartFrom = DateTime.Today - TimeSpan.FromDays(_settings.Offset); SaveSettings(); } return base.OnProcess(); }
public void Start(Security security, Type dataType, object arg, IEnumerableEx values, object path) { if (dataType == null) { throw new ArgumentNullException("dataType"); } if (security == null && dataType != typeof(NewsMessage) && dataType != typeof(SecurityMessage)) { throw new ArgumentNullException("security"); } if (values == null) { throw new ArgumentNullException("values"); } var currProgress = 5; var valuesPerPercent = (values.Count / (100 - currProgress)).Max(1); var valuesPerCount = (valuesPerPercent / 10).Max(1); var currCount = 0; var valuesCount = 0; Func <int, bool> isCancelled = count => { var isCancelling = _worker.CancellationPending; if (!isCancelling) { valuesCount += count; if (valuesCount / valuesPerPercent > currProgress) { currProgress = valuesCount / valuesPerPercent; _worker.ReportProgress(currProgress); } if (valuesCount > currCount) { currCount = valuesCount + valuesPerCount; this.GuiAsync(() => UpdateCount(valuesCount)); } } return(isCancelling); }; string fileName; BaseExporter exporter; switch (_button.ExportType) { case ExportTypes.Excel: fileName = (string)path; exporter = new ExcelExporter(security, arg, isCancelled, fileName, () => GuiDispatcher.GlobalDispatcher.AddSyncAction(TooManyValues)); break; case ExportTypes.Xml: fileName = (string)path; exporter = new XmlExporter(security, arg, isCancelled, fileName); break; case ExportTypes.Txt: var wnd = new ExportTxtPreviewWindow { DataType = dataType, Arg = arg }; var registry = ((HydraEntityRegistry)ConfigManager.GetService <IEntityRegistry>()).Settings.TemplateTxtRegistry; if (dataType == typeof(SecurityMessage)) { wnd.TxtTemplate = registry.TemplateTxtSecurity; } else if (dataType == typeof(NewsMessage)) { wnd.TxtTemplate = registry.TemplateTxtNews; } else if (dataType.IsSubclassOf(typeof(CandleMessage))) { wnd.TxtTemplate = registry.TemplateTxtCandle; } else if (dataType == typeof(Level1ChangeMessage)) { wnd.TxtTemplate = registry.TemplateTxtLevel1; } else if (dataType == typeof(QuoteChangeMessage)) { wnd.TxtTemplate = registry.TemplateTxtDepth; } else if (dataType == typeof(ExecutionMessage)) { if (arg == null) { throw new ArgumentNullException("arg"); } switch ((ExecutionTypes)arg) { case ExecutionTypes.Tick: wnd.TxtTemplate = registry.TemplateTxtTick; break; case ExecutionTypes.Order: case ExecutionTypes.Trade: wnd.TxtTemplate = registry.TemplateTxtTransaction; break; case ExecutionTypes.OrderLog: wnd.TxtTemplate = registry.TemplateTxtOrderLog; break; default: throw new ArgumentOutOfRangeException(); } } else { throw new ArgumentOutOfRangeException("dataType", dataType, LocalizedStrings.Str721); } if (!wnd.ShowModal(this)) { return; } if (dataType == typeof(SecurityMessage)) { registry.TemplateTxtSecurity = wnd.TxtTemplate; } else if (dataType == typeof(NewsMessage)) { registry.TemplateTxtNews = wnd.TxtTemplate; } else if (dataType.IsSubclassOf(typeof(CandleMessage))) { registry.TemplateTxtCandle = wnd.TxtTemplate; } else if (dataType == typeof(Level1ChangeMessage)) { registry.TemplateTxtLevel1 = wnd.TxtTemplate; } else if (dataType == typeof(QuoteChangeMessage)) { registry.TemplateTxtDepth = wnd.TxtTemplate; } else if (dataType == typeof(ExecutionMessage)) { if (arg == null) { throw new ArgumentNullException("arg"); } switch ((ExecutionTypes)arg) { case ExecutionTypes.Tick: registry.TemplateTxtTick = wnd.TxtTemplate; break; case ExecutionTypes.Order: case ExecutionTypes.Trade: registry.TemplateTxtTransaction = wnd.TxtTemplate; break; case ExecutionTypes.OrderLog: registry.TemplateTxtOrderLog = wnd.TxtTemplate; break; default: throw new ArgumentOutOfRangeException(); } } else { throw new ArgumentOutOfRangeException("dataType", dataType, LocalizedStrings.Str721); } fileName = (string)path; exporter = new TextExporter(security, arg, isCancelled, fileName, wnd.TxtTemplate, wnd.TxtHeader); break; case ExportTypes.Sql: fileName = null; exporter = new DatabaseExporter(security, arg, isCancelled, (DatabaseConnectionPair)path) { CheckUnique = false }; break; case ExportTypes.Bin: var drive = (IMarketDataDrive)path; fileName = drive is LocalMarketDataDrive ? drive.Path : null; exporter = new BinExporter(security, arg, isCancelled, drive); break; default: throw new ArgumentOutOfRangeException(); } CreateWorker(values.Count, fileName); _worker.DoWork += (s, e) => { _worker.ReportProgress(currProgress); exporter.Export(dataType, values); _worker.ReportProgress(100); Thread.Sleep(500); _worker.ReportProgress(0); }; _worker.RunWorkerAsync(); }
public void Start(Security security, Type dataType, object arg, IEnumerableEx values, object path) { if (security == null && dataType != typeof(News) && dataType != typeof(Security)) { throw new ArgumentNullException("security"); } if (dataType == null) { throw new ArgumentNullException("dataType"); } if (values == null) { throw new ArgumentNullException("values"); } var currProgress = 5; var valuesPerPercent = (values.Count / (100 - currProgress)).Max(1); var valuesPerCount = (valuesPerPercent / 10).Max(1); var currCount = 0; var valuesCount = 0; Func <int, bool> isCancelled = count => { var isCancelling = _worker.CancellationPending; if (!isCancelling) { valuesCount += count; if (valuesCount / valuesPerPercent > currProgress) { currProgress = valuesCount / valuesPerPercent; _worker.ReportProgress(currProgress); } if (valuesCount > currCount) { currCount = valuesCount + valuesPerCount; this.GuiAsync(() => UpdateCount(valuesCount)); } } return(isCancelling); }; string fileName; BaseExporter exporter; switch (_button.ExportType) { case ExportTypes.Excel: fileName = (string)path; exporter = new ExcelExporter(security, arg, isCancelled, fileName, () => GuiDispatcher.GlobalDispatcher.AddSyncAction(TooManyValues)); break; case ExportTypes.Xml: fileName = (string)path; exporter = new XmlExporter(security, arg, isCancelled, fileName); break; case ExportTypes.Txt: fileName = (string)path; exporter = new TextExporter(security, arg, isCancelled, fileName); break; case ExportTypes.Sql: fileName = null; exporter = new DatabaseExporter(security, arg, isCancelled, (DatabaseConnectionPair)path) { CheckUnique = false }; break; case ExportTypes.Bin: var drive = (IMarketDataDrive)path; fileName = drive is LocalMarketDataDrive ? drive.Path : null; exporter = new BinExporter(security, arg, isCancelled, drive); break; default: throw new ArgumentOutOfRangeException(); } CreateWorker(values.Count, fileName); _worker.DoWork += (s, e) => { _worker.ReportProgress(currProgress); exporter.Export(dataType, values); _worker.ReportProgress(100); Thread.Sleep(500); _worker.ReportProgress(0); }; _worker.RunWorkerAsync(); }