93 lines
3.0 KiB
C#
93 lines
3.0 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 log4net;
|
|
|
|
namespace bsmd.hisnord
|
|
{
|
|
public class transmitter
|
|
{
|
|
private static ILog _log = LogManager.GetLogger(typeof(transmitter));
|
|
|
|
|
|
|
|
public static result UseHisNordTransmitter(string filenameFullPath)
|
|
{
|
|
Process process = new Process();
|
|
process.StartInfo.FileName = Properties.Settings.Default.Transmitter;
|
|
process.StartInfo.RedirectStandardError = true;
|
|
process.StartInfo.RedirectStandardOutput = true;
|
|
process.StartInfo.RedirectStandardInput = 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);
|
|
|
|
_log.Error(process.StandardError.ReadToEnd());
|
|
process.WaitForExit();
|
|
|
|
_log.Info(process.StandardOutput.ReadToEnd());
|
|
process.WaitForExit();
|
|
|
|
// now we should read the response message...
|
|
string resultFilename = string.Format("{0}.result.xml", Path.GetFileName(filenameFullPath));
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|