Created
December 23, 2013 17:22
-
-
Save anonymous/8101041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Drawing; | |
using System.Windows.Forms; | |
using System.Runtime.Remoting; | |
using System.Runtime.Remoting.Channels; | |
using System.Runtime.Remoting.Channels.Tcp; | |
using QTrack.QT500.Demo.Core; | |
using QTrack.RemoteEvents; | |
using Npgsql; | |
using System.Data; | |
using RabbitMQ.Client; | |
using System.Text; | |
using Newtonsoft.Json; | |
namespace RemoteEventsTestHarness | |
{ | |
public partial class Form1 : Form | |
{ | |
IModel channel = null; | |
IConnection connection = null; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_FormClosing(Object sender, FormClosingEventArgs args){ | |
channel.Close(); | |
connection.Close(); | |
} | |
private void Form1_Shown(object sender, EventArgs e) | |
{ | |
using (MachineNameForm dialog = new MachineNameForm()) | |
{ | |
if (dialog.ShowDialog() == DialogResult.OK) | |
{ | |
serverURI = "tcp://" + dialog.Value + ":1551/QTrackRemoteEvents.Rem"; | |
Connect(); | |
} | |
else | |
{ | |
this.Close(); //exit program | |
} | |
} | |
} | |
private void Connect() | |
{ | |
try | |
{ | |
var factory = new ConnectionFactory() { HostName = "localhost" }; | |
connection = factory.CreateConnection(); | |
channel = connection.CreateModel(); | |
channel.QueueDeclare("hello", false, false, false, null); | |
string message = "Hello World!"; | |
var body = Encoding.UTF8.GetBytes(message); | |
channel.BasicPublish("", "hello", null, body); | |
clientProv = new BinaryClientFormatterSinkProvider(); | |
serverProv = new BinaryServerFormatterSinkProvider(); | |
serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; | |
Hashtable props = new Hashtable(); | |
props["name"] = "remotingClient"; | |
props["port"] = 0; //First available port | |
tcpChan = new TcpChannel(props, clientProv, serverProv); | |
ChannelServices.RegisterChannel(tcpChan, false); | |
RemotingConfiguration.RegisterWellKnownClientType | |
(new WellKnownClientTypeEntry(typeof(IRemoteEvents), serverURI)); | |
remoteServer = (IRemoteEvents)Activator.GetObject(typeof(IRemoteEvents), serverURI); | |
m_Text = "Connected to QTrack Standalone"; | |
//Register for remote events we are interested in | |
// Lots of delegates | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment