Ejemplo n.º 1
0
        public IEnumerable <KeyValuePair <long, Tick> > Read()
        {
            LinterDbCommand command = connection.CreateCommand();

            command.CommandText = String.Format(
                "SELECT * FROM {0} " +
                "ORDER BY ID", name);

            using (LinterDbDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    long key = reader.GetInt64(0);

                    Tick tick = new Tick();
                    tick.Symbol    = reader.GetString(1);
                    tick.Timestamp = reader.GetDateTime(2);
                    tick.Bid       = reader.GetDouble(3);
                    tick.Ask       = reader.GetDouble(4);
                    tick.BidSize   = reader.GetInt32(5);
                    tick.AskSize   = reader.GetInt32(6);
                    tick.Provider  = reader.GetString(7);

                    yield return(new KeyValuePair <long, Tick>(key, tick));
                }
            }
        }
Ejemplo n.º 2
0
        public Tick this[long key]
        {
            get
            {
                LinterDbCommand command = connection.CreateCommand();
                command.CommandText = String.Format(
                    "SELECT * FROM {0} " +
                    "WHERE ID = {1}", name, key);

                using (LinterDbDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        Tick tick = new Tick();
                        tick.Symbol    = reader.GetString(1);
                        tick.Timestamp = reader.GetDateTime(2);
                        tick.Bid       = reader.GetDouble(3);
                        tick.Ask       = reader.GetDouble(4);
                        tick.BidSize   = reader.GetInt32(5);
                        tick.AskSize   = reader.GetInt32(6);
                        tick.Provider  = reader.GetString(7);
                        return(tick);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            set
            {
                lock (SyncRoot)
                {
                    writeCommand.Parameters[0].Value = key;
                    writeCommand.Parameters[1].Value = value.Symbol;
                    writeCommand.Parameters[2].Value = value.Timestamp;
                    writeCommand.Parameters[3].Value = value.Bid;
                    writeCommand.Parameters[4].Value = value.Ask;
                    writeCommand.Parameters[5].Value = value.BidSize;
                    writeCommand.Parameters[6].Value = value.AskSize;
                    writeCommand.Parameters[7].Value = value.Provider;

                    writeCommand.ExecuteNonQuery();
                }
            }
        }