public void Run() { try { if (_NoArgs) { Help(); } else if (_BadArgs) { Error(); Help(); } else { if (_InType != null) { converter.waitForLoadingAllPlugins(); } IECGReader reader = _InType == null ? new UnknownECGReader() : converter.getReader(_InType); if (reader == null) { Console.Error.WriteLine("Error: no reader provided by input type!"); return; } ECGConfig config1 = ECGConverter.Instance.getConfig(_InType); if (config1 != null) { for (int i = 0; i < _Config.Count; i++) { config1[(string)_Config.GetKey(i)] = (string)_Config.GetByIndex(i); } } IECGFormat src = reader.Read(_InFile, _InFileOffset, config1); if (src == null || !src.Works()) { Console.Error.WriteLine("Error: {0}", reader.getErrorMessage()); return; } if ((_BufferedSecondsToLoad > 0) || (_BufferedOffsetToLoad > 0)) { ECGConversion.ECGSignals.Signals sigs = null; if ((src.Signals.getSignals(out sigs) == 0) && sigs.IsBuffered) { ECGConversion.ECGSignals.BufferedSignals bs = (ECGConversion.ECGSignals.BufferedSignals)sigs; int start = 0, end = 0; start = bs.RealRhythmStart + (_BufferedOffsetToLoad * bs.RhythmSamplesPerSecond); end = (_BufferedSecondsToLoad == int.MaxValue) ? _BufferedSecondsToLoad : start + (_BufferedSecondsToLoad * bs.RhythmSamplesPerSecond); if (start > bs.RealRhythmEnd) { start = bs.RealRhythmEnd; } if (end > bs.RealRhythmEnd) { end = bs.RealRhythmEnd; } if (start < end) { bs.LoadSignal(start, end); src.Signals.setSignals(bs); } } } IECGManagementSystem manSys = _OutFile == null ? null : converter.getECGManagementSystem(_OutType); config1 = ECGConverter.Instance.getConfig(manSys == null ? _OutType : manSys.FormatName); ECGConfig config2 = manSys == null ? null : manSys.Config; for (int i = 0; i < _Config.Count; i++) { if (config1 != null) { config1[(string)_Config.GetKey(i)] = (string)_Config.GetByIndex(i); } if (config2 != null) { config2[(string)_Config.GetKey(i)] = (string)_Config.GetByIndex(i); } } if ((config1 != null) && !config1.ConfigurationWorks()) { Console.Error.WriteLine("Error: Bad Configuration for ECG Format!"); return; } if ((config2 != null) && !config2.ConfigurationWorks()) { Console.Error.WriteLine("Error: Bad Configuration for ECG Management System!"); return; } if (manSys == null) { IECGFormat dst = src.GetType() == ECGConverter.Instance.getType(_OutType) ? src : null; if (dst == null) { if ((src.Demographics != null) && (src.Demographics.PatientID == null)) { src.Demographics.PatientID = _PatientId; } ECGConverter.Instance.Convert(src, _OutType, config1, out dst); } if ((dst == null) || !dst.Works()) { Console.Error.WriteLine("Error: Conversion Failed!"); return; } if (_Anonymize) { dst.Anonymous(); } if ((_PatientId != null) && (dst.Demographics != null)) { dst.Demographics.PatientID = _PatientId; } ECGWriter.Write(dst, _OutFile, true); if (ECGWriter.getLastError() != 0) { Console.Error.WriteLine("Error: {0}", ECGWriter.getLastErrorMessage()); } } else { if (manSys.ConfiguredToSave()) { if (_Anonymize) { src.Anonymous(); } manSys.SaveECG(src, _PatientId, config1); } else { Console.Error.WriteLine("Error: Not configured to store!"); } } } } catch (Exception ex) { Console.Error.WriteLine("Error: {0}", ex.ToString()); } }
public void Run() { try { if (!converter.waitForFormatSupport("PDF")) { Console.Error.WriteLine("Error: PDF plug-in is not available!"); return; } if (_NoArgs) { Help(); } else if (_BadArgs) { Error(); Help(); } else { UnknownECGReader reader = new UnknownECGReader(); IECGFormat src = reader.Read(_InFile, _InFileOffset); if ((src == null) || !src.Works()) { Console.Error.WriteLine("Error: {0}", reader.getErrorMessage()); return; } ECGConfig config = converter.getConfig("PDF"); for (int i = 0; i < _Config.Count; i++) { if (config != null) { config[(string)_Config.GetKey(i)] = (string)_Config.GetByIndex(i); } } if ((config != null) && !config.ConfigurationWorks()) { Console.Error.WriteLine("Error: Bad Configuration for ECG Format!"); return; } IECGFormat dst = null; converter.Convert(src, "PDF", config, out dst); if ((dst == null) || !dst.Works()) { Console.Error.WriteLine("Error: Creating PDF failed!"); return; } if (_Anonymize) { dst.Anonymous(); } if ((_PatientId != null) && (dst.Demographics != null)) { dst.Demographics.PatientID = _PatientId; } string outfile = Path.GetTempFileName(); ECGWriter.Write(dst, outfile, true); if (ECGWriter.getLastError() != 0) { Console.Error.WriteLine("Error: {0}", ECGWriter.getLastErrorMessage()); return; } if (!PrintPdf(outfile, _Silence)) { Console.Error.WriteLine("Error: Using acrobat to print failed!"); return; } try { File.Delete(outfile); } catch { } } } catch (Exception ex) { Console.Error.WriteLine("Error: {0}", ex.ToString()); } }