// // Class: transmitter // Current CLR: 4.0.30319.34209 // System: Microsoft Visual Studio 10.0 // Author: dani // Created: 7/14/2015 7:39:29 AM // // Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text; using System.Xml; using System.Xml.Serialization; using bsmd.database; using log4net; namespace bsmd.hisnord { public class transmitter { private static ILog _log = LogManager.GetLogger(typeof(transmitter)); public static void CallTransmitter(bool useTest) { Process process = new Process(); process.StartInfo.FileName = Properties.Settings.Default.Transmitter; process.StartInfo.WorkingDirectory = Path.GetDirectoryName(useTest ? Properties.Settings.Default.TestTransmitterRoot : Properties.Settings.Default.LiveTransmitterRoot); process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = false; process.StartInfo.UseShellExecute = false; // der Transmitter schickt alles was im Ausgabe-Verzeichnis ist // damit das gut geht schicken wir die Nachrichten einzeln und arbeiten jeweils das // Ergebnis ab process.Start(); int timeout = Properties.Settings.Default.BatchTimeoutMins * 1000 * 60; // convert to ms process.WaitForExit((timeout == 0) ? int.MaxValue : timeout); string errorString = process.StandardError.ReadToEnd(); if(!errorString.IsNullOrEmpty()) _log.ErrorFormat("HIS-Nord transmitter error: {0}", errorString); // process.WaitForExit(); string outputString = process.StandardOutput.ReadToEnd(); if(!outputString.IsNullOrEmpty()) _log.DebugFormat("HIS-Nord transmitter: {0}", outputString); // process.WaitForExit(); } public static result GetResult(string filenameFullPath, bool useTest) { // now we should read the response message... string resultFilename = string.Format("{0}.result.xml", Path.GetFileName(filenameFullPath)); string resultDir = Path.Combine(useTest ? Properties.Settings.Default.TestTransmitterRoot : Properties.Settings.Default.LiveTransmitterRoot, Properties.Settings.Default.ResultDir); string resultFullPath = Path.Combine(resultDir, resultFilename); return result.ReadResult(resultFullPath); } /// /// class to read transmitter result xml files /// [Serializable] public class result { public result() { } public int code { get; set; } public string message { get; set; } public string detail { get; set; } /// /// create result items from file /// public static result ReadResult(string filename) { result aResult = null; try { XmlSerializer serializer = new XmlSerializer(typeof(result)); using (FileStream fs = new FileStream(filename, FileMode.Open)) { aResult = (result)serializer.Deserialize(fs); } } catch (Exception ex) { _log.ErrorFormat("Exception deserializing transmitter result: {0}", ex.Message); } return aResult; } } } }