static void Main(string[] args)
        {
            // set up multicast
            byte[]   receiveBuffer = new byte[512];
            EndPoint endPoint      = new IPEndPoint(IPAddress.Any, 0);
            Socket   mdcSocket     = CommsTools.SetUpMcastListenSocket(Convert.ToInt32(ConfigurationManager.AppSettings["receive_port"]));

            Console.WriteLine("Ticker Service Started - (Listening Using MultiCast)");

            // using the rtm system
            RtmDataGatherer rtm = new RtmDataGatherer("Ticker RTM");

            rtm.Attach(new LoggerObserver());
            rtm.Attach(new ScreenPrinterObserver());

            while (true)
            {
                int        bytesReceived = mdcSocket.ReceiveFrom(receiveBuffer, ref endPoint);
                IPEndPoint mdpEndPoint   = (IPEndPoint)endPoint;
                string     s             = Encoding.ASCII.GetString(receiveBuffer, 0, bytesReceived);

                // using the rtm system
                rtm.SetMessage(s);
                rtm.Notify();
            }
        }
Example #2
0
        private void DoNotifications()
        {
            RtmDataGatherer rtm = new RtmDataGatherer("Error Handler");

            rtm.Attach(new LoggerObserver());
            rtm.Attach(new ScreenPrinterObserver());
            rtm.Attach(new EmailerObserver());
            rtm.SetMessage(Message);
            rtm.Notify();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("OME Service Started - (Listening Using MultiCast)");

            // set up multicast receive
            byte[]   receiveBuffer = new byte[512];
            EndPoint endPoint      = new IPEndPoint(IPAddress.Any, 0);
            Socket   mdcSocket     = CommsTools.SetUpMcastListenSocket(
                Convert.ToInt32(ConfigurationManager.AppSettings["receive_port"]));

            // using the observer pattern here to log what goes on in main
            RtmDataGatherer rtm = new RtmDataGatherer("OME Receiver RTM");

            rtm.Attach(new LoggerObserver());
            rtm.Attach(new EmailerObserver());
            rtm.Attach(new ScreenPrinterObserver());

            rtm.Notify();

            // set up OME
            OME.BizDomain equityDomain = setUpEquityDomain();
            equityDomain.Start();

            // loop until we get a quit signal
            while (true)
            {
                int        bytesReceived    = mdcSocket.ReceiveFrom(receiveBuffer, ref endPoint);
                IPEndPoint mdpEndPoint      = (IPEndPoint)endPoint;
                string     inboundOrderText = Encoding.ASCII.GetString(receiveBuffer, 0, bytesReceived);

                rtm.SetMessage("Order Received : " + inboundOrderText);
                rtm.Notify();

                var array = inboundOrderText.Split(',');
                if (array[0] == "-1")
                {
                    break;
                }                                // quit signal

                try
                {
                    equityDomain.SubmitOrder("MSFT", new EquityMatchingEngine.EquityOrder(
                                                 array[0], array[1], array[2], Convert.ToDouble(array[3]),
                                                 Convert.ToInt32(array[4])));
                }
                catch (BadOrder e)
                {
                    // nothing to do here, as this order will just be skipped,
                    // and the exception will make the neccessary notifications.
                }
            }
            mdcSocket.Close();
            Console.WriteLine("received quit signal");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            string line;

            // this implementation of the observer pattern creates a real time
            // monitor, and attaches to logger,and screen printer concrete observers.
            // the emailer concrete observer is left out here.
            RtmDataGatherer rtm = new RtmDataGatherer("CSV Eater RTM");

            rtm.Attach(new LoggerObserver());
            rtm.Attach(new ScreenPrinterObserver());

            // setting up to send multicast
            Socket     mdpSocket = CommsTools.SetUpMCastSendSocket();
            IPEndPoint mcastEp   = new IPEndPoint(IPAddress.Parse("224.5.6.7"),
                                                  Convert.ToInt32(ConfigurationManager.AppSettings["send_port"]));

            Console.WriteLine("CSV Eater Service Started - (Sending Using MultiCast)");
            Thread.Sleep(3000);  // relax a moment while the receiver starts up

            // read from the csv
            var stream = File.OpenRead(
                ConfigurationManager.AppSettings["csvpath"]);
            var streamReader = new StreamReader(stream);

            while ((line = streamReader.ReadLine()) != null)
            {
                try
                {
                    // this method will throw the BadOrderInput exception if the
                    // order format doesn't match the required pattern
                    CommsTools.sendOrderDataToOME(line, mdpSocket, mcastEp);
                    rtm.SetMessage("sending: " + line);
                    rtm.Notify();
                }
                catch (BadOrderInput e)
                {
                    // simply skipping and going on to the next CSV line, the exception
                    // itself logs the error
                }

                // this just keeps the orders from all zipping by too fast to see
                Thread.Sleep(Convert.ToInt32(ConfigurationManager.AppSettings["order_send_delay"]));
            }

            // telling receiver we're all done
            CommsTools.SendMCastData("-1,-1,-1,-1,-1", mdpSocket, mcastEp);  // send quit signal
            Console.WriteLine("reached end of file, sent quit signal");
            mdpSocket.Close();
            Environment.Exit(0);
        }