rendered paste bodyusing System;
using System.Collections.Generic;
using System.Text;
using System.Messaging;
using Weborb.Util.Logging;
using Weborb.Data.Management;
using com.intellifinance.domain;
namespace iConsumer
{
public class Consumer
{
private Weborb.Config.ORBConfig orbConfigInstance;
public void Main(String[] args)
{
orbConfigInstance = new Weborb.Config.ORBConfig();
Consumer oCon = new Consumer();
oCon.subscribe();
System.Console.ReadLine();
}
public void subscribe()
{
Log.log(LoggingConstants.INFO, "starting subscriber");
MessageQueue.EnableConnectionCache = false;
MessageQueue queue = null;
String queuePath = @".\private$\IFNewsQueue";
if (!MessageQueue.Exists(queuePath))
Console.Write("no queue found");
else
{
queue = new MessageQueue(queuePath);
queue.Formatter = new BinaryMessageFormatter();
//queue.MessageReadPropertyFilter.SetAll();
queue.ReceiveCompleted += new ReceiveCompletedEventHandler(queue_ReceiveCompleted);
IAsyncResult queueResult = queue.BeginReceive();
}
}
public void queue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
{
Weborb.Util.ThreadContext.setConfig(orbConfigInstance);
MessageQueue msgQueue = (MessageQueue)sender;
Log.log(LoggingConstants.INFO, "QUEUE RECEIVECOMPLETED");
Intelli_FinanceDb oDb = new Intelli_FinanceDb();
//synchro is for WDMF
using (SynchronizationScope scope = new SynchronizationScope(oDb))
{
try
{
System.Messaging.Message msg = msgQueue.EndReceive(e.AsyncResult);
Text oText = (Text)msg.Body;
TextDataMapper oTextDataMapper = new TextDataMapper(oDb);
oTextDataMapper.create(oText);
if(oText.relatedTopicText != null)
Log.log(LoggingConstants.INFO, "TEXTOBJECT: " + oText.ToString() + "\n" + oText.relatedTopicText.ToString());
scope.Invoke();
IAsyncResult asyncResult = msgQueue.BeginReceive();
}
catch (Exception error)
{
Log.log(LoggingConstants.ERROR, error.ToString());
System.Console.WriteLine(error.ToString());
}
}
}
}
}