Beispiel #1
0
 static public void Err(string strLog)
 {
     if (KB9Logger.Instance().LoggerState == State.Running)
     {
         KB9Logger.Instance().Error(strLog);
     }
 }
Beispiel #2
0
 static public void Log(string strLog)
 {
     if (KB9Logger.Instance().LoggerState == State.Running)
     {
         KB9Logger.Instance().Info(strLog);
     }
 }
Beispiel #3
0
 static public KB9Logger Instance()
 {
     if (_Logger == null)
     {
         _Logger = new KB9Logger(Util.GetAppPath() + "\\KB9Log.txt", true, (uint)Level.All);
     }
     return(_Logger);
 }
Beispiel #4
0
 static public void EnableLog(bool bEnable)
 {
     if (bEnable)
     {
         KB9Logger.Instance().Start();
     }
     else
     {
         KB9Logger.Instance().Stop();
     }
 }
Beispiel #5
0
        /************************************************************************/

        /*
         * return: 0: ok
         *          1: messagebox shown, and correct
         *          2: messagebox shown, and manually correct them
         *          3: cancel edit, undo
         */
        /************************************************************************/
        static public int ValidateKeyTextBox2(Form frmCaller, KB9TextBox ctrlText)
        {
            string strKeys = ctrlText.Text;// GetInputedKeyCodes();

            if (strKeys == string.Empty)
            {
                return(0);
            }
            KB9Validation kb9 = new KB9Validation();

            KB9Validation.ERR_VALIDATION err = kb9.ValidateKB9Keycodes(strKeys);
            if (err == KB9Validation.ERR_VALIDATION.OK)
            {
                return(0);
            }
            string err_msg = ValidateErrMsg(err);
            string strlog  = "Key contents validation error";

            strlog += KB9Logger.LOG_LF;
            strlog += KB9Logger.LOG_TAB;
            strlog += ("Key contents:" + strKeys);
            strlog += KB9Logger.LOG_LF;
            strlog += KB9Logger.LOG_TAB;
            strlog += err_msg;

            KB9Logger.Err(strlog);



            if (err == KB9Validation.ERR_VALIDATION.Single_Function_With_Up)
            { //if it is single function key, just keep down key.
                ctrlText.RemoveLastKey();
                ctrlText.Refresh();
                return(0);
            }

            if (err == ERR_VALIDATION.Repeat_Must_Follow_Key ||
                err == ERR_VALIDATION.Repeat_Can_Not_Follow_Combination_Macro_Pause)
            {
                MessageBox.Show(frmCaller,
                                err_msg,
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return(2);
            }

            if (err == ERR_VALIDATION.Less_AltDown ||
                err == ERR_VALIDATION.Less_CtrlDown ||
                err == ERR_VALIDATION.Less_RAltDown ||
                err == ERR_VALIDATION.Less_RCtrlDown ||
                err == ERR_VALIDATION.Less_RShiftDown ||
                err == ERR_VALIDATION.Less_RWinDown ||
                err == ERR_VALIDATION.Less_ShiftDown ||
                err == ERR_VALIDATION.Less_WinDown)
            {
                DialogResult r = frmKeyCodeLessDown.ConfirmCancel();// MessageBox.Show(frmCaller,
                if (r == DialogResult.Yes)
                {
                    return(3);
                }
                else
                {
                    return(2);
                }
            }

            //DialogResult result = MessageBox.Show(frmCaller,
            //                                      "Key release codes does not match with corresponding key press codes.  Automatic fix by inserting key release codes at the end?",
            //                                      "Warning",
            //                                      MessageBoxButtons.YesNo,
            //                                      MessageBoxIcon.Warning);
            DialogResult result = frmKeyCodeError.ConfirmError();// MessageBox.Show(frmCaller,

            if (result == DialogResult.Yes)
            {
                int nloop = 0;
                while (err != ERR_VALIDATION.OK)
                {
                    if (err == KB9Validation.ERR_VALIDATION.Less_AltUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_RAltUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_CtrlUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_RCtrlUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_RShiftUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_ShiftUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_WinUp ||
                        err == KB9Validation.ERR_VALIDATION.Less_RWinUp)
                    {
                        string strAppend = AppendErrKey(err);
                        //ctrlText.AddKeyCode(strAppend, false);
                        ctrlText.AppendKeyCode(strAppend);
                    }
                    //else if (err == KB9Validation.ERR_VALIDATION.Single_Function_With_Up)
                    //{
                    //    ctrlText.RemoveLastKey();
                    //}
                    else
                    { //less down, remove last up
                        string strRemove = RemoveErrKey(err);
                        ctrlText.RemoveLastKeyCode(strRemove);
                    }
                    strKeys = ctrlText.Text;
                    err     = kb9.ValidateKB9Keycodes(strKeys);
                    nloop++;
                    if (nloop > 256)
                    {
                        MessageBox.Show(frmCaller, "The automatic fix failed, please correct it manually.",
                                        "Warning",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                        ctrlText.Refresh();
                        //log
                        strlog  = "Can not fixed automaticly.";
                        strlog += KB9Logger.LOG_LF;
                        strlog += KB9Logger.LOG_TAB;
                        strlog += "Result:";
                        strlog += ctrlText.Text;
                        KB9Logger.Err(strlog);
                        return(2);
                    }
                }
                ctrlText.Refresh();
                //log
                strKeys = ctrlText.Text;
                strlog  = "Auto fixed result:";
                strlog += KB9Logger.LOG_LF;
                strlog += KB9Logger.LOG_TAB;
                strlog += strKeys;
                KB9Logger.Log(strlog);
            }
            else
            {
                return(2);
            }



            return(1);
        }