- Codeproject.EventBroker.zip
- Codeproject.EventBroker
- Codeproject.EventBroker.Common
- Codeproject.EventBroker.Contracts
- Codeproject.EventBroker.Host
- Codeproject.EventBroker.Service
- Codeproject.EventBroker.sln
- Codeproject.EventBroker.suo
- Codeproject.EventBroker.TestMessagePublisher
- Codeproject.EventBroker.WebUI
- Lib
- Apache
- log4net
- 1.2.10.0
- Castle
- 1.2.0.6623
- Castle.Components.Binder.dll
- Castle.Components.Validator.dll
- Castle.Core.dll
- Castle.DynamicProxy2.dll
- Castle.MicroKernel.dll
- Castle.Windsor.dll
- Microsoft
- SignalR
- SignalR.dll
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Messaging;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Threading.Tasks;
using Message = System.Windows.Forms.Message;
namespace Codeproject.EventBroker.TestMessagePublisher
{
public partial class MainWindow : Form
{
private enum RunMode { Automatic = 1, Manual }
private RunMode CurrentRunMode = RunMode.Automatic;
private string inputQueueName = ConfigurationManager.AppSettings["eventBrokerQueueName"];
private List<string> places = new List<string>();
private List<int> waits = new List<int>();
private Random rand = new Random();
private bool listenToSelectionChanges = true;
private bool stopAuto = false;
public MainWindow()
{
InitializeComponent();
places.Add("220.233.19.142");
places.Add("64.233.160.0");
places.Add("91.135.229.5");
waits.Add(1000);
waits.Add(2000);
waits.Add(4000);
waits.Add(5000);
waits.Add(8000);
}
public void SendMessages()
{
Task.Factory.StartNew(() =>
{
while (!stopAuto)
{
SendMessage();
Thread.Sleep(10000);
}
}, TaskCreationOptions.LongRunning);
}
public string GetXmlData(string tcpIpAddress)
{
return string.Format(
"<realtimeEvent>" +
"<originatingIp>{0}</originatingIp>" +
"<eventName>ClientDealEvent</eventName>" +
"<entityIdType>ClientDeal</entityIdType>" +
"<description>Someone bought something</description>" +
"<date>{1}</date>" +
"<additionalData></additionalData>" +
"</realtimeEvent>", tcpIpAddress, DateTime.Now);
}
private void btnCreateManual_Click(object sender, EventArgs e)
{
if (radAuto.Checked)
{
SendMessages();
}
else
{
SendMessage();
}
}
private void SendMessage()
{
using (MessageQueue queue = new MessageQueue(inputQueueName, QueueAccessMode.Send))
{
queue.Formatter = new XmlMessageFormatter(new[] { typeof(string) });
try
{
System.Messaging.Message message = new System.Messaging.Message(
GetXmlData(places[rand.Next(places.Count)]));
Debug.WriteLine("Producing message {0}", message.Body.ToString());
queue.Send(message);
}
catch (MessageQueueException mex)
{
if (mex.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
{
Debug.WriteLine("Message queue exception occured", mex);
}
}
catch (Exception ex)
{
// Write the message details to the Error queue
Debug.WriteLine("Exception occured", ex);
}
}
}
private void CheckedChanged(object sender, EventArgs e)
{
if (radAuto.Checked)
{
stopAuto = false;
}
else
{
stopAuto = true;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)
- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence
Both of these at Sussex University UK.
Award(s)
I am lucky enough to have won a few awards for Zany Crazy code articles over the years
- Microsoft C# MVP 2016
- Codeproject MVP 2016
- Microsoft C# MVP 2015
- Codeproject MVP 2015
- Microsoft C# MVP 2014
- Codeproject MVP 2014
- Microsoft C# MVP 2013
- Codeproject MVP 2013
- Microsoft C# MVP 2012
- Codeproject MVP 2012
- Microsoft C# MVP 2011
- Codeproject MVP 2011
- Microsoft C# MVP 2010
- Codeproject MVP 2010
- Microsoft C# MVP 2009
- Codeproject MVP 2009
- Microsoft C# MVP 2008
- Codeproject MVP 2008
- And numerous codeproject awards which you can see over at my blog
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.