Example #1
0
    public static void Main()
    {
        ConsoleCtrl cc = new ConsoleCtrl();
        cc.ControlEvent += new ConsoleCtrl.ControlEventHandler(MyHandler);

        Console.WriteLine("Enter 'E' to exit");

        Thread.Sleep(15000);  // sleep 15 seconds
    }
 private void Ctrl_Write(int value)
 {
     try
     {
         int           Line  = this.Invoke(() => ConsoleCtrl.GetLineIndexFromCharacterIndex(ConsoleCtrl.SelectionStart));
         int           start = this.Invoke(() => ConsoleCtrl.GetCharacterIndexFromLineIndex(Line));
         StringBuilder sb    = new StringBuilder();
         sb.AppendLine(value.ToString());
         this.Invoke(() =>
         {
             ConsoleCtrl.AppendText(sb.ToString());
             ConsoleCtrl.SelectionStart = ConsoleCtrl.Text.Length;
         });
     }
     catch (Exception)
     {
     }
 }
Example #3
0
        private void btnAtualizar_Click(object sender, EventArgs e)
        {
            try
            {
                Model.Console c = CarregarConsoleDoForm();

                ConsoleCtrl controlConsole = new ConsoleCtrl();

                if ((bool)controlConsole.BD('u', c))
                {
                    MessageBox.Show("Cadastro atualizado com sucesso!!");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERRO AO ATUALIZAR DADOS: " + ex.Message);
            }
        }
        private void CarregarListBoxConsoles()
        {
            try
            {
                ConsoleCtrl controlConsole = new ConsoleCtrl();

                Dictionary <Int64, Model.Console> mapaConsoles = (Dictionary <Int64, Model.Console>)controlConsole.BD('t', null);

                List <Model.Console> listaConsoles = mapaConsoles.Values.ToList <Model.Console>();

                ltbConsole.DisplayMember = "nome";
                ltbConsole.ValueMember   = "numero";

                ltbConsole.DataSource = listaConsoles;
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERRO AO CARREGAR LISTBOX CONSOLES: " + ex.Message);
            }
        }
        private void iMenuDeletar_Click(object sender, EventArgs e)
        {
            try
            {
                Int64 numero = Convert.ToInt64(dgvDados.SelectedRows[0].Cells[0].Value);

                ConsoleCtrl control = new ConsoleCtrl();

                if ((bool)control.BD('d', numero))
                {
                    MessageBox.Show("Cadastro deletado com sucesso!!");
                }

                CarregarGridDoBD("");
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERRO AO DELETAR CADASTRO: " + ex.Message);
            }
        }
 private void ExecuteCode(object sender, RoutedEventArgs e)
 {
     try
     {
         ConsoleCtrl.Clear();
         List <ErrorInfo> list = ErrorList.ItemsSource as List <ErrorInfo>;
         if (list.Count > 0)
         {
             StatusContent.Text = "在执行前请改正所有错误";
             return;
         }
         ConsoleTab.IsSelected = true;
         string         code = CodeEditor.Text;
         VirtualMachine vm   = new VirtualMachine();
         VMStartup      v    = new VMStartup(vm, new string(code.ToCharArray()), this);
         ConsoleThread = new Thread(v.Execute);
         ConsoleThread.Start();
     }
     catch (Exception) { }
 }
        private string Ctrl_Read()
        {
            try
            {
                KeydownHandled = false;
                ConsoleThread.Suspend();
                //等待回调
                //开线程,用suspend模拟中断?
                KeydownHandled = true;

                return(this.Invoke(() =>
                {
                    string str = ConsoleCtrl.GetLineText(ConsoleCtrl.LineCount - 2);
                    return str.Substring(0, str.Length - 2);
                }));
            }
            catch (Exception)
            {
                return("");
            }
        }
Example #8
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                Model.Console c = CarregarConsoleDoForm();

                ConsoleCtrl control = new ConsoleCtrl();

                //Linha trocada para que o processo seja feito no BD, e não mais no arquivo
                if ((bool)control.BD('i', c))
                {
                    MessageBox.Show("Cadastro efetuado com sucesso!!!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Cadastro não efetuado!!!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERRO: " + ex.Message);
            }
        }
Example #9
0
 public Core()
 {
     c_validation  = new CoreBasics.Validation();
     c_consoleCtrl = new ConsoleCtrl();
     c_webCtrl     = new WebCtrl();
 }
Example #10
0
 static bool ConsoleEventHandler(ConsoleCtrl.ConsoleEvent consoleEvent)
 {
     MainForm instance = MainForm.instance;
     if (instance == null || (instance.CheckProcessTerminate() && instance.CheckFileSave()))
         Application.Exit();
     return true;
 }
Example #11
0
        static void Main(string[] arguments)
        {
            consoleCtrl = new ConsoleCtrl();
            consoleCtrl.ControlEvent += new ConsoleCtrl.ControlEventHandler(ConsoleEventHandler);
            MainForm f = new MainForm(arguments);

            if (f.exitProgram)
                return;

            if (!f.viewdiff && f.reportKind == MainForm.ReportKind.NoReport && f.processFileName == null)
            {
                Application.Run(f);
            }
            else
            {
                try
                {
                    ReportForm _MgrForm = new ReportForm(f);
                    if (!f.noUI)
                    {
                        Application.Run(_MgrForm);
                    }
                }
                catch
                {
                    Application.Exit();
                }
            }
        }
Example #12
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            try
            {
                string instanceName = @"Local\{7A97254E-AFC8-4C0C-A6DB-C6DA0BFB463F}";
                using (new SingleInstance(instanceName))
                {
                    Log.Logger = new LoggerConfiguration()
                                 .ReadFrom.AppSettings()
                                 .CreateLogger();

                    if (Environment.UserInteractive)
                    {
                        if (args.Contains("--migrate"))
                        {
                            var runner = new MahloService.DbMigrations.Runner(new DbLocal(new DbConnectionFactory.Factory()));
                            runner.MigrateToLatest();
                            Environment.Exit(0);
                        }

                        if (args.Contains("--install"))
                        {
                            var runner = new MahloService.DbMigrations.Runner(new DbLocal(new DbConnectionFactory.Factory()));
                            runner.MigrateToLatest();
                            ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                            new ServiceController(StrMahloMapper).Start();
                            Environment.Exit(0);
                        }

                        if (args.Contains("--uninstall"))
                        {
                            ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                            Environment.Exit(0);
                        }

                        bool shouldSimulate = args.Contains("--simulate");
                        if (shouldSimulate)
                        {
                            Application.EnableVisualStyles();
                            Application.SetCompatibleTextRenderingDefault(false);
                            using (new Control()) { }
                            using (var container = InitializeContainer(WindowsFormsSynchronizationContext.Current, shouldSimulate))
                            {
                                ICarpetProcessor carpetProcessor = container.GetInstance <ICarpetProcessor>();
                                carpetProcessor.Start();
                                Application.Run(container.GetInstance <FormSim>());
                                container.GetInstance <IProgramState>().Save();
                                carpetProcessor.Stop();
                            }
                        }
                        else
                        {
                            ApplicationContext appContext = new ApplicationContext();
                            WindowsFormsSynchronizationContext.AutoInstall = false;

                            WindowsFormsSynchronizationContext syncContext = new WindowsFormsSynchronizationContext();
                            SynchronizationContext.SetSynchronizationContext(syncContext);

                            using (var consoleCtrl = new ConsoleCtrl())
                                using (var container = InitializeContainer(syncContext, shouldSimulate))
                                {
                                    consoleCtrl.ControlEvent += (sender, e) =>
                                    {
                                        Application.Exit();
                                        e.Result = true;
                                    };

                                    Log.Logger.Information("Application started");
                                    ICarpetProcessor carpetProcessor = container.GetInstance <ICarpetProcessor>();
                                    carpetProcessor.Start();
                                    Application.Run(appContext);
                                    container.GetInstance <IProgramState>().Save();
                                    carpetProcessor.Stop();
                                    Log.Logger.Information("Application stopped");
                                }
                        }
                    }
                    else
                    {
                        service = new Service();
                        ServiceBase.Run(service);
                    }
                }
            }
            catch (SingleInstanceException)
            {
                Environment.Exit(1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), Application.ProductName);
                Environment.Exit(1);
            }
        }
Example #13
0
 public static void MyHandler(ConsoleCtrl.ConsoleEvent consoleEvent)
 {
     Console.WriteLine("Event: {0}", consoleEvent);
 }
Example #14
0
        private void Ctrl_PreKeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (KeydownHandled)
                {
                    e.Handled = true;
                    return;
                }
                int Line  = ConsoleCtrl.GetLineIndexFromCharacterIndex(ConsoleCtrl.SelectionStart);
                int start = ConsoleCtrl.GetCharacterIndexFromLineIndex(Line);
                if (e.Key == Key.Up || e.Key == Key.Down)
                {
                    e.Handled = true;
                    return;
                }
                else if (e.Key == Key.Left)
                {
                    //判断是否最后一行
                    if (start == ConsoleCtrl.SelectionStart)
                    {
                        e.Handled = true;
                    }
                    return;
                }
                if (Line != ConsoleCtrl.LineCount - 1)
                {
                    e.Handled = true;
                    return;
                }
                if (Key.Enter == e.Key)
                {
                    ConsoleThread.Resume();
                    return;
                }

                /*
                 * switch (e.Key)
                 * {
                 *  case Key.NumPad0:
                 *  case Key.NumPad1:
                 *  case Key.NumPad2:
                 *  case Key.NumPad3:
                 *  case Key.NumPad4:
                 *  case Key.NumPad5:
                 *  case Key.NumPad6:
                 *  case Key.NumPad7:
                 *  case Key.NumPad8:
                 *  case Key.NumPad9:
                 *      string res = Convert.ToString(e.Key - Key.NumPad0);
                 *      ConsoleCtrl.SelectionStart++;
                 *      string text = ConsoleCtrl.Text;
                 *      ConsoleCtrl.Text = text.Substring(0, ConsoleCtrl.SelectionStart - 2) + res + text.Substring(ConsoleCtrl.SelectionStart - 1);
                 *      break;
                 *  case Key.D0:
                 *  case Key.D1:
                 *  case Key.D2:
                 *  case Key.D3:
                 *  case Key.D4:
                 *  case Key.D5:
                 *  case Key.D6:
                 *  case Key.D7:
                 *  case Key.D8:
                 *  case Key.D9:
                 *      ConsoleCtrl.AppendText(Convert.ToString(e.Key - Key.D0));
                 *      e.Handled = true;
                 *      break;
                 * }
                 */
            }
            catch (Exception) { }
        }