Example #1
0
        public void SqlForm_Load(object sender, EventArgs e)
        {
            ToolTip();
            QueryBox.Text      = "Enter Query Here";
            QueryBox.ForeColor = Color.Gray;
            this.AcceptButton  = QueryButton;
            var _message = new DisplayMessage();

            _message.Message("This is the form. Do your thing.");
        }
Example #2
0
    public static void HashEachInput(string[] inputs, bool text, HashFunction hashFunction)
    {
        if (inputs == null)
        {
            DisplayMessage.Error(!text ? "Please specify a file/directory to hash." : "Please specify text to hash.");
            return;
        }
        foreach (string input in inputs)
        {
            try
            {
                switch (text)
                {
                case false when Directory.Exists(input):
                {
                    string[] filePaths  = Directory.GetFiles(input, searchPattern: "*", SearchOption.AllDirectories);
                    int      arrayIndex = Array.IndexOf(inputs, input);
                    if (arrayIndex > 0)
                    {
                        Console.WriteLine();
                    }
                    DisplayMessage.Message(input, "Hashing each file in the directory...");
                    HashEachInput(filePaths, text: false, hashFunction);
                    if (arrayIndex != inputs.Length - 1)
                    {
                        Console.WriteLine();
                    }
                    continue;
                }

                case false when !File.Exists(input):
                    DisplayMessage.NamedError(input, "This file/directory path doesn't exist.");
                    continue;
                }
                using Stream stream = !text ? new FileStream(input, FileMode.Open, FileAccess.Read, FileShare.Read, HashingAlgorithms.BufferSize, FileOptions.SequentialScan) : new MemoryStream(Encoding.UTF8.GetBytes(input));
                byte[] hash = HashingAlgorithms.GetHash(stream, hashFunction);
                DisplayMessage.Message(input, BitConverter.ToString(hash).Replace("-", "").ToLower());
            }
            catch (Exception ex) when(ex is IOException or UnauthorizedAccessException or ArgumentException or SecurityException or NotSupportedException)
            {
                DisplayMessage.NamedError(input, ex.GetType().ToString());
            }
        }
    }
Example #3
0
        private void Init()
        {
            QueryParser parser = new QueryParser(query);

            root = parser.GetRoot();

            try
            {
                if (root != null)
                {
                    _messenger.Message("Valid Query");
                    parser.PrintNode(root, 0);
                    _messenger.Message("====================");

                    if (root.ChildNodes[0].Term.ToString() == "createDatabaseStmt")
                    {
                        CreateDatabase();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "dropDatabaseStmt")
                    {
                        DropDatabase();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "useDatabaseStmt")
                    {
                        ChangeDatabase();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "showTablesStmt")
                    {
                        ShowTables();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "showDatabasesStmt")
                    {
                        ShowDatabases();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "describeTableStmt")
                    {
                        DescribeTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "createTableStmt")
                    {
                        CreateTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "dropTableStmt")
                    {
                        DropTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "insertStmt")
                    {
                        InsertRecordIntoTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "updateStmt")
                    {
                        UpdateRecordOfTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "deleteStmt")
                    {
                        DeleteRecordsFromTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "selectStmt")
                    {
                        SelectRecordsFromTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "selectJoinStmt")
                    {
                        SelectRecordsFromMultipleTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "createIndexStmt")
                    {
                        CreateIndexOnColumn();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "dropIndexStmt")
                    {
                        DropIndexOnColumn();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "addPrimaryKeyStmt")
                    {
                        CreatePrimaryKey();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "dropPrimaryKeyStmt")
                    {
                        DropPrimaryKey();
                    }
                    else
                    {
                        _messenger.Error("Some error in alloting query");
                    }
                }
                else                 //invalid query
                {
                    _messenger.Error("Invalid Query");
                }
            }
            catch (Exception e)
            {
                _messenger.Error(e.Message);
            }
        }