Skip to content

Instantly share code, notes, and snippets.

@workmaster2n
Forked from anonymous/form1.cs
Created December 23, 2013 17:48
Show Gist options
  • Save workmaster2n/8101506 to your computer and use it in GitHub Desktop.
Save workmaster2n/8101506 to your computer and use it in GitHub Desktop.
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 event FormClosingEventHandler FormClosing;
public Form1()
{
InitializeComponent();
}
private void my_FormClosing(Object sender, FormClosingEventArgs args){
channel.Close();
connection.Close();
}
private void Form1_Shown(object sender, EventArgs e)
{
FormClosing += my_FormClosing;
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