All pastes #764106 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-06 23:23 UTC
rendered paste body
using 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
    {
        public static void Main(String[] args)
        {
            Weborb.Config.ORBConfig 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 static 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());
                }
            }
        }
    }
}