Exemplo n.º 1
0
        public PoboDayFileSummary(string name, string fileName)
        {
            Name = name;

            FileInfo info = new FileInfo(fileName);

            int fileSize = (int)info.Length;

            if (fileSize % PoboBarStructure.Size != 0)
            {
                Console.WriteLine("Wrong file size of " + fileSize.ToString());
                return;
            }

            byte[] buffer1 = new byte[PoboBarStructure.Size];
            byte[] buffer2 = new byte[PoboBarStructure.Size];

            FileStream   fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            buffer1 = br.ReadBytes(PoboBarStructure.Size);

            fs.Seek(-PoboBarStructure.Size, SeekOrigin.End);
            buffer2 = br.ReadBytes(PoboBarStructure.Size);

            br.Close();
            fs.Close();

            PoboBarStructure first = PoboDataImporter.BytesToStructures <PoboBarStructure>(buffer1)[0];
            PoboBarStructure last  = PoboDataImporter.BytesToStructures <PoboBarStructure>(buffer2)[0];

            Since      = first.Time.Date;
            Until      = last.Time.Date;
            ItemsCount = fileSize / PoboBarStructure.Size;
            TotalDays  = (int)(Until - Since).TotalDays + 1;
            IsAlive    = true;
        }
Exemplo n.º 2
0
        //public static List<Quote> Import(string fileName)
        //{
        //    return Import(fileName, 0);
        //}

        //public static List<Quote> Import(string fileName, int offset)
        //{
        //    FileStream fs = null;

        //    try
        //    {
        //        FileInfo info = new FileInfo(fileName);

        //        int fileSize = (int)(info.Length);

        //        if (fileSize % PoboBarStructure.Size != 0)
        //        {
        //            Console.WriteLine("File size = " + fileSize.ToString() + ", check to see if the file is corrupted!");
        //            return null;
        //        }
        //        else if (offset >= fileSize / PoboBarStructure.Size - 1 || offset < 0)
        //            throw new ArgumentOutOfRangeException("Offset is out of range!");

        //        byte[] buffer = new byte[fileSize - offset * PoboBarStructure.Size];

        //        fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        //        int start = offset * PoboBarStructure.Size;
        //        int count = fileSize - offset * PoboBarStructure.Size;
        //        int readed = fs.Read(buffer, start, count);
        //        fs.Close();

        //        if (readed != fileSize - offset * PoboBarStructure.Size)
        //            throw new IOException("Failed to read all data!");

        //        PoboBarStructure[] rawRecords = BytesToStructures<PoboBarStructure>(buffer);

        //        return PoboBarStructure.QuotesOf(rawRecords);
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine(ex.Message);
        //        Console.WriteLine(ex.StackTrace);
        //        return null;
        //    }
        //}

        public static List <Quote> Import(string fileName, RecordType type)
        {
            FileStream fs = null;

            try
            {
                FileInfo info = new FileInfo(fileName);

                int fileSize = (int)(info.Length);

                if (fileSize % PoboBarStructure.Size != 0)
                {
                    Console.WriteLine("File size = " + fileSize.ToString() + ", check to see if the file is corrupted!");
                    return(null);
                }
                byte[] buffer = new byte[fileSize];

                fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                int readed = fs.Read(buffer, 0, fileSize);
                fs.Close();

                if (readed != fileSize)
                {
                    throw new IOException("Failed to read all data!");
                }

                PoboBarStructure[] rawRecords = BytesToStructures <PoboBarStructure>(buffer);

                return(PoboBarStructure.QuotesOf(rawRecords, type));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(null);
            }
        }
Exemplo n.º 3
0
 public static Quote QuoteOf(PoboBarStructure record, RecordType type)
 {
     return(new Quote(type, record.Time, record.Open, record.High, record.Low, record.Close, record.Volume));
 }