git_bsmd/nsw/Source/bsmd.hisnord/transmitter.cs

100 lines
3.6 KiB
C#

//
// 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()
{
Process process = new Process();
process.StartInfo.FileName = Properties.Settings.Default.Transmitter;
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(Properties.Settings.Default.Transmitter);
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)
{
// now we should read the response message...
string resultFilename = string.Format("{0}.result", Path.GetFileName(filenameFullPath)); // hier war früher noch ein .xml dran am Ende
string resultFullPath = Path.Combine(Properties.Settings.Default.ResultDir, resultFilename);
return result.ReadResult(resultFullPath);
}
/// <summary>
/// class to read transmitter result xml files
/// </summary>
[Serializable]
public class result
{
public result() { }
public int code { get; set; }
public string message { get; set; }
public string detail { get; set; }
/// <summary>
/// create result items from file
/// </summary>
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;
}
}
}
}