private static void AddPerson(IWritableReactiveTable people, int id, string name)
        {
            var rowIndex = people.AddRow();

            people.SetValue(PersonColumns.IdColumn, rowIndex, PersonIdOffset + id);
            people.SetValue(PersonColumns.NameColumn, rowIndex, name);
        }
Exemplo n.º 2
0
        public static IReactiveTable CreateJoinedReactiveTable(out IWritableReactiveTable table1, out IWritableReactiveTable table2)
        {
            table1 = CreateReactiveTable();
            table2 = CreateReactiveTable2();

            return(table1.Join(table2, new Join <int>(table1, TestTableColumns.IdColumn, table2, TestTableColumns.OtherIdColumn2)));
        }
Exemplo n.º 3
0
        private void UpdateRates(Dictionary <string, int> ccyPairsToRowIds, IWritableReactiveTable fxRates, bool full = true)
        {
            for (var i = 0; i < _currencyList.Length; i++)
            {
                for (var j = i + 1; j < _currencyList.Length; j++)
                {
                    var ccy1 = _currencyList[i];
                    var ccy2 = _currencyList[j];

                    var ccyPair = ccy1 + ccy2;
                    var rowId   = ccyPairsToRowIds[ccyPair];
                    if (full)
                    {
                        fxRates.SetValue(FxTableDefinitions.FxRates.CcyPairId, rowId, ccyPair);
                    }
                    fxRates.SetValue(FxTableDefinitions.FxRates.Bid, rowId, GetRandomBidAsk());
                    fxRates.SetValue(FxTableDefinitions.FxRates.Ask, rowId, GetRandomBidAsk());
                    fxRates.SetValue(FxTableDefinitions.FxRates.Open, rowId, GetRandomBidAsk());
                    fxRates.SetValue(FxTableDefinitions.FxRates.Close, rowId, GetRandomBidAsk());
                    fxRates.SetValue(FxTableDefinitions.FxRates.YearRangeStart, rowId, GetRandomBidAsk());
                    fxRates.SetValue(FxTableDefinitions.FxRates.YearRangeEnd, rowId, GetRandomBidAsk());
                    fxRates.SetValue(FxTableDefinitions.FxRates.Change, rowId, GetRandomBidAsk());
                    fxRates.SetValue(FxTableDefinitions.FxRates.Time, rowId, DateTime.UtcNow);
//                    var ticksElapsed = DateTime.Now.Ticks - _start.Ticks;
//                    fxRates.SetValue(FxTableDefinitions.FxRates.Ticks, rowId, ticksElapsed);
                }
            }
        }
Exemplo n.º 4
0
        private void AddRow(string groupVal, int value, IWritableReactiveTable table1, string GroupColumnId, string ValueColumnId)
        {
            var row1 = table1.AddRow();

            table1.SetValue(GroupColumnId, row1, groupVal);
            table1.SetValue(ValueColumnId, row1, value);
        }
 public void SetValues(IWritableReactiveTable targetTable)
 {
     while (_updates.Count > 0)
     {
         var update = _updates.Dequeue();
         targetTable.SetValue(update.ColumnId, update.RowIndex, update.Value);
     }
 }
Exemplo n.º 6
0
        private void AddCurrencyPair(IWritableReactiveTable currencyPairsWire, string ccyPair)
        {
            var row = currencyPairsWire.AddRow();

            currencyPairsWire.SetValue(BrokerTableDefinition.BrokerClientColumns.ClientIpColumn, row, IPAddress.Loopback.ToString());
            currencyPairsWire.SetValue(BrokerTableDefinition.BrokerClientColumns.ClientCcyPairColumn, row, ccyPair);
            currencyPairsWire.SetValue(BrokerTableDefinition.BrokerClientColumns.ClientSide.Selected, row, false);
        }
Exemplo n.º 7
0
//        private readonly IDisposable _columnSubscription;

        public TableSynchroniser(IReactiveTable sourceTable, IWritableReactiveTable targetTable, IThreadMarshaller threadMarshaller)
        {
            _sourceTable      = sourceTable;
            _targetTable      = targetTable;
            _threadMarshaller = threadMarshaller;

            _subscription = _sourceTable.Subscribe(this);
        }
 public void SetValues(IWritableReactiveTable targetTable)
 {
     foreach (var update in _updatesByRow.Values)
     {
         targetTable.SetValue(update.ColumnId, update.RowIndex, update.Value);
     }
     Clear();
 }
        private static void AddAccount(IWritableReactiveTable accountsWire, int accountId, int personId, decimal balance)
        {
            var rowId = accountsWire.AddRow();

            accountsWire.SetValue(AccountColumns.IdColumn, rowId, AccountIdOffset + accountId);
            accountsWire.SetValue(AccountColumns.PersonId, rowId, PersonIdOffset + personId);
            accountsWire.SetValue(AccountColumns.AccountBalance, rowId, balance);
        }
 /// <summary>
 /// Create batched pass through table - uses a timer
 /// </summary>
 /// <param name="targetTable">The table to write to</param>
 /// <param name="marshaller">The thread marshaller</param>
 /// <param name="delay">The frequency with which we should update the target table</param>
 /// <param name="onlyKeepLastValue">Whether to only keep the last value for a column/cell position</param>
 public ReactiveBatchedPassThroughTable(IWritableReactiveTable targetTable, IThreadMarshaller marshaller, TimeSpan delay, bool onlyKeepLastValue = false)
     : this(targetTable, marshaller, onlyKeepLastValue)
 {
     _timer           = new System.Timers.Timer(delay.TotalMilliseconds);
     _timer.Elapsed  += (sender, args) => SynchroniseChanges();
     _timer.AutoReset = false;
     _timer.Start();
 }
Exemplo n.º 11
0
        private void StartReceiving(IWritableReactiveTable currenciesWire, Dictionary <string, int> columnsToFieldIds, int port)
        {
            var endPoint = new IPEndPoint(IPAddress.Loopback, port);
            var client   = new ReactiveTableTcpClient <IWritableReactiveTable>(new ProtobufTableDecoder(), currenciesWire,
                                                                               new ProtobufDecoderState(columnsToFieldIds.InverseUniqueDictionary()), endPoint);

            _clients.Add(client);
            client.Start();
        }
        private static void UpdateRandomPerson(IWritableReactiveTable people, int maxId, Random random)
        {
            var id       = random.Next(1, maxId);
            var rowIndex = id - 1;

            //            var currentValue = People.GetValue<string>(PersonColumns.NameColumn, rowIndex);
            people.SetValue(PersonColumns.NameColumn, rowIndex, new string('*', random.Next(0, BatchSize)));
            //            People.SetValue(PersonColumns.NameColumn, rowIndex, "Modified at " + DateTime.Now);
        }
        private static void UpdateRandomAccount(IWritableReactiveTable accounts, int maxId, Random random)
        {
            var     id             = random.Next(1, maxId);
            var     rowIndex       = id - 1;
            var     currentBalance = random.Next(0, 100000); // accounts.GetValue<decimal>(AccountColumns.AccountBalance, rowIndex);
            decimal offset         = id % 2 == 0 ? 3242 : -7658;

            accounts.SetValue(AccountColumns.AccountBalance, rowIndex, currentBalance + offset);
        }
Exemplo n.º 14
0
        private static int AddRow(IWritableReactiveTable table, int id, string stringVal, decimal decimalVal)
        {
            var row1 = table.AddRow();

            table.SetValue(TestTableColumns.IdColumn, row1, id);
            table.SetValue(TestTableColumns.StringColumn, row1, stringVal);
            table.SetValue(TestTableColumns.DecimalColumn, row1, decimalVal);
            return(row1);
        }
Exemplo n.º 15
0
 public static void SetAndTestValueNotPresent <T>(IWritableReactiveTable setTable,
                                                  IReactiveTable getTable,
                                                  int setRowId,
                                                  int getRowId,
                                                  T value,
                                                  string columnId)
 {
     setTable.SetValue(columnId, setRowId, value);
     Assert.AreEqual(default(T), getTable.GetValue <T>(columnId, getRowId));
 }
Exemplo n.º 16
0
        public BatchedTableSynchroniser(ReactiveTable sourceTable, IWritableReactiveTable targetTable,
                                        IThreadMarshaller threadMarshaller, TimeSpan delay)
        {
            _sourceTable      = sourceTable;
            _targetTable      = targetTable;
            _threadMarshaller = threadMarshaller;
            _timer            = new Timer(SynchroniseChanges, null, delay, delay);

            _subscription = _sourceTable.Subscribe(this);
        }
        public PersonAccountsViewModel(IReactiveTable personAccounts, IWritableReactiveTable accounts)
        {
            _personAccounts = personAccounts;

            PersonAccounts = new IndexedObservableCollection <PersonAccountViewModel, int>(h => h.RowIndex);
            _subscription  = _personAccounts.ReplayAndSubscribe(OnNext);

            Change = new DelegateCommand(
                () => accounts.SetValue(AccountColumns.AccountBalance, CurrentRowIndex, (decimal)DateTime.Now.Millisecond));

            _personAccounts.ChangeNotifier.RegisterPropertyNotifiedConsumer(this, CurrentRowIndex);
        }
Exemplo n.º 18
0
        private static void StartBrokerFeeds(IWritableReactiveTable feeds)
        {
            var feeders = new List <BrokerFeed>
            {
                new BrokerFeed("Tullet", feeds),
                new BrokerFeed("VolBroker", feeds),
                new BrokerFeed("Tradition", feeds)
            };

            foreach (var brokerFeed in feeders)
            {
                brokerFeed.Start();
            }
        }
Exemplo n.º 19
0
        private void SetupClientCcyPairServer(IWritableReactiveTable clientsTable, IReactiveTableProcessor <IWritableReactiveTable> tableDecoder)
        {
            clientsTable.Subscribe(update => Console.WriteLine("Server side: " + update.ToString()));

            // Used non-batched pass through as we won't be receiving much data.
            var server = new ReactiveTableTcpServer <IWritableReactiveTable>(
                () => tableDecoder,
                new IPEndPoint(IPAddress.Loopback, (int)ServerPorts.BrokerFeedClients),
                _finished,
                s => clientsTable);

            // Start the server in a new thread
            Task.Run(() => server.Start(GetDecoderState()));
        }
        private IWritableReactiveTable SetupAccountTable(IWritableReactiveTable accounts,
                                                         List <IReactiveColumn> baseAccountColumns,
                                                         Dispatcher dispatcher)
        {
            baseAccountColumns.ForEach(col => accounts.AddColumn(col));

            // Create the wire table
            var accountsWire = new ReactiveBatchedPassThroughTable(accounts, new WpfThreadMarshaller(dispatcher), _synchroniseTablesDelay);

            //            var accountsWire = new ReactiveTable(accounts);
            //            new BatchedTableSynchroniser(accountsWire, accounts, new WpfThreadMarshaller(dispatcher), _synchroniseTablesDelay);

            return(accountsWire);
        }
        protected void SetTable(IReactiveTable table)
        {
            _table         = table;
            _writableTable = _table as IWritableReactiveTable;
            _token         = table.ReplayAndSubscribe(OnNext);
            var sortedTable = table as ISortedTable;

            if (sortedTable != null)
            {
                RowPositionsUpdated = sortedTable.RowPositionsUpdated;
            }

            // TODO: This should look up a dictionary of column id's to friendly column names
            ColumnNames = table.Columns.Select(c => c.ColumnId.Substring(c.ColumnId.LastIndexOf('.') + 1)).ToList();

            _columnIds = table.Columns.Select(c => c.ColumnId).ToList();
        }
Exemplo n.º 22
0
        private void StartReceiving(IWritableReactiveTable wireTable, Dictionary <string, int> columnsToFieldIds, int port, IReactiveTableProcessor <IWritableReactiveTable> decoder)
        {
            var endPoint = new IPEndPoint(IPAddress.Loopback, port);
            var client   = new ReactiveTableTcpClient <IWritableReactiveTable>(decoder,
                                                                               wireTable,
                                                                               GetDecoderState(columnsToFieldIds),
                                                                               endPoint);

            _feedClient = client;
            try
            {
                client.Start();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
        private IWritableReactiveTable SetupPersonTable(IWritableReactiveTable people,
                                                        List <IReactiveColumn> baseColumns,
                                                        Dispatcher dispatcher)
        {
            // Wire up the two tables before the dynamic columns
            var peopleWire = new ReactiveBatchedPassThroughTable(people, new WpfThreadMarshaller(dispatcher), _synchroniseTablesDelay);

            //            var PeopleWire = new ReactiveTable(People);
            //            new BatchedTableSynchroniser(PeopleWire, People, new WpfThreadMarshaller(dispatcher), _synchroniseTablesDelay);

            people.AddColumn(new ReactiveCalculatedColumn2 <string, int, string>(
                                 PersonColumns.IdNameColumn,
                                 (IReactiveColumn <int>)baseColumns[0],
                                 (IReactiveColumn <string>)baseColumns[1],
                                 (idVal, nameVal) => idVal + nameVal));

            return(peopleWire);
        }
 /// <summary>
 /// Create batched pass through table
 /// </summary>
 /// <param name="targetTable">The table to write to</param>
 /// <param name="marshaller">The thread marshaller</param>
 /// <param name="onlyKeepLastValue">Whether to only keep the last value for a column/cell position</param>
 public ReactiveBatchedPassThroughTable(IWritableReactiveTable targetTable, IThreadMarshaller marshaller, bool onlyKeepLastValue = false)
 {
     _targetTable       = targetTable;
     _marshaller        = marshaller;
     _onlyKeepLastValue = onlyKeepLastValue;
 }
Exemplo n.º 25
0
 public static void SetAndTestValue <T>(IWritableReactiveTable table, int rowId, T value, string columnId)
 {
     table.SetValue(columnId, rowId, value);
     Assert.AreEqual(value, table.GetValue <T>(columnId, rowId));
 }
Exemplo n.º 26
0
 public static void SetAndTestValue <T>(IWritableReactiveTable setTable, IReactiveTable getTable, int setRowId, int getRowId, T value, string columnId)
 {
     setTable.SetValue(columnId, setRowId, value);
     TestValue(getTable, getRowId, value, columnId);
 }
Exemplo n.º 27
0
 public BrokerFeed(string name, IWritableReactiveTable table)
 {
     Name   = name;
     _table = table;
 }
 private static void AddTestPeople(IWritableReactiveTable people)
 {
     AddPerson(people, 1, "Mendel");
     AddPerson(people, 2, "Marie");
 }
 private static void AddTestAccounts(IWritableReactiveTable accounts)
 {
     AddAccount(accounts, 1, 1, 10m);
     AddAccount(accounts, 2, 1, 100m);
     AddAccount(accounts, 3, 2, 10000m);
 }