Ejemplo n.º 1
0
        public SdCardFile Open(bool ClearContent)
        {
            DTPMaster.CheckConnAndVal();
            if (!IsExists)
            {
                throw new FileHandlerException("Файл не существует");
            }
            if (IsOpen)
            {
                throw new FileHandlerException("Файл уже был открыть");
            }
            if (IsGlobalOpenedFiles)
            {
                throw new FailOperationException("На этом домене уже есть открытый файл. Невозможно отрыть более однго файлов");
            }
            var res = Master.ph.File_Open(FilePath, ClearContent);

            if (res != GeneralPacketHandler.WriteReadFileHandleResult.OK)
            {
                throw new FailOperationException("Не удалось открыть файл", res);
            }
            IsOpen = true;
            IsGlobalOpenedFiles = true;
            return(this);
        }
Ejemplo n.º 2
0
        public void Delete()
        {
            DTPMaster.CheckConnAndVal();
            var res = Master.ph.File_Delete(FilePath);

            if (res != GeneralPacketHandler.FileDirHandleResult.OK)
            {
                throw new FailOperationException(res);
            }
        }
Ejemplo n.º 3
0
 public bool SetValidation(bool Use)
 {
     DTPMaster.CheckConnAndVal();
     if (ParentMaster.ph.Security_SetValidation(Use))
     {
         IsValidationRequired = true;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 4
0
 public bool ChangeKey(SecurityKey LastKey, SecurityKey NewKey)
 {
     DTPMaster.CheckConnAndVal();
     if (ParentMaster.ph.Security_ChangeKey(LastKey.key, NewKey.key))
     {
         _validKey = NewKey;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 5
0
 public bool Write(Int32 val)
 {
     DTPMaster.CheckConnAndVal();
     if (ph.File_Append(BitConverter.GetBytes(val)))
     {
         cacheLength += _i32;
         CursorPos   += _i32;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 6
0
 public bool Write(string val)
 {
     DTPMaster.CheckConnAndVal();
     if (ph.File_Append(System.Text.Encoding.Default.GetBytes(val)))
     {
         cacheLength += (UInt32)val.Length;
         CursorPos   += (UInt32)val.Length;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 7
0
        public SdCardFile Create()
        {
            DTPMaster.CheckConnAndVal();
            var res = Master.ph.File_Create(FilePath);

            if (res != GeneralPacketHandler.FileDirHandleResult.OK)
            {
                throw new FailOperationException("Не удалось создать файл", res);
            }
            return(this);
        }
Ejemplo n.º 8
0
 public bool Write(byte[] val)
 {
     DTPMaster.CheckConnAndVal();
     if (ph.File_Append(val))
     {
         cacheLength += (UInt32)val.Length;
         CursorPos   += (UInt32)val.Length;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 9
0
 public bool Write(byte val)
 {
     DTPMaster.CheckConnAndVal();
     if (ph.File_Append(new byte[1] {
         val
     }))
     {
         cacheLength += _Ui8;
         CursorPos   += _Ui8;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 10
0
        public bool Validate(SecurityKey Key)
        {
            if (IsValidated)
            {
                return(true);
            }

            DTPMaster.CheckConnAndVal(true);
            if (ParentMaster.ph.Security_Validate(Key.key))
            {
                _validKey = Key;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 11
0
        private SdCardBinnaryFileReadResult <object> ReadDouble()
        {
            DTPMaster.CheckConnAndVal();
            if (CursorPos + _D > cacheLength)
            {
                throw new ArgumentOutOfRangeException();
            }
            var res = ph.File_Read(CursorPos, _D);

            if (res.Status == GeneralPacketHandler.WriteReadFileHandleResult.OK)
            {
                CursorPos += _D;
                return(new SdCardBinnaryFileReadResult <object>(BitConverter.ToDouble(res.Result, 0), true));
            }
            return(new SdCardBinnaryFileReadResult <object>(0, false));
        }
Ejemplo n.º 12
0
        public void Close()
        {
            DTPMaster.CheckConnAndVal();
            if (!IsOpen)
            {
                throw new FileHandlerException("Файл закрыт");
            }
            var res = Master.ph.File_Close();

            if (!res)
            {
                throw new FailOperationException("Не удалось закрыть файл");
            }
            IsOpen = false;
            IsGlobalOpenedFiles = false;
        }
Ejemplo n.º 13
0
        public SdCardBinnaryFileReadResult <byte[]> ReadByteArray(UInt32 length)
        {
            DTPMaster.CheckConnAndVal();
            if (CursorPos + length > cacheLength)
            {
                throw new ArgumentOutOfRangeException();
            }
            var res = ph.File_Read(CursorPos, length);

            if (res.Status == GeneralPacketHandler.WriteReadFileHandleResult.OK)
            {
                CursorPos += length;
                return(new SdCardBinnaryFileReadResult <byte[]>(res.Result, true));
            }
            return(new SdCardBinnaryFileReadResult <byte[]>(new byte[0], false));
        }
Ejemplo n.º 14
0
        private SdCardBinnaryFileReadResult <object> ReadBool()
        {
            DTPMaster.CheckConnAndVal();
            if (CursorPos + _Ui8 > cacheLength)
            {
                throw new ArgumentOutOfRangeException();
            }
            var res = ph.File_Read(CursorPos, _Ui8);

            if (res.Status == GeneralPacketHandler.WriteReadFileHandleResult.OK)
            {
                CursorPos += _Ui8;
                return(new SdCardBinnaryFileReadResult <object>(res.Result[0] == 1, true));
            }
            return(new SdCardBinnaryFileReadResult <object>(0, false));
        }
Ejemplo n.º 15
0
        public void Delete(bool DeleteSubItems)
        {
            DTPMaster.CheckConnAndVal();
            if (DirectoryPath == "/")
            {
                throw new FileHandlerException("Невозможно удалить корень -_-");
            }
            if (!IsExists)
            {
                throw new FileHandlerException("Папка не существует");
            }
            var res = master.ph.Dir_Delete(DirectoryPath, DeleteSubItems);

            if (res != GeneralPacketHandler.FileDirHandleResult.OK)
            {
                throw new FailOperationException(res);
            }
        }
Ejemplo n.º 16
0
        public SdCardDirectory Create(bool CreateNecessary)
        {
            DTPMaster.CheckConnAndVal();
            if (DirectoryPath == "/")
            {
                throw new FileHandlerException("Невозможно создать корень -_-");
            }
            if (IsExists)
            {
                throw new FileHandlerException("Папка уже существует");
            }
            var res = master.ph.Dir_Create(DirectoryPath, CreateNecessary);

            if (res != GeneralPacketHandler.FileDirHandleResult.OK)
            {
                throw new FailOperationException("Не удалось создать папку", res);
            }
            return(this);
        }
Ejemplo n.º 17
0
        public void ClearAllBytes()
        {
            DTPMaster.CheckConnAndVal();
            if (IsOpen)
            {
                if (!Master.ph.File_Close())
                {
                    throw new FailOperationException("Не удалось закрыть файл");
                }
            }
            var res = Master.ph.File_Open(FilePath, true);

            if (res != GeneralPacketHandler.WriteReadFileHandleResult.OK)
            {
                throw new FailOperationException("Не удалось открыть файл", res);
            }
            if (!IsOpen)
            {
                if (!Master.ph.File_Close())
                {
                    throw new FailOperationException("Не удалось закрыть файл");
                }
            }
        }