OpenTTCN/Knowledge base/Creating NETCONF Over SOAP XML Codec/Program.cs
From OpenTTCN
Home | Developer's corner | Knowledge base | Working documents | Documentation | OpenTTCN IDE | Tutorials | Training | How do I | Frequently asked questions | Technical support |
Program.cs
using System;
using OpenTTCN.Sdk;
using Etsi.Ttcn3.Tci;
using Etsi.Ttcn3.Tri;
namespace soap_codec_adapter
{
class CD_impl : ITciCDProvided
{
private ICodecComponent _xmlDelegate;
public CD_impl()
{
_xmlDelegate = StartHereCD.GetCodecComponent("http://www.openttcn.com/Codecs/2011/XML");
_xmlDelegate.SetProperty("ENABLE-XML-DECLARATION", true);
}
public ITriMessage Encode(ITciValue value)
{
// Invoke XML encoder:
ITriMessage m = _xmlDelegate.Encode(value);
byte[] utf8 = m.EncodedMessage;
OutputHandler.WriteLine("=== Encoded XML ===\n" +
(new System.Text.UTF8Encoding()).GetString(utf8),
OutputHandler.TRACE_LEVEL_DEBUG);
return m;
}
public ITciValue Decode(ITriMessage message, ITciType decodingHypothesis)
{
// Indication that XML decoder is applicable:
return _xmlDelegate.Decode(message, null);
}
}
class Program
{
public static string SessionName { get; set; }
static void Main(string[] args)
{
string sessionName = "netconf";
if (args.Length > 0) sessionName = args[0];
SessionName = sessionName;
Console.WriteLine("Session is " + sessionName);
try
{
StartHere.Initialize();
OutputHandler.MinTraceLevel = OutputHandler.TRACE_LEVEL_DEBUG;
StartHereCD.RegisterCodecImpl(new CD_impl());
StartHereCD.RegisterAsStandaloneCodec(sessionName);
StartHere.SelectSession(sessionName);
Console.WriteLine("Running as a standalone codec.");
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
catch (SdkException e)
{
Console.WriteLine("ERROR: " + e.Message);
Console.WriteLine("Error detail: " + e.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
