상속: System.Windows.Forms.Form
예제 #1
0
        public Recorder(RecorderView view)
        {
            this.view = view;
            view.recorder = this;

            /////////// Setup logger ///////////
            logger = NLog.LogManager.GetCurrentClassLogger();
            loggerWCF = NLog.LogManager.GetLogger("Capture.Recorder.WCF");

            /////////// Setup WCF notification to a BriefMaker ///////////
            briefMakerClient = new BriefMakerServiceReference.BriefMakerClient();

            /////////// Download Symbols ///////////
            try
            {
                logger.Debug("Downloading symbols");
                var dbSymbols = from s in dc.Symbols select s;

                foreach (var s in dbSymbols)
                {
                    if (String.IsNullOrWhiteSpace(s.Name))
                    {
                        logger.Error("SymbolID:" + s.SymbolID + " does not have a name(symbol). Item will be skipped.");
                        continue;
                    }
                    if (s.SymbolID > 255 || s.SymbolID < 0)
                    {
                        logger.Error("SymbolID:" + s.SymbolID + " range is not valid. Supported(0-255). Item will be skipped.");
                        continue;
                    }

                    SecurityType secType = s.Type.Trim() == "STK" ? SecurityType.Stock : SecurityType.Index;
                    string market = s.Market.Trim();

                    var new_symb = new MarketSymbol()
                    {
                        SymbolID = s.SymbolID,
                        Symbol = s.Name.Trim(),
                        securityType = s.Type.Trim() == "STK" ? SecurityType.Stock : SecurityType.Index,
                        Market = s.Market
                    };
                    symbols.Add(new_symb);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Database Exception: " + ex.Message);
                logger.Error("Make sure that the connection string is set correctly in app.config.");
                Thread.Sleep(5000);
                ShutdownRecorder();
            }


            // Setup BinaryWriters
            logger.Debug("Downloading symbols");
            capturingWriter = new BinaryWriter(new MemoryStream(MemoryStreamReserveSpace));
            capturingWriter.Write((long)0);  // leave some space at the beginning for time later
            manufacturedWriterForFuture = new BinaryWriter(new MemoryStream(MemoryStreamReserveSpace));
            manufacturedWriterForFuture.Write((long)0);  // leave some space at the beginning for time later

            // Run this thread will a little higher priority since it is dealing with real-time information.
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
            // Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;

            view.timer.Tick += new EventHandler(timer1Sec_Tick);


            while (true)
            {
                TimeSpan timespan = new TimeSpan(DateTime.Now.Ticks - lastRecievedUpdate.Ticks);
                if (timespan.Seconds > 30)
                {
                    logger.Info("No Data received in over 30 seconds. Requesting Reconnect...");
                    lastRecievedUpdate = DateTime.Now;
                    ConnectToIB();
                }

                if (terminateRequested || (DateTime.Now.TimeOfDay > settings.ShutDownTime))
                {
                    logger.Info("Close requested or automatic end of day shutdown.");
                    ShutdownRecorder();
                    break;
                }

                view.BeginInvoke((MethodInvoker)delegate
                {
                    view.toolStripStatusLabelEventCt.Text = totalCaptureEventsForDisplay.ToString() + " (" + (totalCaptureEventsForDisplay - lastTotalCaptureEventsForDisplay).ToString() + "/sec)";  // runs on UI thread 
                    lastTotalCaptureEventsForDisplay = totalCaptureEventsForDisplay;
                    view.toolStripStatusLabelLastBrfID.Text = lastUpdateTime.ToString();
                });  // runs on UI thread 

                Thread.Sleep(1000);
            }
        }
예제 #2
0
        public Recorder(RecorderView view)
        {
            this.view     = view;
            view.recorder = this;

            /////////// Setup logger ///////////
            logger    = NLog.LogManager.GetCurrentClassLogger();
            loggerWCF = NLog.LogManager.GetLogger("Capture.Recorder.WCF");

            /////////// Setup WCF notification to a BriefMaker ///////////
            briefMakerClient = new BriefMakerServiceReference.BriefMakerClient();

            /////////// Download Symbols ///////////
            logger.Debug("Downloading symbols");
            var dbSymbols = from s in dc.Symbols select s;

            foreach (var s in dbSymbols)
            {
                if (String.IsNullOrWhiteSpace(s.Name))
                {
                    logger.Error("SymbolID:" + s.SymbolID + " does not have a name(symbol). Item will be skipped.");
                    continue;
                }
                if (s.SymbolID > 255 || s.SymbolID < 0)
                {
                    logger.Error("SymbolID:" + s.SymbolID + " range is not valid. Supported(0-255). Item will be skipped.");
                    continue;
                }

                SecurityType secType = s.Type.Trim() == "STK" ? SecurityType.Stock : SecurityType.Index;
                string       market  = s.Market.Trim();

                var new_symb = new MarketSymbol()
                {
                    SymbolID     = s.SymbolID,
                    Symbol       = s.Name.Trim(),
                    securityType = s.Type.Trim() == "STK" ? SecurityType.Stock : SecurityType.Index,
                    Market       = s.Market
                };
                symbols.Add(new_symb);
            }


            // Setup BinaryWriters
            logger.Debug("Downloading symbols");
            capturingWriter = new BinaryWriter(new MemoryStream(MemoryStreamReserveSpace));
            capturingWriter.Write((long)0);             // leave some space at the beginning for time later
            manufacturedWriterForFuture = new BinaryWriter(new MemoryStream(MemoryStreamReserveSpace));
            manufacturedWriterForFuture.Write((long)0); // leave some space at the beginning for time later

            // Run this thread will a little higher priority since it is dealing with real-time information.
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
            // Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;

            view.timer.Tick += new EventHandler(timer1Sec_Tick);


            while (true)
            {
                TimeSpan timespan = new TimeSpan(DateTime.Now.Ticks - lastRecievedUpdate.Ticks);
                if (timespan.Seconds > 30)
                {
                    logger.Info("No Data received in over 30 seconds. Requesting Reconnect...");
                    lastRecievedUpdate = DateTime.Now;
                    ConnectToIB();
                }

                if (terminateRequested || (DateTime.Now.TimeOfDay > settings.ShutDownTime))
                {
                    logger.Info("Close requested or automatic end of day shutdown.");
                    ShutdownRecorder();
                    break;
                }

                view.BeginInvoke((MethodInvoker) delegate
                {
                    view.toolStripStatusLabelEventCt.Text   = totalCaptureEventsForDisplay.ToString() + " (" + (totalCaptureEventsForDisplay - lastTotalCaptureEventsForDisplay).ToString() + "/sec)"; // runs on UI thread
                    lastTotalCaptureEventsForDisplay        = totalCaptureEventsForDisplay;
                    view.toolStripStatusLabelLastBrfID.Text = lastUpdateTime.ToString();
                });  // runs on UI thread

                Thread.Sleep(1000);
            }
        }