예제 #1
0
        public CreateSTF(long securityCode, long xmlBlockSize, string filename, long endMarker, Root DirectoryHierarchyManager)
        {
            #region Routine for creating STF
            FileStream   STFStream = new FileStream(string.Format("{0}.{1}", Environment.CurrentDirectory + @"\" + ConfigurationSettings.AppSettings["AllEntityLocation"] + filename, ConfigurationSettings.AppSettings["SecureBinTemporaryExtension"]), FileMode.Create, FileAccess.Write);
            BinaryWriter writeSTF  = new BinaryWriter(STFStream);

            writeSTF.Write(securityCode);              //Security Code
            writeSTF.Write(true);                      //Setting IsFolder Property
            writeSTF.Write(xmlBlockSize);              //Writing XML File Size
            IncludeXML("HierarchySize.xml", writeSTF); //Writing XML Document

            long numberOfFiles = LockParameters.NumberOfFiles;
            writeSTF.Write(numberOfFiles);   //Writing number of files included
            ByteOffset  = 25 + xmlBlockSize; //Byte Offset before files
            ByteOffset += numberOfFiles * 24;
            for (long FileKey = 0; FileKey < numberOfFiles; ++FileKey)
            {
                FileAttrib SelectFile = LockParameters.GetFileAttrib((int)FileKey);
                writeSTF.Write(FileKey);                                                                   //Writing FileID
                writeSTF.Write(LockParameters.GetFileAttrib((int)FileKey).FileStartLocation + ByteOffset); //Writing File Start Location
                writeSTF.Write(LockParameters.GetFileAttrib((int)FileKey).FileEndLocation + ByteOffset);   //Writing File End Location
            }

            for (long FileKey = 0; FileKey < numberOfFiles; ++FileKey)
            {
                IncludeFile(LockParameters.GetFileAttrib((int)FileKey), writeSTF);
            }

            writeSTF.Write(endMarker);
            writeSTF.Close();
            STFStream.Close();

            #endregion
        }
예제 #2
0
        private void IncludeFile(FileAttrib FileToWrite, BinaryWriter Writer)
        {
            FileStream Reader = new FileStream(FileToWrite.FileName, FileMode.Open, FileAccess.Read);

            for (int FilePointer = 0; FilePointer < Reader.Length; ++FilePointer)
            {
                byte data = (byte)Reader.ReadByte();
                Writer.Write(data);
            }
            Reader.Close();
        }