예제 #1
0
        public void Read(AerospikeClient client, BatchPolicy policy, string ns, string set, string accountId)
        {
            Record record = client.Join(policy,
                new Key(ns, set, accountId),
                new Join("tickers", ns, set));

            if (record == null)
            {
                throw new Exception("Failed to read: " + accountId);
            }

            this.accountId = accountId;
            byte[] positionsBytes = (byte[])record.GetValue("positions");
            Record[] records = (Record[])record.GetValue("tickers");

            if (positionsBytes != null)
            {
                MemoryStream ms = new MemoryStream(positionsBytes);
                BinaryReader reader = new BinaryReader(ms);
                int count = reader.ReadInt32();
                positions = new List<Position>(count);

                for (int i = 0; i < count; i++)
                {
                    positions.Add(new Position(reader, records[i]));
                }
            }
            else
            {
                positions = new List<Position>(0);
            }
        }