Пример #1
0
 protected void SubscribeForEvents(DataEventBroker broker)
 {
     if (broker != null)
     {
         broker.Subscribe(new Func <EventArgs, bool>(IsMatchRowUpdating), new EventHandler <RowUpdatingEventArgs>(RowUpdatingHandler));
         broker.Subscribe(new Func <EventArgs, bool>(IsMatchRowUpdated), new EventHandler <RowUpdatedEventArgs>(RowUpdatedHandler));
     }
 }
Пример #2
0
        public SQLiteStorageContext(Func <DataRowDalcMapper, IObjectContainerStorage, IDataSchemaStorage> getSchemaStorage)
        {
            dbFileName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".db");
            var connStr           = String.Format("Data Source={0};FailIfMissing=false;Pooling=False;", dbFileName);
            var sqliteDalcFactory = new SQLiteDalcFactory();

            Connection = sqliteDalcFactory.CreateConnection();
            Connection.ConnectionString = connStr;
            InternalDalc = new DbDalc(sqliteDalcFactory, Connection, new [] {
                new DbDalcView("objects_view", @"
					SELECT @SqlFields
					FROM objects
					@Joins
					@SqlWhere[where {0}]
					@SqlOrderBy[order by {0}]
				"                )
                {
                    FieldMapping = new Dictionary <string, string>()
                    {
                        { "id", "objects.id" },
                        { "compact_class_id", "objects.compact_class_id" }
                    }
                },

                new DbDalcView("object_relations_view", @"
					SELECT @SqlFields
					FROM object_relations r
					LEFT JOIN objects subj ON (subj.id=subject_id)
					LEFT JOIN objects obj ON (obj.id=object_id)
					@SqlWhere[where {0}]
					@SqlOrderBy[order by {0}]					
				"                ,
                               "subject_id,predicate_class_compact_id,object_id,subj.compact_class_id as subject_compact_class_id,obj.compact_class_id as object_compact_class_id",
                               "count(r.id)")
            });
            var dbEventsBroker = new DataEventBroker(InternalDalc);
            var sqlTraceLogger = new NI.Data.Triggers.SqlCommandTraceTrigger(dbEventsBroker);

            InitDbSchema();

            StorageDbMgr = new DataRowDalcMapper(InternalDalc, new StorageDataSetPrv(CreateStorageSchemaDS()).GetDataSet);

            var objStorage = new ObjectContainerSqlDalcStorage(StorageDbMgr, InternalDalc, () => { return(DataSchemaStorage.GetSchema()); });

            objStorage.DeriveTypeMapping = new Dictionary <string, string>()
            {
                { "getDateYear", "CAST(strftime('%Y', {0}) as integer)" }
            };
            DataSchemaStorage = getSchemaStorage(StorageDbMgr, objStorage);

            objStorage.ObjectViewName         = "objects_view";
            objStorage.ObjectRelationViewName = "object_relations_view";
            ObjectContainerStorage            = objStorage;

            StorageDalc = new StorageDalc(InternalDalc, ObjectContainerStorage, DataSchemaStorage.GetSchema);
        }
Пример #3
0
 public void InitTickBroker()
 {
     _logger.Debug("[Quote.InitTickBroker()] {symbol}", QuoteInfo.Symbol);
     DataBroker = new DataEventBroker <Tick>();
     DataBroker
     .WindowByTimestamp(x => x.LocalTime.ToDateTime().Ticks, OHLCInterval)
     .SelectMany(window => window.Aggregate(new OHLC(),
                                            (state, tick) => Accumulate(state, tick)))
     .Subscribe(async ohlc => await Publish(ohlc));
 }
Пример #4
0
        public HealthAction(IFCMAPIConnection apiConnection, ILogger logger, DataEventBroker <ConnectionStatusEvent> connStatusBroker)
        {
            _connStatusBroker = connStatusBroker;
            _conn             = apiConnection;
            _log = logger;
            _connStatusBroker.Subscribe(async x =>
            {
                logger.Debug("[HealthAction()] {ConnectionStatus} : {Message}",
                             x.ConnectionStatus.ToString(),
                             x.Message
                             );
                await Task.Run(async() =>
                {
                    switch (x.ConnectionStatus)
                    {
                    case ConnectionStatus.NotConnected:
                        await apiConnection.Reconnect();
                        break;

                    case ConnectionStatus.Connecting:
                        //await CheckConnectingStatus();
                        await CheckConnectingStatus();
                        break;

                    case ConnectionStatus.ConnectionReady:
                        break;

                    case ConnectionStatus.ConnectionError:
                        await apiConnection.Reconnect();
                        break;

                    default:
                        //throw new ArgumentOutOfRangeException();
                        break;
                    }
                });
            });
            //apiConnection.Connect().Wait();
            _connStatusBroker.Publish(ConnectionStatusEvent.GetEvent(apiConnection.APIStatus, "Ready for Connect()."));
        }
Пример #5
0
        public void Unsubscribe()
        {
            var broker = new DataEventBroker();

            var counterHandler = new CounterHanlder();

            broker.Subscribe(new EventHandler <EventArgs>(counterHandler.Handler));
            broker.Subscribe(new EventHandler <CustomEventArgs>(counterHandler.Handler));

            var anotherHandlerCounter = 0;

            broker.Subscribe <EventArgs>((sender, args) => {
                anotherHandlerCounter++;
            });

            Assert.True(broker.Unsubscribe(new EventHandler <EventArgs>(counterHandler.Handler)));
            Assert.False(broker.Unsubscribe(new EventHandler <CustomEventArgs>(counterHandler.Handler)));

            broker.Publish(this, new CustomEventArgs());
            Assert.AreEqual(0, counterHandler.Counter);
            Assert.AreEqual(1, anotherHandlerCounter);
        }
Пример #6
0
        public void PublishAndSubscribe()
        {
            var broker = new DataEventBroker();

            int publishingCallCount                    = 0;
            int publishedCallCount                     = 0;
            int allEventsSubscriberCallCount           = 0;
            int customEventsSubscriberCallCount        = 0;
            EventHandler <EventArgs> publishingHandler = (sender, args) => {
                publishingCallCount++;
            };
            EventHandler <EventArgs> publishedHandler = (sender, args) => {
                publishedCallCount++;
                Assert.AreEqual(publishingCallCount, publishedCallCount);
            };
            EventHandler <EventArgs> allEventsSubscribedHandler = (sender, args) => {
                allEventsSubscriberCallCount++;
                Assert.AreEqual(allEventsSubscriberCallCount, publishingCallCount);
                Assert.AreEqual(allEventsSubscriberCallCount - 1, publishedCallCount);
            };
            EventHandler <CustomEventArgs> customEventsSubscribedHandler = (sender, args) => {
                customEventsSubscriberCallCount++;
            };

            broker.Publishing += publishingHandler;
            broker.Published  += publishedHandler;

            broker.Subscribe(allEventsSubscribedHandler);
            broker.Subscribe(customEventsSubscribedHandler);

            broker.Publish(this, EventArgs.Empty);
            Assert.AreEqual(1, allEventsSubscriberCallCount);
            Assert.AreEqual(0, customEventsSubscriberCallCount);

            broker.Publish(this, new CustomEventArgs());
            Assert.AreEqual(2, allEventsSubscriberCallCount);
            Assert.AreEqual(1, customEventsSubscriberCallCount);
        }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of SqlCommandTraceTrigger and subscribes it to data events
 /// </summary>
 public SqlCommandTraceTrigger(DataEventBroker eventBroker) : this()
 {
     eventBroker.Subscribe(new EventHandler <DbCommandExecutingEventArgs>(DbCommandExecuting));
     eventBroker.Subscribe(new EventHandler <DbCommandExecutedEventArgs>(DbCommandExecuted));
 }
Пример #8
0
 /// <summary>
 /// Initializes new instance of DataRowTrigger with specified row action, table name, handler and subscribes it to appropriate data events.
 /// </summary>
 /// <param name="rowAction">row action flags</param>
 /// <param name="tableName">table name to match</param>
 /// <param name="handler">handler delegate</param>
 /// <param name="broker">data events broker</param>
 public DataRowTrigger(DataRowActionType rowAction, string tableName, Action <DataRowTriggerEventArgs> handler, DataEventBroker broker)
 {
     TableName = tableName;
     Action    = rowAction;
     Handler   = handler;
     SubscribeForEvents(broker);
 }
Пример #9
0
 /// <summary>
 /// Initializes new instance of DataRowTrigger with specified handler
 /// </summary>
 /// <param name="handler">handler delegate</param>
 /// <param name="broker">data events broker</param>
 public DataRowTrigger(Action <DataRowTriggerEventArgs> handler, DataEventBroker broker)
 {
     Handler = handler;
     SubscribeForEvents(broker);
 }
 public InvalidateDataDependencyTrigger(string dataSourceId, DataEventBroker broker)
 {
     broker.Subscribe(IsMatch, new EventHandler <RowUpdatedEventArgs>(RowUpdatedHandler));
 }