Esempio n. 1
0
        public DriverBase()
        {
            // Set up logging - will participate in the standard toolkit log
            log = log4net.LogManager.GetLogger("KaiTrade");

            wireLog = log4net.LogManager.GetLogger("KaiTradeWireLog");
            driverLog = log4net.LogManager.GetLogger("KaiDriverLog");

            _state = new DriverState();
            _facade = AppFacade.Instance();

            _clOrdIDOrderMap = new Dictionary<string, OrderContext>();
            _apiIDOrderMap = new Dictionary<string, OrderContext>();
            _pXContexts = new Dictionary<string, PXUpdateContext>();

            _clients = new List<KaiTrade.Interfaces.IClient>();
            _publisherRegister = new Dictionary<string, KaiTrade.Interfaces.IPublisher>();
            _productGenericNameRegister = new Dictionary<string, string>();
            _productRegister = new Dictionary<string, KaiTrade.Interfaces.IProduct>();
            _externalProduct = new Dictionary<string, object>();
            _sessions = new Dictionary<string, IDriverSession>();
            _priceAgregators = new Dictionary<string, List<IPriceAgregator>>();
            _identity = System.Guid.NewGuid().ToString();

            // setup the components info - used on status messages
            SetComponentInfo(out _module, this, this.m_ID, "DriverManager", 0, "");

            // creat a last status object - used to report status when requested
            _lastStatus = new K2DataObjects.Message();

            _lastStatus.Label = "Status";
            _lastStatus.Data = "Loaded";
            _lastStatus.AppState = (int)KaiTrade.Interfaces.Status.loaded;
            _activeContextMap = new Dictionary<string, OrderContext>();
            _runningState = new DriverStatus();


            log.Info("MainMessageHandler Created");

            pxUpdates = new BlockingCollection<KaiTrade.Interfaces.IPXUpdate>();
            _pxUpdateProcessor = new PxUpdateProcessor(this, pxUpdates);
            _pXUpdateThread = new Thread(_pxUpdateProcessor.ThreadRun);
            _pXUpdateThread.Start();

            replaceRequests = new BlockingCollection<RequestData>();
            _replaceProcessor = new OrderReplaceProcessor(this, replaceRequests);
            _replaceUpdateThread = new Thread(_replaceProcessor.ThreadRun);
            _replaceUpdateThread.Start();

            //private BlockingCollection<List<KaiTrade.Interfaces.IDOMSlot>> slotUpdates;
            inboundMessages = new BlockingCollection<KaiTrade.Interfaces.IMessage>();      
            _inboundProcessor = new MessageProcessorThread(this, inboundMessages);
            _inboundProcessorThread = new Thread(_inboundProcessor.ThreadRun);
            _inboundProcessorThread.Start();

            outboundMessages = new BlockingCollection<KaiTrade.Interfaces.IMessage>();
            _outboundProcessor = new MessageProcessorThread(ref _clients, outboundMessages);
            _outboundProcessorThread = new Thread(_outboundProcessor.ThreadRun);
            _outboundProcessorThread.Start();

        }
Esempio n. 2
0
 void IStateContext.SetState(IState state)
 {
     CurrentState = (IDriverState)state;
     StateChanged?.Invoke(this, CurrentState);
 }
Esempio n. 3
0
        public void Start(string myState)
        {
            try
            {
                _startState = myState;
                // set this as a publisher
                //Factory.Instance().GetPublisherManager().Add(this);
               
                //set the  default location of the config path

                _configPath = Directory.GetCurrentDirectory() + @"\config\";
                try
                {
                    // load the driver state
                    if (myState.Length > 0)
                    {
                        _state = JsonConvert.DeserializeObject<DriverState>(myState);
                        _configPath = _state.ConfigPath;
                        _useAsyncPriceUpdates = _state.AsyncPrices;
                        _queueReplaceRequests = _state.QueueReplaceRequests;
                        
                    }
                }
                catch (Exception myE)
                {
                    log.Error("Driver.Start:cannot read state", myE);
                }
                if (this.UseWatchDogStart)
                {
                    /// the watch dog issues the start req
                    StartWD();
                }
                else
                {
                    DoStart(_startState);
                }
                

            }
            catch (Exception myE)
            {
                log.Error("Driver.Start", myE);
            }

        }