Esempio n. 1
0
        public CacheRow Find(string identityCode, string searchKey)
        {
            CacheRow cacheRow      = null;
            long     lastRowNumber = 0;

            if (binaryFiles.ContainsKey(identityCode))
            {
                BinaryNavigator navigator = binaryFiles[identityCode].Navigator;
                navigator.MoveToFirst();
                object[] row   = null;
                bool     found = false;
                while (!navigator.EOF())
                {
                    lastRowNumber = navigator.RowNumber;
                    row           = navigator.Read();
                    if (((long)row[0]).ToString() == searchKey)
                    {
                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    cacheRow = new CacheRow(binaryFiles[identityCode].Header.Columns, lastRowNumber, row);
                }
            }

            return(cacheRow);
        }
Esempio n. 2
0
        public static void ValidateFile(string file)
        {
            if (!File.Exists(file))
            {
                throw new Exception(string.Concat("Bar data file '", file, "' does not exist!"));
            }
            else
            {
                BinaryNavigator binaryNavigator = null;
                try
                {
                    binaryNavigator = new BinaryNavigator(file, binaryFields);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Concat("Error reading data file '", file, "'!'"), ex);
                }

                object[] record = binaryNavigator.Read();

                //time must be valid
                try
                {
                    DateTime time = new DateTime((long)record[0]);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Concat("Invalid time format of data file '", file, "'!'"), ex);
                }
                finally
                {
                    binaryNavigator.Close();
                }

                binaryNavigator.Close();

                //prices must not be less than or equal to zero
                //open and closing prices must be anywhere between high and low prices
                if ((double)record[1] <= 0 || (double)record[2] <= 0 || (double)record[3] <= 0 || (double)record[4] <= 0 ||
                    (double)record[1] > (double)record[3] || (double)record[1] < (double)record[4] ||
                    (double)record[2] > (double)record[3] || (double)record[2] < (double)record[4])
                {
                    throw new Exception(string.Concat("Invalid price format of data file '", file, "'!'"));
                }
            }
        }
Esempio n. 3
0
        public CacheRow[] Select(string identityCode, long rowNumber, long rows = 1)
        {
            List <CacheRow> result    = new List <CacheRow>();
            BinaryNavigator navigator = binaryFiles[identityCode].Navigator;

            if (navigator.Seek(rowNumber))
            {
                for (int index = 0; index < rows; index++)
                {
                    result.Add(new CacheRow(binaryFiles[identityCode].Header.Columns, rowNumber + index, navigator.Read()));
                    if (navigator.EOF())
                    {
                        break;
                    }
                }
            }

            return(result.Count > 0 ? result.ToArray() : null);
        }