Ejemplo n.º 1
0
        public void AddTables(string[] asTableNames)
        {
            int i = 0;

            string[] asSqlCommands;

            if (((_eState == nState.OK) || (_eState == nState.FileNotFound)) && (_DatabaseConnection != null) && (asTableNames != null) && (asTableNames.Length > 0))
            {
                _eState       = nState.OK;
                asSqlCommands = new string[asTableNames.Length];

                foreach (string sTableName in asTableNames)
                {
                    asSqlCommands[i++] = "CREATE TABLE IF NOT EXISTS " + sTableName + " ( id INT PRIMARY KEY NOT NULL, data BLOB )";
                }
                CommandsNonQuery(asSqlCommands);
                Close();

                if (File.Exists(_sPath))
                {
                    _eState = nState.OK;
                }
                else
                {
                    _eState = nState.FileNotFound;
                }
            }
            else
            {
                _eState = nState.CouldNotCreate;
            }
        }
Ejemplo n.º 2
0
 public bool Open()
 {
     if (_eState == nState.OK)
     {
         if (!_isOpen)
         {
             try
             {
                 _DatabaseConnection.Open();
                 _isOpen = true;
                 _eState = nState.OK;
             }
             catch
             {
                 _isOpen = false;
                 _eState = nState.CouldNotOpen;
             }
         }
     }
     else
     {
         _isOpen = false;
         _eState = nState.CouldNotOpen;
         if (_DatabaseConnection != null)
         {
             _DatabaseConnection.Close();
             _DatabaseConnection = null;
         }
     }
     return(_isOpen);
 }
Ejemplo n.º 3
0
 protected SQLiteDatabase()
 {
     _isOpen             = false;
     _abMemoryBuffer     = new byte[ciMemoryBufferLength];
     _eState             = nState.Undefined;
     _sPath              = _sConnectionString = string.Empty;
     _DatabaseConnection = null;
 }
Ejemplo n.º 4
0
 /// <summary></summary>
 public bool Start()
 {
     if ((_eState != nState.Idle) || _quCommand.IsEmpty)
     {
         return(false);
     }
     else
     {
         eState       = nState.Working;
         _AsyncThread = new Thread(() => AsynchronousThreadMethod());
         _AsyncThread.Start();
         return(true);
     }
 }
Ejemplo n.º 5
0
        /// <summary></summary>
        public bool Start()
        {
            if ((_eState != nState.Idle) || _quCommands.IsEmpty)
            {
                return(false);
            }
            else
            {
                // Task t = new Task(() => { _Cryptography.FillKey(new CryptoKey("", CryptoKey.nKeyFormat.KeePass, CryptoKey.nKeyType.Symmetric, 32)); });
                // t.Start();

                eState       = nState.Working;
                _AsyncThread = new Thread(() => AsynchronousThreadMethod());
                _AsyncThread.Start();
                return(true);
            }
        }
Ejemplo n.º 6
0
        /// <summary></summary>
        private void AsynchronousThreadMethod()
        {
            while (_quCommand.TryDequeue(out BackgroundMessage UserInterfaceMessage))
            {
                switch (UserInterfaceMessage.eType)
                {
                case BackgroundMessage.nType.PasswordToKey: ExecutePasswordToKey(UserInterfaceMessage); break;

                default: throw new NotImplementedException("command not implemented: " + UserInterfaceMessage.eType.ToString());
                }
                if (_eState == nState.CancelRequested)
                {
                    Reset();
                }
            }
            _quReturn.Enqueue(new BackgroundMessage(BackgroundMessage.nType.Stop));
            eState       = nState.Idle;
            _AsyncThread = null;
        }
Ejemplo n.º 7
0
        /// <summary>Reset all variables.</summary>
        private void Reset()
        {
#pragma warning disable IDE0059   // Suppres warnings that the value assigned to variable is never used
            if (!_quCommands.IsEmpty)
            {
                while (_quCommands.TryDequeue(out BackgroundMessage MessageToDiscard))
                {
                    ;
                }
            }

            if (!_quReturn.IsEmpty)
            {
                while (_quReturn.TryDequeue(out BackgroundMessage MessageToDiscard))
                {
                    ;
                }
            }
#pragma warning restore IDE0059   // Value assigned to variable is never used

            eState       = nState.Idle;
            _AsyncThread = null;
        }
Ejemplo n.º 8
0
        public SQLiteDatabase(string sPath) : this()
        {
            string sDirectoryName = Path.GetDirectoryName(sPath);

            if (string.IsNullOrEmpty(sPath))
            {
                _eState = nState.DirectoryNotFound;
            }
            else
            {
                if (!Directory.Exists(sDirectoryName))
                {
                    try { Directory.CreateDirectory(sDirectoryName); }
                    catch { };
                }

                if (Directory.Exists(sDirectoryName))
                {
                    _sPath              = sPath;
                    _sConnectionString  = "Data Source=" + _sPath;
                    _DatabaseConnection = new SQLiteConnection(_sConnectionString);

                    if (File.Exists(sPath))
                    {
                        _eState = nState.OK;
                    }
                    else
                    {
                        _eState = nState.FileNotFound;
                    }
                }
                else
                {
                    _eState = nState.DirectoryNotFound;
                }
            }
        }
Ejemplo n.º 9
0
 /// <summary></summary>
 public void RequestCancel()
 {
     eState = nState.CancelRequested;
 }