Exemplo n.º 1
0
        /// <summary>
        /// Run Java program in debugger
        /// </summary>
        public static void RunInDebugger()
        {
            CompileProject(false);
            _process = new Process
            {
                StartInfo = new ProcessStartInfo()
                {
                    FileName = "JdbWrapper.exe", Arguments = $"{JavaJdb} \"{ProjectFolder}\""
                }
            };
            OutputTextbox.Text += "Debugger Starting...\n";
            OutputTextbox.ScrollToEnd();

            _process.Start();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends specified key to a process
        /// </summary>
        /// <param name="proc">Tibia process</param>
        /// <param name="mana">Required mana for a spell / delay between clicks</param>
        /// <param name="prof">Class param, set 1 to ignore</param>
        /// <param name="item">Item equipped param, set 0 to ignore</param>
        /// <param name="key">VK key id</param>
        /// <param name="textBox">Textbox for debug</param>
        /// <param name="timesPressed">Amount of presses in single loop</param>
        /// <returns></returns>
        public async Task SendKey(Process proc, int mana, double prof, double item, int key, TextBox textBox, int timesPressed)
        {
            while (true)
            {
                if (Stop)
                {
                    break;
                }

                var rnd = new Random().Next(10, 200);
                //todo: remove this trash
                if (timesPressed == 2)
                {
                    PostMessage(proc.MainWindowHandle, WM_KEYDOWN, 0x1B, 0);
                    PostMessage(proc.MainWindowHandle, WM_KEYUP, 0x1B, 0);
                    await Task.Delay(250 + new Random().Next(1, 50));
                }
                for (var i = 0; i < timesPressed; i++)
                {
                    PostMessage(proc.MainWindowHandle, WM_KEYDOWN, key, 0);
                    PostMessage(proc.MainWindowHandle, WM_KEYUP, key, 0);
                }


                _totalrnd += rnd;
                var delay = mana / (prof + item) * 1000 + rnd;
                textBox?.AppendText($"\n{DateTime.Now:hh:mm:ss} - Pressed {key} with: {delay} ms.");
                textBox?.ScrollToEnd();
                await Task.Delay((int)delay);
            }
        }
Exemplo n.º 3
0
        public bool CancelMonitor(Monitor monitor, System.Windows.Controls.TextBox txtMessage)
        {
            string xml = string.Format(@"<hytera>
  <product_name>PUC</product_name>
  <version>10</version>
  <cmd_name>mon_monitor</cmd_name>
  <cmd_guid>{0}</cmd_guid>
  <puc_id>{1}</puc_id>
  <system_id>{2}</system_id>
  <user_id>{3}</user_id>
  <monitor_level>{4}</monitor_level>
  <target>
    <number>{5}</number>
    <number_type>{6}</number_type>
  </target>
</hytera>", Guid.NewGuid(), monitor.Puc_id, monitor.SystemID, monitor.pseudo_trunking_id, (GlobalCommandName.PUCMonitorLevelCancelAll).ToString(), monitor.Number, monitor.NumberType);

            txtMessage.Text += "\n发起取消监听 send xml:\n";
            txtMessage.Text += FormatXml(xml);
            txtMessage.ScrollToEnd();
            IntPtr xmlPtr = Marshal.StringToHGlobalUni(xml);

            PUCApiAdapter.PUCAPI_ProcessRequest(xmlPtr);
            return(true);
        }
Exemplo n.º 4
0
 /// <summary>
 ///   Writes the line.
 /// </summary>
 /// <param name = "str">The STR.</param>
 public override void WriteLine(string str)
 {
     /********************* .NET 4.0 (i.e. WPF) Specific Reference *********************/
     if (outputBox.Dispatcher.CheckAccess())
     {
         outputBox.AppendText(Thread.CurrentThread.Name + "•" + str + "\n");
         outputBox.ScrollToEnd();
     }
     else
     {
         outputBox.Dispatcher.Invoke(
             (ThreadStart) delegate
         {
             /*********************************************************************************/
             outputBox.AppendText(Thread.CurrentThread.Name + "•" + str + "\n");
             outputBox.ScrollToEnd();
         }
             );
     }
 }
Exemplo n.º 5
0
        public bool SetMonitor(Monitor monitor, System.Windows.Controls.TextBox txtMessage)
        {
            string monitorLevel = string.Empty;

            if (string.IsNullOrEmpty(monitor.MonitorLevel))
            {
                monitorLevel = (GlobalCommandName.PUCMonitorLevelEvent |
                                GlobalCommandName.PUCMonitorLevelMedia |
                                GlobalCommandName.PUCMonitorLevelOnline |
                                GlobalCommandName.PUCMonitorLevelSDSStatus |
                                GlobalCommandName.PUCMonitorLevelSDSText
                                ).ToString();
            }
            else
            {
                monitorLevel = monitor.MonitorLevel;
            }


            string xml = string.Format(@"<hytera>
  <product_name>PUC</product_name>
  <version>10</version>
  <cmd_name>mon_monitor</cmd_name>
  <cmd_guid>{0}</cmd_guid>
  <puc_id>{1}</puc_id>
  <system_id>{2}</system_id>
  <user_id>{3}</user_id>
  <monitor_level>{4}</monitor_level>
  <target>
    <number>{5}</number>
    <number_type>{6}</number_type>
  </target>
</hytera>", Guid.NewGuid(), monitor.Puc_id, monitor.SystemID, monitor.pseudo_trunking_id, monitorLevel, monitor.Number, monitor.NumberType);

            txtMessage.Text += "\n发起监听 send xml:\n";
            txtMessage.Text += FormatXml(xml);
            txtMessage.ScrollToEnd();
            IntPtr xmlPtr = Marshal.StringToHGlobalUni(xml);

            PUCApiAdapter.PUCAPI_ProcessRequest(xmlPtr);
            return(true);
        }
Exemplo n.º 6
0
        public async Task SendKeyMultiple(Process proc, int mana, double prof, double item, int key, TextBox textBox)
        {
//            var proc = Process.GetProcessesByName("client").FirstOrDefault();
//            if (proc == null)
//            {
//                return;
//            }

            while (true)
            {
                if (Stop)
                {
                    break;
                }

                var rnd = new Random().Next(10, 200);
                _totalrnd += rnd;
                var delay = mana / (prof + item) * 1000 + rnd;

                textBox?.AppendText($"\n{DateTime.Now:hh:mm:ss} - Pressed {key} with: {delay} ms.");
                textBox?.ScrollToEnd();

                await Task.Delay((int)delay);

                PostMessage(proc.MainWindowHandle, WM_KEYDOWN, key, 0);
                await Task.Delay(250);

                PostMessage(proc.MainWindowHandle, WM_KEYUP, key, 0);
                await Task.Delay(250);

                if (_totalrnd > 10000)
                {
                    delay -= _totalrnd;
                    textBox?.AppendText($"\n{DateTime.Now:hh:mm:ss} - Delay of {_totalrnd} removed.");
                    _totalrnd = 0;
                }

                //await Task.Delay((int)delay);
            }
        }
Exemplo n.º 7
0
 public static void AppendAndScroll(this System.Windows.Controls.TextBox ctl, string text)
 {
     ctl.AppendText(text);
     ctl.ScrollToEnd();
 }
Exemplo n.º 8
0
        private void bgwValidate_DoWork(object sender, DoWorkEventArgs e)
        {
            //Do the validation here
            DateTime begin = DateTime.Now;

            try
            {
                excelApp = new Application();
                List <String> scodes = new List <string>();
                int           rowCount = 0, columnCount = 0, i, j = 1;

                Workbook  courseWorkbook = excelApp.Workbooks.Open(fileName, 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                Worksheet courseWorksheet;
                Range     courseWorksheetRange;
                isValid = true;

                tempProcessLog = ln + "Reading worksheet..." + ln + "Total sheets : " + courseWorkbook.Sheets.Count;

                foreach (Worksheet cws in courseWorkbook.Sheets)
                {
                    if (!Medatabase.isPresentLike("course_master", "course_code", cws.Name))
                    {
                        tempProcessLog += ln + "sheet with name \"" + cws.Name + "\" course code is not present in database";
                        isValid         = false;
                        invalidRows++;
                    }
                    else
                    {
                        tempProcessLog      += ln + "======== reading sheet " + cws.Name + "========" + ln;
                        courseWorksheet      = cws;
                        courseWorksheetRange = courseWorksheet.UsedRange;

                        rowCount    = courseWorksheetRange.Rows.Count;
                        columnCount = courseWorksheetRange.Columns.Count;

                        tempProcessLog += ln + "Rows " + rowCount + " | Columns " + columnCount + ln;

                        if (rowCount <= 1)
                        {
                            tempProcessLog += ln + "in sheet \"" + cws.Name + "\" There are no records to validate...";
                            isValid         = false;
                            continue; //Move to next sheet
                        }

                        if (columnCount > 5 || columnCount < 5)
                        {
                            tempProcessLog += ln + "in sheet \"" + cws.Name + "\" Expecting columns to be 5, " + columnCount + " is present." + ln + "This excelsheet is not meeting the desired format.";
                            isValid         = false;
                            continue; //Move to next sheet
                        }

                        tempProcessLog += ln + "Expecting first row to be column names. " + ln + "reading from 2nd row...";

                        for (i = 2; i <= rowCount; i++)
                        {
                            try
                            {
                                tempProcessLog += ln + ">> Sheet [" + cws.Name + "] > Processing Row: " + i + ln;

                                /** CANT CHECK FOR DUPLICATE AS ELECTIVE LAB CAN HAVE DUPLICATE SUBJECT CODE :( **/

                                //Check for duplicate subject_code in database
                                if (Medatabase.isPresent("subject_master", "sub_code", (string)courseWorksheet.Cells[i, 1].Value))
                                {
                                    tempProcessLog += ln + "duplicate subject_code '" + (string)courseWorksheet.Cells[i, 1].Value + "' already present in database in row " + i;
                                    isValid         = false;
                                    invalidRows++;
                                }

                                //if not a lab subject
                                if (String.Compare((string)courseWorksheet.Cells[i, 5].Value, "Lab", true) != 0)
                                {
                                    //Check for duplicate subject_code in the same excel sheet
                                    if (scodes.IndexOf((string)courseWorksheet.Cells[i, 1].Value) != -1)
                                    {
                                        tempProcessLog += ln + "duplicate subject_code '" + (string)courseWorksheet.Cells[i, 1].Value + "' already present in the same excel sheet in row " + i;
                                        isValid         = false;
                                        invalidRows++;
                                    }
                                    scodes.Add((string)courseWorksheet.Cells[i, 1].Value);
                                }

                                if (courseWorksheet.Cells[i, 1].Value == null)
                                {
                                    tempProcessLog += ln + "Empty value given for subject_code in row " + i;
                                    isValid         = false;
                                    invalidRows++;
                                }

                                if (courseWorksheet.Cells[i, 2].Value == null)
                                {
                                    tempProcessLog += ln + "Empty value given for subject_name in row " + i;
                                    isValid         = false;
                                    invalidRows++;
                                }

                                if ((int)courseWorksheet.Cells[i, 3].Value <= 0 || (int)courseWorksheet.Cells[i, 3].Value > Courses.getSemCount(cws.Name))
                                {
                                    tempProcessLog += ln + "Invalid semester number \"" + (int)courseWorksheet.Cells[i, 3].Value + "\" in row " + i;
                                    isValid         = false;
                                    invalidRows++;
                                }

                                if ((int)courseWorksheet.Cells[i, 4].Value <= 0)
                                {
                                    tempProcessLog += ln + "Subject credits cannot be less than or equal to 0 in row " + i;
                                    isValid         = false;
                                    invalidRows++;
                                }

                                if (courseWorksheet.Cells[i, 5].Value == null)
                                {
                                    tempProcessLog += ln + "Empty value given for subject type in row " + i;
                                    isValid         = false;
                                    invalidRows++;
                                }
                            }
                            catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException be)
                            {
                                invalidRows++;
                                isValid         = false;
                                tempProcessLog += ln + "In row [" + i + "] expecting int value, string given!";
                                LogWriter.WriteError("While validating subject details worksheet", be.Message);
                            }

                            //Update output textbox
                            App.Current.Dispatcher.Invoke(new System.Action(() =>
                            {
                                txtOutput.AppendText(tempProcessLog);
                                txtOutput.ScrollToEnd();
                            }));

                            bgwValidate.ReportProgress(Convert.ToInt16(((i * 100) / rowCount)));
                            tempProcessLog = "";
                        }
                    }
                    bgwValidate.ReportProgress(Convert.ToInt16(((j * 100) / courseWorkbook.Sheets.Count)));
                    j++;
                }
            }
            catch (System.IO.IOException ioe)
            {
                tempProcessLog += ln + "ERROR HANDLING FILE :(" + ln + "Please retry";
                LogWriter.WriteError("While validating subject details worksheet", ioe.Message);
                isValid = false;
                return;
            }
            catch (databaseException)
            {
                tempProcessLog += ln + "ERROR OCCURED IN DATABASE OPERATION :(" + ln + "Please retry.";
                isValid         = false;
                return;
            }
            catch (Exception ex)
            {
                tempProcessLog += ln + "UNEXPECTED ERROR OCCURED :(" + ln + "Please retry.";
                LogWriter.WriteError("While validating subject details worksheet", ex.Message);
                isValid = false;
                return;
            }
            finally
            {
                if (invalidRows > 0)
                {
                    tempProcessLog += ln + ln + "There are total " + invalidRows + " errors.";
                }

                //Update output textbox
                tempProcessLog += ln + "Took " + String.Format("{0:0.00}", (DateTime.Now - begin).TotalSeconds) + " seconds";
                App.Current.Dispatcher.Invoke(new System.Action(() =>
                {
                    txtOutput.AppendText(tempProcessLog);
                    txtOutput.ScrollToEnd();
                    progress.Value = 100;
                }));

                excelApp.Workbooks.Close();
            }
        }
Exemplo n.º 9
0
        private void bgwValidate_DoWork(object sender, DoWorkEventArgs e)
        {
            //Do the validation here
            DateTime begin = DateTime.Now;

            try
            {
                const int MAX_SEMS = 8;
                int       sheetCount = 0;
                int       rowCount = 0, columnCount = 0, i;
                int       isem = 0, tsem = 0;
                string[]  courseCodes;
                isValid = true;

                excelApp = new Application();
                Workbook  courseWorkbook       = excelApp.Workbooks.Open(fileName, 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                Worksheet courseWorksheet      = (Worksheet)courseWorkbook.Sheets.get_Item(1);
                Range     courseWorksheetRange = courseWorksheet.UsedRange;

                sheetCount     = courseWorkbook.Sheets.Count;
                tempProcessLog = ln + "Reading worksheet..." + ln + "Total sheets : " + sheetCount;

                tempProcessLog += ln + "Using Sheet1... ";

                rowCount    = courseWorksheetRange.Rows.Count;
                columnCount = courseWorksheetRange.Columns.Count;
                courseCodes = new string[rowCount];

                tempProcessLog += ln + "Rows " + rowCount + " | Columns " + columnCount + ln;

                if (rowCount <= 1)
                {
                    tempProcessLog += ln + "There are no records to validate...";

                    App.Current.Dispatcher.Invoke(new System.Action(() =>
                    {
                        txtOutput.AppendText(tempProcessLog);
                        txtOutput.ScrollToEnd();
                        progress.Value = 100;
                    }));

                    isValid = false;
                    return;
                }

                if (columnCount > 4 || columnCount < 4)
                {
                    tempProcessLog += ln + "Expecting columns to be 4, " + columnCount + " is present." + ln + "This excelsheet is not meeting the desired format.";

                    App.Current.Dispatcher.Invoke(new System.Action(() =>
                    {
                        txtOutput.AppendText(tempProcessLog);
                        txtOutput.ScrollToEnd();
                        progress.Value = 100;
                    }));

                    isValid = false;
                    return;
                }

                tempProcessLog += ln + "Expecting first row to be column names. " + ln + "reading from 2nd row...";

                List <String> tmpCourseCodes = new List <string>();

                for (i = 2; i <= rowCount; i++)
                {
                    try
                    {
                        tempProcessLog += ln + "> Processing Row: " + i + ln;

                        if (courseWorksheet.Cells[i, 1].Value != null)
                        {
                            //Check for duplicate course_code in database
                            if (Medatabase.isPresentLike("course_master", "course_code", (string)courseWorksheet.Cells[i, 1].Value))
                            {
                                tempProcessLog += ln + "duplicate course_code '" + (string)courseWorksheet.Cells[i, 1].Value + "' already present in database...";
                                isValid         = false;
                                invalidRows++;
                            }

                            //Check for duplicate course_code in the same excel sheet
                            if (tmpCourseCodes.IndexOf((string)courseWorksheet.Cells[i, 1].Value) != -1)
                            {
                                tempProcessLog += ln + "duplicate course_code '" + (string)courseWorksheet.Cells[i, 1].Value + "' already present in the same excel sheet...";
                                isValid         = false;
                                invalidRows++;
                            }
                            else //if not duplicate
                            {
                                tmpCourseCodes.Add((string)courseWorksheet.Cells[i, 1].Value);
                            }
                        }
                        else
                        {
                            tempProcessLog += ln + "empty course_code given...'" + ln;
                            isValid         = false;
                            invalidRows++;
                        }

                        if (courseWorksheet.Cells[i, 2].Value != null)
                        {
                            tsem = Convert.ToInt16(courseWorksheet.Cells[i, 2].Value);
                            if (tsem > MAX_SEMS || tsem < 0)
                            {
                                tempProcessLog += ln + (string)courseWorksheet.Cells[i, 1].Value + " > total semesters must be between 0 and " + MAX_SEMS + ", " + tsem + " given";
                                isValid         = false;
                                invalidRows++;
                            }
                        }
                        else
                        {
                            tempProcessLog += ln + "empty value given for total semesters...'" + ln;
                            isValid         = false;
                            invalidRows++;
                        }

                        if (courseWorksheet.Cells[i, 3].Value != null)
                        {
                            isem = Convert.ToInt16(courseWorksheet.Cells[i, 3].Value);
                            if (isem < 1)
                            {
                                tempProcessLog += ln + (string)courseWorksheet.Cells[i, 1].Value + " > in semesters must be between 0 and " + MAX_SEMS + ", " + isem + " given";
                                isValid         = false;
                                invalidRows++;
                            }

                            if (isem > tsem)
                            {
                                tempProcessLog += ln + (string)courseWorksheet.Cells[i, 1].Value + " > in semesters can't be > than total sems, " + isem + " given";
                                isValid         = false;
                                invalidRows++;
                            }

                            if (isem > MAX_SEMS)
                            {
                                tempProcessLog += ln + (string)courseWorksheet.Cells[i, 1].Value + " > max in semesters possible is " + MAX_SEMS + ", " + isem + " given";
                                isValid         = false;
                                invalidRows++;
                            }
                        }
                        else
                        {
                            tempProcessLog += ln + "empty value given for in semesters...'" + ln;
                            isValid         = false;
                            invalidRows++;
                        }
                        if (courseWorksheet.Cells[i, 4].Value != null)
                        {
                            if ((int)courseWorksheet.Cells[i, 4].Value < 1)
                            {
                                tempProcessLog += ln + "credits must be greater than 0";
                                isValid         = false;
                                invalidRows++;
                            }
                        }
                        else
                        {
                            tempProcessLog += ln + "empty value given for total credits...'" + ln;
                            isValid         = false;
                            invalidRows++;
                        }
                    }
                    catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException be)
                    {
                        invalidRows++;
                        isValid         = false;
                        tempProcessLog += ln + "In row [" + i + "] expecting numeric value, string given!";
                        LogWriter.WriteError("During course excel sheet validation", be.Message);
                    }

                    //Update output textbox
                    App.Current.Dispatcher.Invoke(new System.Action(() =>
                    {
                        txtOutput.AppendText(tempProcessLog);
                        txtOutput.ScrollToEnd();
                    }));

                    bgwValidate.ReportProgress(Convert.ToInt16(((i * 100) / rowCount)));
                    tempProcessLog = "";
                }
            }
            catch (System.IO.IOException ioe)
            {
                tempProcessLog += ln + "ERROR HANDLING FILE :(" + ln + "Please retry";
                LogWriter.WriteError("During course excel sheet validation", ioe.Message);
                isValid = false;
                return;
            }
            catch (databaseException)
            {
                tempProcessLog += ln + "ERROR OCCURED IN DATABASE OPERATION :(" + ln + "Please retry.";
                isValid         = false;
                return;
            }
            catch (Exception ex)
            {
                tempProcessLog += ln + "UNEXPECTED ERROR OCCURED :(" + ln + "Please retry.";
                LogWriter.WriteError("During course excel sheet validation", ex.Message);
                isValid = false;
                return;
            }
            finally
            {
                if (invalidRows > 0)
                {
                    tempProcessLog += ln + "There are total " + invalidRows + " errors.";
                    tempProcessLog += ln + "Took " + String.Format("{0:0.00}", (DateTime.Now - begin).TotalSeconds) + " seconds";
                    App.Current.Dispatcher.Invoke(new System.Action(() =>
                    {
                        txtOutput.AppendText(tempProcessLog);
                        txtOutput.ScrollToEnd();
                        progress.Value = 100;
                    }));
                }
                excelApp.Workbooks.Close();
            }
        }
Exemplo n.º 10
0
 public static void WriteToNotificationWindow(string message)
 {
     System.Windows.Application.Current.Dispatcher.Invoke(() => m_TbNotification.AppendText(message + "\r\n"));
     System.Windows.Application.Current.Dispatcher.Invoke(() => m_TbNotification.ScrollToEnd());
 }