Skip to content
Snippets Groups Projects
Commit 5bea7e23 authored by Risav Karna's avatar Risav Karna
Browse files

with .net libraries needed, some cleanup later

parent 5f89cae6
No related branches found
No related tags found
No related merge requests found
Showing
with 14307 additions and 0 deletions

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SallyConnect", "SallyConnect\SallyConnect.csproj", "{09398E99-4FCB-4480-AE35-ACCA9C1E5A50}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{09398E99-4FCB-4480-AE35-ACCA9C1E5A50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09398E99-4FCB-4480-AE35-ACCA9C1E5A50}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09398E99-4FCB-4480-AE35-ACCA9C1E5A50}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09398E99-4FCB-4480-AE35-ACCA9C1E5A50}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
File added
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Xml;
using System.IO;
using log4net;
using log4net.Config;
using SallySchemas;
using Apache.NMS;
using Apache.NMS.Util;
using Apache.NMS.ActiveMQ.Commands;
using SallyConnect;
namespace ConnectToSally
{
//A refers to default queue,producer, consumer. B refers to the new queue(s) in response from sally.
class DotNetSallyClient : SallyClient
{
//protected static AutoResetEvent semaphore = new AutoResetEvent(false);
//protected static string xmlQResponse = null;
protected static TimeSpan receiveTimeout = TimeSpan.FromSeconds(10);
private static readonly ILog logger = LogManager.GetLogger(typeof(DotNetSallyClient));
private bool responseQSubscribed;
public string user { get; private set; }
public string password { get; private set; }
public ISession session { get; private set; }
public IConnection connection { get; private set; }
private IMessageProducer sendToSallyProducer { get; set; }
protected void startConnection()
{
Uri connecturi = new Uri("activemq:tcp://neptune.eecs.jacobs-university.de:61616");//neptune.eecs.jacobs-university.de:61616
IConnectionFactory connectFactory = new NMSConnectionFactory(connecturi);
try
{
this.connection = connectFactory.CreateConnection(this.user, this.password);
this.session = this.connection.CreateSession();
this.connection.Start();
}
catch (TypeLoadException e)
{
Console.WriteLine(e.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public DotNetSallyClient(string user="webclient", string password="webclient")
{
this.user = user;
this.password = password;
BasicConfigurator.Configure(); //for the logger
startConnection();
if (!this.connection.IsStarted)
{
Console.WriteLine("Could not start connection..");
logger.Fatal("Could not start connection!");
}
Console.WriteLine("Started connection and registered the document. Queue A set.");
}
/// <summary>
/// Register a new document with Sally so as to start communicating details about that document.
/// </summary>
/// <param name="docName"></param>
/// <param name="interfaces"></param>
public void registerDocument(string docName, string[] interfaces)
{
SallySchemas.registerdocument reg = new registerdocument();
reg.environmentid = docName;
reg.documentqueue = "dotnet_alex_" + Guid.NewGuid().ToString();
reg.interfaces = interfaces;
string xmlMessage = Apache.NMS.Util.XmlUtil.Serialize(reg);
IDestination docQueue = SessionUtil.GetDestination(this.session, "queue://" + reg.documentqueue);
//ActiveMQQueue myQueue = new ActiveMQQueue("tes"+reg.documentqueue);
IMessageConsumer regConsumer = this.session.CreateConsumer(docQueue);
regConsumer.Listener += new MessageListener(OnDocMessage); //TODO OnDocMessage
ITextMessage regRequest = this.session.CreateTextMessage(xmlMessage);
Console.WriteLine(xmlMessage); //Now sending it to sally_register with a temp queue for the replyTo
sendReceive(SessionUtil.GetDestination(this.session, "queue://sally_register"), regRequest);
}
protected void OnDocMessage(IMessage receivedMsg) {
Console.WriteLine("Received a message on docQueue");
OnTMessage(receivedMsg);
}
/// <summary>
/// Send a message to the given destination. A temporary queue is set as a replyTo for this transaction.
/// </summary>
/// <param name="destination"></param>
/// <param name="message"></param>
public void sendReceive(IDestination destination, IMessage message) {
ITemporaryQueue tempQueue = this.session.CreateTemporaryQueue();
IMessageConsumer tempQueueConsumer = this.session.CreateConsumer(tempQueue);
tempQueueConsumer.Listener += new MessageListener(OnTMessage);
message.NMSReplyTo = tempQueue;
message.NMSCorrelationID = Guid.NewGuid().ToString();
IMessageProducer producer = this.session.CreateProducer(destination);
producer.Send(message);
//semaphore.WaitOne((int)TimeSpan.FromSeconds(10).TotalMilliseconds, true);
//Console.WriteLine("Register document request sent");
}
protected Dictionary<String, String> xmlResponseReader(XmlReader xmlReader, String xmlNode = "heartbeatrequest")
{
Dictionary<String, String> sallyResponse = new Dictionary<string, string>();
while (xmlReader.Read())
{
if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == xmlNode || xmlReader.Name == "sallyqueue"))
{
sallyResponse.Add(xmlReader.Name, xmlReader.ReadElementContentAsString());
return sallyResponse;
}
}
sallyResponse.Add("noresponse", "null");
return sallyResponse;
}
protected void registerToResponseQueue(String responseQueue)
{
logger.Info("Reached to the registration of response queue..");
string prefixedQueue = responseQueue;
IDestination responseQDestination = SessionUtil.GetDestination(this.session, prefixedQueue);
this.sendToSallyProducer = session.CreateProducer(responseQDestination);
this.responseQSubscribed = true;
//semaphore.Set();
Console.WriteLine("Ready to send messages to Sally on the response queue");
}
protected void heartBeartResponder(IMessage receivedHeartBeat)
{
Console.WriteLine("Going to respond to heartbeat request");
SallySchemas.heartbeatresponse hbResponseContent = new heartbeatresponse();
ITextMessage hbResponse = this.session.CreateTextMessage(Apache.NMS.Util.XmlUtil.Serialize(hbResponseContent));
sendReceive(receivedHeartBeat.NMSReplyTo, hbResponse);
Console.WriteLine("Responded to heartbeat request");
}
protected void OnTMessage(IMessage receivedMsg)
{
IBytesMessage msg = (IBytesMessage)receivedMsg;
//semaphore.Set();
logger.Info("Received a response on ..");
Console.WriteLine("Received a response on non-doc queue..");
if (receivedMsg == null)
{
logger.Warn("No ITextMessage...");
}
else
{
System.Byte[] content = (receivedMsg as IBytesMessage).Content;
String xmlResponse = System.Text.Encoding.Default.GetString(content);
logger.Info("Received => " + receivedMsg);
logger.Info("ByteArray => " + content);
Console.WriteLine("ByteArray => " + content);
logger.Info("Init parsing the response: " + xmlResponse);
using (XmlReader reader = XmlReader.Create(new StringReader(xmlResponse)))
{
string res;
Dictionary<String, String> sallyResponse = xmlResponseReader(reader);
if (sallyResponse.ContainsKey("sallyqueue"))
{
//register to the queue in response - even if already registered before
res = sallyResponse["sallyqueue"];
registerToResponseQueue(res);
}
else if (sallyResponse.ContainsKey("heartbeatrequest"))
{
//respond to the hb request, deserialize first(?)
Console.WriteLine("Heartbeatrequest is getting heartbeat response..");
res = sallyResponse["heartbeatrequest"];
heartBeartResponder(receivedMsg);
}
else
{
//default handler
logger.Warn("Unknown message type..");
Console.WriteLine("Unknown message type..");
}
}
}
}
/// <summary>
/// Check whether or not the client is registered to the queue returned by Sally after the client's document was registered.
/// </summary>
/// <returns>boolean</returns>
public bool isRegistered()
{
return this.responseQSubscribed;
}
/// <summary>
/// Send a message to Sally on the specific queue provided by Sally after the registration of the document.
/// </summary>
/// <param name="xmlMessage"></param>
public void sendToSally(String xmlMessage)
{
//semaphore.WaitOne((int)TimeSpan.FromSeconds(1).TotalMilliseconds, true);
if (!responseQSubscribed)
{
logger.Fatal("Register to the queue from sally's response first...");
Console.WriteLine("Register to the queue from sally's response first...");
}
else
{
this.sendToSallyProducer.Send(xmlMessage);
Console.WriteLine("Sent a message on response queue..");
}
}
//public object deserializer(string xmlString)
//{
//var serializer = new System.Xml.Serialization.XmlSerializer(typeof(SallySchemas.heartbeatrequest));
//Stream contStream = new MemoryStream(content);
//SallySchemas.heartbeatrequest hbRequest = (SallySchemas.heartbeatrequest)serializer.Deserialize(contStream);
//}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SallyConnect")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SallyConnect")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d388a928-a41e-4580-af17-8d8b57518587")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apache.NMS;
using Apache.NMS.Util;
namespace ConnectToSally
{
interface SallyClient
{
void registerDocument(String docName, String[] interfaces);
//void onMessage(IMessage message);
bool isRegistered();
//void sendToSally(IMessage message);
void sendToSally(String message);
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{09398E99-4FCB-4480-AE35-ACCA9C1E5A50}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SallyConnect</RootNamespace>
<AssemblyName>SallyConnect</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>SallyConnect.TestUnit</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Apache.NMS">
<HintPath>..\packages\Apache.NMS.1.6.0.3083\lib\net40\Apache.NMS.dll</HintPath>
</Reference>
<Reference Include="Apache.NMS.ActiveMQ">
<HintPath>..\packages\Apache.NMS.ActiveMQ.1.6.2\lib\net40\Apache.NMS.ActiveMQ.dll</HintPath>
</Reference>
<Reference Include="Apache.NMS.Stomp">
<HintPath>..\packages\Apache.NMS.Stomp.1.5.4\lib\net40\Apache.NMS.Stomp.dll</HintPath>
</Reference>
<Reference Include="commcore">
<HintPath>E:\rsvworks\sallymay14\tocommit\dist\commcore.dll</HintPath>
</Reference>
<Reference Include="commlmh">
<HintPath>E:\rsvworks\sallymay14\tocommit\dist\commlmh.dll</HintPath>
</Reference>
<Reference Include="commmhworker">
<HintPath>E:\rsvworks\sallymay14\tocommit\dist\commmhworker.dll</HintPath>
</Reference>
<Reference Include="commplanetaryclient">
<HintPath>E:\rsvworks\sallymay14\tocommit\dist\commplanetaryclient.dll</HintPath>
</Reference>
<Reference Include="commtheo">
<HintPath>E:\rsvworks\sallymay14\tocommit\dist\commtheo.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="SallyDocument.cs" />
<Compile Include="TestUnit.cs" />
<Compile Include="DotNetSallyClient.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SallyClient.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SallySchemas;
namespace SallyConnect
{
class SallyDocument
{
public string sallyQueue { get; private set; }
public bool subscribedToQueue { get; set; }
public SallyDocument(string queue)
{
this.sallyQueue = queue;
this.subscribedToQueue = false;
}
public void sendToSally()
{
}
//public string environmentID { get; private set; }
//public string[] interfaces { get; private set; }
//public SallyDocument(string environmentID, string[] interfaces) {
// this.environmentID = environmentID;
// this.interfaces = interfaces;
// this.subscribedToQueue = false;
//}
//public SallySchemas.registerdocument getCoreRegisterDocument(){
// SallySchemas.registerdocument reg = new registerdocument();
// reg.environmentid = this.environmentID;
// reg.documentqueue = "dotnet_alex_" + Guid.NewGuid().ToString();
// reg.interfaces = this.interfaces;
// return reg;
//}
}
}
using ConnectToSally;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SallyConnect
{
class TestUnit
{
static void Main(string[] args) {
String[] interfaces = new string[] { "theo" };
String docName = "random_edit_1114717882592231.sdaf";
DotNetSallyClient sallyClient = new DotNetSallyClient();
sallyClient.registerDocument(docName, interfaces);
System.Threading.Thread.Sleep(1000);
if (sallyClient.isRegistered()){
sallyClient.sendToSally("some message");
}
Console.Read();
}
}
}
File added
File added
This diff is collapsed.
File added
File added
This diff is collapsed.
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment