Beispiel #1
0
        private void InitSystem()
        {
            this.Icon = BitmapFrame.Create(this.GetImageResourceStream("main.ico"));

            _uiState = SbmqSystem.UIState;
            RestoreWindowState();

            this.IsEnabled       = false;
            lbLoading.Visibility = System.Windows.Visibility.Visible;

            BackgroundWorker w = new BackgroundWorker();

            w.DoWork += (s, e) => {
                try {
                    _sys = SbmqSystem.Create();
                    _sys.ItemsChanged   += sys_ItemsChanged;
                    _sys.ErrorOccured   += _sys_ErrorOccured;
                    _sys.WarningOccured += _sys_WarningOccured;
                    _mgr = _sys.Manager;
                } catch (Exception ex) {
                    Dispatcher.Invoke(DispatcherPriority.Normal,
                                      new Action(() => { LogError("Failed to initialize System", ex, true); }));
                }
            };

            w.RunWorkerCompleted += (s, e) => {
                RestoreQueueButtonsState();
                this.IsEnabled       = true;
                lbLoading.Visibility = System.Windows.Visibility.Hidden;


                btnSendCommand.IsEnabled       = _sys.CanSendCommand;
                btnViewSubscriptions.IsEnabled = _sys.CanViewSubscriptions;

                lbItems.ItemsSource = _sys.Items;

                SetupContextMenu();

                UpdateNotifyIconText();

                if (_sys.Config.StartCount == 1)
                {
                    ShowConfigDialog();
                }
                else if (_sys.Config.VersionCheck.Enabled)
                {
                    if (_sys.Config.VersionCheck.LastCheck < DateTime.Now.AddDays(-14))
                    {
                        CheckIfLatestVersion(false);
                    }
                }

                UpdateTitle();

                _sys.StartMonitoring();
            };

            w.RunWorkerAsync();
        }
Beispiel #2
0
        private void RestartSystem()
        {
            _timer.Stop();

            if (_sys != null)
            {
                _sys.Manager.Terminate();
            }

            this.IsEnabled      = false;
            lbItems.ItemsSource = null;

            BackgroundWorker w = new BackgroundWorker();

            w.DoWork += (s, e) => {
                _sys = SbmqSystem.Create();
                _sys.ItemsChanged += MessageMgr_ItemsChanged;

                _mgr = _sys.Manager;
            };

            w.RunWorkerCompleted += (s, e) => {
                this.IsEnabled = true;
                RestoreMonitorQueueState();

                btnSendCommand.IsEnabled       = _sys.CanSendCommand;
                btnViewSubscriptions.IsEnabled = _sys.CanViewSubscriptions;

                lbItems.ItemsSource = _sys.Items;

                SetupContextMenu();

                timer_Tick(this, EventArgs.Empty);

                _timer.Interval = TimeSpan.FromMilliseconds(_sys.Config.MonitorInterval);
                _timer.Start();
            };

            w.RunWorkerAsync();
        }
Beispiel #3
0
        private void RestartSystem()
        {
            StopMonitoring();

            if (_sys != null)
            {
                _sys.Manager.Terminate();
            }

            this.IsEnabled      = false;
            lbItems.ItemsSource = null;

            BackgroundWorker w = new BackgroundWorker();

            w.DoWork += (s, e) => {
                _sys = SbmqSystem.Create();
                _sys.ItemsChanged += MessageMgr_ItemsChanged;

                _mgr = _sys.Manager;
            };

            w.RunWorkerCompleted += (s, e) => {
                this.IsEnabled = true;
                RestoreMonitorQueueState();

                btnSendCommand.IsEnabled       = _sys.CanSendCommand;
                btnViewSubscriptions.IsEnabled = _sys.CanViewSubscriptions;

                lbItems.ItemsSource = _sys.Items;

                SetupContextMenu();

                RestartMonitoring();
            };

            w.RunWorkerAsync();
        }
Beispiel #4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            List <Arg> args = ProcessArgs(e.Args);

            StartMinimized = args.Any(a => a.Type == ArgType.Minimized);

            _silent = args.Any(a => a.Type == ArgType.Silent);

            var arg = args.FirstOrDefault(a => a.Type == ArgType.Send);

            if (arg != null)
            {
                AttachConsole(-1);

                PrintHeader();

                string[] cmds = arg.Param.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                var sys = SbmqSystem.Create();
                try {
                    foreach (var cmd in cmds)
                    {
                        var itm = sys.SavedCommands.Items.FirstOrDefault(c => c.DisplayName == cmd);

                        if (itm != null)
                        {
                            Out(string.Format("Sending Command '{0}'...", cmd));
                            sys.SendCommand(itm.SentCommand.ConnectionStrings, itm.SentCommand.Queue, itm.SentCommand.Command);
                        }
                        else
                        {
                            Out(string.Format("No Command with name '{0}' found, exiting...", cmd));
                        }
                    }
                } finally {
                    sys.Manager.Terminate();
                }

                Application.Current.Shutdown(0);
                return;
            }

            if (args.Where(a => (int)a.Type < 20).Count() > 0)
            {
                AttachConsole(-1);
                PrintHeader();
                PrintHelp();

                Application.Current.Shutdown(0);
                return;
            }



            if (!args.Any(a => a.Type == ArgType.Force))
            {
                // Check if we are already running...
                Process currProc  = Process.GetCurrentProcess();
                Process existProc = Process.GetProcessesByName(currProc.ProcessName).Where(p => p.Id != currProc.Id).FirstOrDefault();
                if (existProc != null)
                {
                    try {
                        // Show the already started SBMQM
                        WindowTools.EnumWindows(new WindowTools.EnumWindowsProc((hwnd, lparam) => {
                            uint procId;
                            WindowTools.GetWindowThreadProcessId(hwnd, out procId);
                            if (procId == existProc.Id)
                            {
                                if (WindowTools.SendMessage(hwnd, ServiceBusMQManager.MainWindow.WM_SHOWWINDOW, 0, 0) == 1)
                                {
                                    return(false);
                                }
                            }
                            return(true);
                        }), 0);
                    } finally {
                        Application.Current.Shutdown();
                    }
                    return;
                }
            }


            base.OnStartup(e);
        }