示例#1
0
        // @return true if success Add header to file
        public bool WriteFileWithHeader(string sFullPath, byte[] fileBytes, STORED_FILE_HEADER header)
        {
            try
            {
                // create byte arrays with header and file.
                Helper h  = new Helper();
                byte[] bs = h.RawSerialize(header);

                FileInfo fi = new FileInfo(sFullPath);
                fi.Delete();

                FileStream fsSource = new FileStream(sFullPath, FileMode.Append);
                fsSource.Write(bs, 0, bs.Length);
                fsSource.Write(fileBytes, 0, fileBytes.Length);

                fsSource.Close();

                return(true);
            }
            catch (Exception e)
            {
                Logger.Log.Error(e.ToString());
                return(false);
            }
        }
示例#2
0
        // @return true if success Add header to file
        public bool AddHeaderToFile(STORED_FILE_HEADER header, String sFullPath)
        {
            try
            {
                // create byte arrays with header and file.
                Helper h         = new Helper();
                byte[] bs        = h.RawSerialize(header);
                byte[] fileBytes = File.ReadAllBytes(sFullPath);

                // rename file (add ".old" extention)
                ReserveFile(sFullPath);

                FileStream fsSource = new FileStream(sFullPath, FileMode.Append);
                fsSource.Write(bs, 0, bs.Length);
                fsSource.Write(fileBytes, 0, fileBytes.Length);

                fsSource.Close();

                DeleteReserveFile(sFullPath); // Delete .old file

                return(true);
            }
            catch (Exception e)
            {
                Logger.Log.Error(e.ToString());
                return(false);
            }
        }
示例#3
0
        public void RawSerialize_TestMethod()
        {
            DataDepositer.Helper          h  = new DataDepositer.Helper();
            DataDepositer.FileManipulator fm = new DataDepositer.FileManipulator();

//            String filePathFull = "d:\\test\\datadepositor\\join\\test.txt";
            String filePathFull = "d:\\test\\datadepositor\\testHeader.txt";
            String MD5Origin    = h.GetStringMD5("55555555555555555555555555555555");
            String MD5Chunk     = h.GetStringMD5("66666666666666666666666666666666");

            DISPLAY_DEVICE dd = new DISPLAY_DEVICE();

            dd.cb = Marshal.SizeOf(dd);

            string str = "Cool Device";

            dd.DeviceInstanceId = str;
            dd.DeviceName       = MD5Origin;
            dd.StateFlags       = 12345;

            byte[] test = h.RawSerialize(dd);

            File.WriteAllBytes(filePathFull, test);
        }