コード例 #1
0
        public static PrivateDataCustomer GetPrivateData(string fileName)
        {
            FileStream          sourceData;
            BinaryReader        sr;
            MemoryStream        ms;
            PrivateDataCustomer pdc;

            char[] signature;
            byte[] buffer;
            long   len, sizeRead, i;

            pdc        = new PrivateDataCustomer();
            sourceData = new FileStream(fileName, FileMode.Open);
            //Read signal
            sr        = new BinaryReader(sourceData);
            len       = sr.ReadInt32();
            signature = new char[len + 1];
            sr.ReadByte();
            sr.Read(signature, 0, (int)len);
            len       = sr.ReadInt32();
            signature = new char[len];
            sr.ReadByte();
            sr.Read(signature, 0, (int)len);
            //signature[len]=(char)0;
            pdc.ReportTitle = new string(signature);
            buffer          = new byte[BUFF_BLOCK];
            len             = sr.ReadInt32();

            pdc.ReportDefinition = new System.IO.MemoryStream();
            //Read report definition, this will be change to encoded version later
            //May be encode entire file, instead of encoding piece by piece
            i = 0;
            do
            {
                if (i + BUFF_BLOCK > len)
                {
                    sizeRead = len - i;
                }
                else
                {
                    sizeRead = BUFF_BLOCK;
                }
                if (sizeRead > 0)
                {
                    sizeRead = sr.Read(buffer, 0, (Int32)sizeRead);
                    pdc.ReportDefinition.Write(buffer, 0, (Int32)sizeRead);
                    i += sizeRead;
                }
            }while (i < len && sizeRead > 0);
            //Read the header images
            len = sr.ReadInt32();
            ms  = new MemoryStream();
            //sr.ReadByte();
            i = 0;
            do
            {
                if (i + BUFF_BLOCK > len)
                {
                    sizeRead = len - i;
                }
                else
                {
                    sizeRead = BUFF_BLOCK;
                }
                if (sizeRead > 0)
                {
                    sizeRead = sr.Read(buffer, 0, (Int32)sizeRead);
                    ms.Write(buffer, 0, (int)sizeRead);
                    i += sizeRead;
                }
            }while (i < len && sizeRead > 0);
            pdc.reportHeader = Image.FromStream(ms);
            ms.Dispose();
            //Read the MainBackGround images
            len = sr.ReadInt32();
            ms  = new MemoryStream();
            //sr.ReadByte();
            i = 0;
            do
            {
                if (i + BUFF_BLOCK > len)
                {
                    sizeRead = len - i;
                }
                else
                {
                    sizeRead = BUFF_BLOCK;
                }
                if (sizeRead > 0)
                {
                    sizeRead = sr.Read(buffer, 0, (Int32)sizeRead);
                    ms.Write(buffer, 0, (int)sizeRead);
                    i += sizeRead;
                }
            }while (i < len && sizeRead > 0);
            pdc.backGround = Image.FromStream(ms);
            sr.Close();
            sourceData.Close();
            return(pdc);
        }
コード例 #2
0
        public static PrivateDataCustomer GetPrivateData(string fileName)
        {
            FileStream sourceData;
            BinaryReader sr;
            MemoryStream ms;
            PrivateDataCustomer pdc;

            char[] signature;
            byte[] buffer;
            long len, sizeRead, i;

            pdc = new PrivateDataCustomer();
            sourceData = new FileStream(fileName, FileMode.Open);
            //Read signal
            sr = new BinaryReader(sourceData);
            len = sr.ReadInt32();
            signature = new char[len+1];
            sr.ReadByte();
            sr.Read(signature, 0, (int)len);
            len = sr.ReadInt32();
            signature = new char[len];
            sr.ReadByte();
            sr.Read(signature, 0, (int)len);
            //signature[len]=(char)0;
            pdc.ReportTitle = new string(signature);
            buffer = new byte[BUFF_BLOCK];
            len = sr.ReadInt32();

            pdc.ReportDefinition = new System.IO.MemoryStream();
            //Read report definition, this will be change to encoded version later
            //May be encode entire file, instead of encoding piece by piece
            i = 0;
            do{
                if (i+BUFF_BLOCK>len)
                    sizeRead  = len-i;
                else
                    sizeRead = BUFF_BLOCK;
                if (sizeRead>0)
                {
                    sizeRead = sr.Read(buffer, 0, (Int32)sizeRead);
                    pdc.ReportDefinition.Write(buffer, 0, (Int32)sizeRead);
                    i+=sizeRead;
                }
            }while (i<len&&sizeRead>0);
            //Read the header images
            len = sr.ReadInt32();
            ms = new MemoryStream();
            //sr.ReadByte();
            i = 0;
            do{
                if (i+BUFF_BLOCK>len)
                    sizeRead  = len-i;
                else
                    sizeRead = BUFF_BLOCK;
                if (sizeRead>0)
                {
                    sizeRead = sr.Read(buffer, 0, (Int32)sizeRead);
                    ms.Write(buffer, 0, (int)sizeRead);
                    i+=sizeRead;
                }
            }while (i<len&&sizeRead>0);
            pdc.reportHeader = Image.FromStream(ms);
            ms.Dispose();
            //Read the MainBackGround images
            len = sr.ReadInt32();
            ms = new MemoryStream();
            //sr.ReadByte();
            i = 0;
            do{
                if (i+BUFF_BLOCK>len)
                    sizeRead  = len-i;
                else
                    sizeRead = BUFF_BLOCK;
                if (sizeRead>0)
                {
                    sizeRead = sr.Read(buffer, 0, (Int32)sizeRead);
                    ms.Write(buffer, 0, (int)sizeRead);
                    i+=sizeRead;
                }
            }while (i<len&&sizeRead>0);
            pdc.backGround = Image.FromStream(ms);
            sr.Close();
            sourceData.Close();
            return pdc;
        }