コード例 #1
0
        public MainWindow()
        {
            AppDomain.CurrentDomain.UnhandledException += (o, e) =>
            {
                Console.WriteLine("Error: " + e.ExceptionObject.ToString());
                MessageWindow.Show(this, Strings.Error, e.ExceptionObject.ToString());
            };

            UICulture.Initialize();
            UICulture.UICultureChanged += new EventHandler(UICulture_UICultureChanged);

            ConsoleWriter.Initialize();

            m_implementation = new ViewerImplementation(this);

            m_implementation.ProtocolChanged += new EventHandler(MainWindow_ProtocolChanged);
            m_implementation.NetworkLogChanged += new EventHandler(MainWindow_NetworkLogChanged);

            InitializeComponent();

            App.InitializeConsole(this);

            // Perform operations that alter UI here
            {
                // Use Minimized as special value
                var stateNotSet = WindowState.Minimized;
                var state = Configuration.GetValue("Window State", stateNotSet);

                if (state != WindowState.Maximized)
                {
                    var screenHeight = SystemParameters.PrimaryScreenHeight;
                    var screenWidth = SystemParameters.PrimaryScreenWidth;
                    var height = Configuration.GetValue("Window Height", this.Height);
                    var width = Configuration.GetValue("Window Width", this.Width);

                    if (width / screenWidth > 0.8)
                        width = screenWidth * 0.8;

                    if (height / screenHeight > 0.8)
                        height = screenHeight * 0.8;

                    this.Width = width;
                    this.Height = height;

                    var left = Math.Max(Configuration.GetValue("Window Left", this.Left), 0.0);
                    var top = Math.Max(Configuration.GetValue("Window Top", this.Top), 0.0);

                    if (left != 0.0 && top != 0.0)
                    {
                        if (left + width > screenWidth)
                            left = screenWidth - width;

                        if (top + height > screenHeight)
                            top = screenHeight - top;

                        this.Left = left;
                        this.Top = top;
                    }
                }

                if (state != stateNotSet)
                    this.WindowState = state;

                int val = Configuration.GetValue("Number of Views", 2);
                this.SetNViews(val);

                var result = Configuration.GetValue("Vertical Splitter", (double[])null);
                if (result != null && result.Length == 2)
                {
                    this.VerticalGrid.RowDefinitions[1].Height = new GridLength(result[0], GridUnitType.Star);
                    this.VerticalGrid.RowDefinitions[2].Height = new GridLength(result[1], GridUnitType.Star);
                }

                InitializeSkins();
            }

            // Command Bindings
            this.CommandBindings.AddRange(new[] {
                new CommandBinding(ApplicationCommands.Close, ApplicationClose_Executed),
                new CommandBinding(ApplicationCommands.Open, ApplicationOpen_Executed),
                new CommandBinding(NetworkLogViewerCommands.OpenConsole, OpenConsole_Executed),
                new CommandBinding(NetworkLogViewerCommands.CloseFile, CloseFile_Executed, (o, e) =>
                {
                    e.CanExecute = this.CurrentLog != null;
                    e.Handled = true;
                }),
                new CommandBinding(NetworkLogViewerCommands.GoToPacketN, GoToPacketN_Executed, CanSearch),
                new CommandBinding(NetworkLogViewerCommands.NextError, NextError_Executed, CanSearch),
                new CommandBinding(NetworkLogViewerCommands.NextUndefinedParser, NextUndefinedParser_Executed, CanSearch),
                new CommandBinding(NetworkLogViewerCommands.NextUnknownOpcode, NextUnknownOpcode_Executed, (o, e) =>
                {
                    CanSearch(o, e);

                    if (e.CanExecute)
                        e.CanExecute = this.CurrentProtocol != null && this.CurrentProtocol.OpcodesEnumType != null;
                }),
                new CommandBinding(NetworkLogViewerCommands.Search, Search_Executed, CanSearch),
                new CommandBinding(NetworkLogViewerCommands.SearchUp, SearchUp_Executed, CanSearch),
                new CommandBinding(NetworkLogViewerCommands.SearchDown, SearchDown_Executed, CanSearch),
            });

            // Key Bindings
            this.InputBindings.AddRange(new[] {
                new KeyBinding(ApplicationCommands.Close, Key.X, ModifierKeys.Alt),
                //new KeyBinding(ApplicationCommands.Open, (KeyGesture)ApplicationCommands.Open.InputGestures[0]),
                new KeyBinding(NetworkLogViewerCommands.OpenConsole, Key.F12, ModifierKeys.None),
            });

            // Background Workers
            this.ui_loadingWorker = new BackgroundWorker()
            {
                WorkerSupportsCancellation = true
            };
            this.ui_loadingWorker.DoWork += new DoWorkEventHandler(this.ui_loadingWorker_DoWork);
            this.ui_loadingWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.ui_loadingWorker_RunWorkerCompleted);

            this.ui_readingWorker = new BackgroundWorker()
            {
                WorkerSupportsCancellation = true
            };
            this.ui_readingWorker.DoWork += new DoWorkEventHandler(this.ui_readingWorker_DoWork);
            this.ui_readingWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.ui_readingWorker_RunWorkerCompleted);

            ui_savingWorker = new BackgroundWorker()
            {
                WorkerSupportsCancellation = true,
                WorkerReportsProgress = true
            };
            ui_savingWorker.DoWork += new DoWorkEventHandler(ui_savingWorker_DoWork);
            ui_savingWorker.ProgressChanged += new ProgressChangedEventHandler(ui_savingWorker_ProgressChanged);
            ui_savingWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ui_savingWorker_RunWorkerCompleted);

            ui_searchWorker = new BackgroundWorker()
            {
                WorkerSupportsCancellation = true,
                WorkerReportsProgress = true
            };
            ui_searchWorker.DoWork += new DoWorkEventHandler(ui_searchWorker_DoWork);
            ui_searchWorker.ProgressChanged += new ProgressChangedEventHandler(ui_searchWorker_ProgressChanged);
            ui_searchWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ui_searchWorker_RunWorkerCompleted);

            ui_lvPackets.ItemsSource = m_implementation.m_items;

            Console.WriteLine("MainWindow initialized.");
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of <see cref="NetworkLogViewer.ViewerItemCollection"/> class.
 /// </summary>
 public ViewerItemCollection(ViewerImplementation viewer)
 {
     m_list   = new List <ViewerItem>();
     m_viewer = viewer;
 }