示例#1
0
        public static List <Quote> Import(string fileName)
        {
            if (!fileName.EndsWith(FilePostfix))
            {
                Console.WriteLine("Unexpected file type!");
                return(null);
            }

            FileStream fs = null;

            try
            {
                FileInfo info = new FileInfo(fileName);

                long fileSize = info.Length;

                if (fileSize % PoboDayStructure.Size != 0)
                {
                    Console.WriteLine("File size = " + info.Length.ToString() + ", check to see if the file is corrupted!");
                    return(null);
                }

                byte[] buffer = new byte[info.Length];

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

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

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

                ////Mapping the byte[] to PoboDayStructure[]
                //PoboDayStructure[] rawRecords = new PoboDayStructure[readed/PoboDayStructure.Size];

                //GCHandle pinned = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                //Int32 addr = pinned.AddrOfPinnedObject().ToInt32();

                //for (int i = 0; i < rawRecords.Length; i++)
                //{
                //    rawRecords[i] = (PoboDayStructure)Marshal.PtrToStructure(new IntPtr(i * PoboDayStructure.Size + addr), typeof(PoboDayStructure));
                //}

                //pinned.Free();

                return(PoboDayStructure.QuotesOf(rawRecords));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(null);
            }
        }
示例#2
0
        public PoboDayFileSummary(string name, string fileName)
        {
            Name = name;

            FileInfo info = new FileInfo(fileName);

            int fileSize = (int)info.Length;

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

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

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

            buffer1 = br.ReadBytes(PoboDayStructure.Size);

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

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

            PoboDayStructure first = PoboImporter.BytesToStructures <PoboDayStructure>(buffer1)[0];
            PoboDayStructure last  = PoboImporter.BytesToStructures <PoboDayStructure>(buffer2)[0];

            Since      = first.Time.Date;
            Until      = last.Time.Date;
            ItemsCount = fileSize / PoboDayStructure.Size;
            TotalDays  = (int)(Until - Since).TotalDays + 1;
            IsAlive    = true;
        }
示例#3
0
 public static Quote QuoteOf(PoboDayStructure record)
 {
     return(new Quote(record.Time, record.Open, record.High, record.Low, record.Close, record.Volume));
 }