Пример #1
0
        //protected override System.Web.Http.Dependencies.IDependencyResolver BuildWebApiDependencyResolver()
        //{
        //    //get the 'default' resolver, populated from the 'main' config metadata
        //    var resolver = base.BuildWebApiDependencyResolver();

        //    //check if its castable to a SpringWebApiDependencyResolver
        //    var springResolver = resolver as SpringWebApiDependencyResolver;

        //    //return the fully-configured resolver
        //    return springResolver;
        //}

        /// <summary>
        /// Method for initializaing the single threaded application parts
        /// </summary>
        private void InitiliazeApplication()
        {
            InputDisruptorPublisher.Shutdown();
            OutputDisruptor.ShutDown();
            IEventStore inputEventStore = new RavenNEventStore(Constants.INPUT_EVENT_STORE);
            IEventStore outputEventStore = new RavenNEventStore(Constants.OUTPUT_EVENT_STORE);
            Journaler inputJournaler = new Journaler(inputEventStore);
            Journaler outputJournaler = new Journaler(outputEventStore);
            ExchangeEssentialsList exchangeEssentialsList=outputEventStore.LoadLastSnapshot();
            ICurrencyPairRepository currencyPairRepository = (ICurrencyPairRepository) ContextRegistry.GetContext()["CurrencyPairRepository"];
            IList<CurrencyPair> tradeableCurrencyPairs = currencyPairRepository.GetTradeableCurrencyPairs();
            Exchange exchange;
            if (exchangeEssentialsList != null)
            {
                //means snapshot found so initialize the exchange
                exchange = new Exchange(tradeableCurrencyPairs, exchangeEssentialsList);
                InputDisruptorPublisher.InitializeDisruptor(new IEventHandler<InputPayload>[] {exchange, inputJournaler});
                OutputDisruptor.InitializeDisruptor(new IEventHandler<byte[]>[] {outputJournaler});
                exchange.InitializeExchangeAfterSnaphot();
                LimitOrderBookReplayService service = new LimitOrderBookReplayService();
                service.ReplayOrderBooks(exchange, outputJournaler);
                exchange.EnableSnaphots(Constants.SnaphsortInterval);
            }
            else
            {
                //no snapshot found
                exchange = new Exchange(tradeableCurrencyPairs);
                InputDisruptorPublisher.InitializeDisruptor(new IEventHandler<InputPayload>[] { exchange, inputJournaler });
                OutputDisruptor.InitializeDisruptor(new IEventHandler<byte[]>[] { outputJournaler });
               // check if there are events to replay
                LimitOrderBookReplayService service = new LimitOrderBookReplayService();
                service.ReplayOrderBooks(exchange, outputJournaler);
                exchange.EnableSnaphots(Constants.SnaphsortInterval);
            }
        }
 /// <summary>
 /// Save Exchange snapshot
 /// </summary>
 /// <param name="exchangeEssentials"></param>
 public void SaveSnapshot(ExchangeEssentialsList exchangeEssentials)
 {
     if (_eventStore == Constants.OUTPUT_EVENT_STORE)
     {
         try
         {
             _store.Advanced.AddSnapshot(new Snapshot(_streamId, _snaphost++,
                                                      StreamConversion.ObjectToByteArray(exchangeEssentials)));
         }
         catch (Exception exception)
         {
             if (Log.IsErrorEnabled)
             {
                 Log.Error("Snapshot Saving error:", exception);
             }
         }
     }
 }
        /// <summary>
        /// Load last snaphost
        /// </summary>
        /// <returns></returns>
        public ExchangeEssentialsList LoadLastSnapshot()
        {
            Snapshot snapshot   = null;
            var      initialize = _store.Advanced.GetFrom(Constants.LastSnapshotSearch).GroupBy(i => i.StreamId).Select(g => g.First()).ToList();

            for (int i = 0; i < initialize.Count; i++)
            {
                snapshot = _store.Advanced.GetSnapshot(initialize[i].StreamId, int.MaxValue);
            }
            _lastSnaphot = snapshot;
            if (snapshot != null)
            {
                JObject jObject = JObject.Parse(snapshot.Payload.ToString());
                byte[]  array   = jObject["$value"].ToObject <byte[]>();
                object  list    = StreamConversion.ByteArrayToObject(array);
                ExchangeEssentialsList exchangeEssentialsList = list as ExchangeEssentialsList;
                _loadFrom = exchangeEssentialsList.LastSnapshotDateTime;
                return(exchangeEssentialsList);
            }
            return(null);
        }
Пример #4
0
 void SnapshotArrived(ExchangeEssentialsList exchangeEssentials)
 {
     _eventStore.SaveSnapshot(exchangeEssentials);
 }