Пример #1
0
        public void Track()
        {
            if (tracking)
            {
                throw new InvalidOperationException("Already tracking. Can't call track on a started tracker");
            }

            keyboardHook.HookActivated += KeyboardHook_HookActivated;
            keyboardHook.Hook();
        }
Пример #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // hotkey mode

            lblHotkeyMode.Text  = string.Format("Shortcut mode {0} ({1})", _hotkeyModeEnabled ? "activated" : "deactivated", this.ParentAgent.ToggleHotkeyModeKey);
            picHotkeyMode.Image = _hotkeyModeEnabled ? ImageResources.HotkeyModeEnabled : ImageResources.HotkeyModeDisabled;

            _keyboardHook.KeyDown += (ss, ee) => HandleHotkey((Keys)ee.KeyCode);
            _keyboardHook.KeyDownCancelOpportunity += (ss, ee) => ee.Cancel = _hotkeyModeEnabled;
            _keyboardHook.Hook();

            // setup Log grid

            using (var theme = new VisualStudio2012DarkTheme())
                gridLog.ThemeName = theme.ThemeName;

            gridLog.AllowAddNewRow       = false;
            gridLog.AllowDeleteRow       = false;
            gridLog.AllowEditRow         = false;
            gridLog.AllowAutoSizeColumns = true;
            gridLog.AllowColumnResize    = true;
            gridLog.ShowFilteringRow     = false;
            gridLog.ShowGroupPanel       = false;
            gridLog.AutoGenerateColumns  = true;
            gridLog.AutoSizeColumnsMode  = GridViewAutoSizeColumnsMode.Fill;

            gridLog.DataSource = _log;

            foreach (var column in gridLog.Columns)
            {
                column.IsVisible = false;
            }

            gridLog.Columns.Move(gridLog.Columns["Id"].Index, 0);
            gridLog.Columns["Id"].TextAlignment = ContentAlignment.MiddleCenter;
            gridLog.Columns["Id"].HeaderText    = "ID";
            gridLog.Columns["Id"].IsVisible     = true;
            gridLog.Columns["Id"].Width         = 20;

            gridLog.Columns.Move(gridLog.Columns["Timestamp"].Index, 1);
            gridLog.Columns["Timestamp"].TextAlignment = ContentAlignment.MiddleCenter;
            gridLog.Columns["Timestamp"].HeaderText    = "Time";
            gridLog.Columns["Timestamp"].IsVisible     = true;
            gridLog.Columns["Timestamp"].Width         = 48;
            gridLog.Columns["Timestamp"].FormatString  = "{0:HH:mm:ss}";

            gridLog.Columns.Move(gridLog.Columns["Distance"].Index, 2);
            gridLog.Columns["Distance"].TextAlignment = ContentAlignment.MiddleCenter;
            gridLog.Columns["Distance"].HeaderText    = "Distance";
            gridLog.Columns["Distance"].IsVisible     = true;
            gridLog.Columns["Distance"].Width         = 51;

            gridLog.Columns.Move(gridLog.Columns["Description"].Index, 3);
            gridLog.Columns["Description"].TextAlignment = ContentAlignment.MiddleCenter;
            gridLog.Columns["Description"].HeaderText    = "Description";
            gridLog.Columns["Description"].IsVisible     = true;
            gridLog.Columns["Description"].MinWidth      = 82;
            gridLog.Columns["Description"].AutoSizeMode  = BestFitColumnMode.DisplayedCells;

            gridLog.Columns.Move(gridLog.Columns["Severity"].Index, 4);
            gridLog.Columns["Severity"].TextAlignment = ContentAlignment.MiddleCenter;
            gridLog.Columns["Severity"].HeaderText    = "Severity";
            gridLog.Columns["Severity"].IsVisible     = true;
            gridLog.Columns["Severity"].MinWidth      = 48;
            gridLog.Columns["Severity"].AutoSizeMode  = BestFitColumnMode.DisplayedCells;

            gridLog.Columns.Move(gridLog.Columns["DistanceManualCorrection"].Index, 5);
            gridLog.Columns["DistanceManualCorrection"].TextAlignment = ContentAlignment.MiddleCenter;
            gridLog.Columns["DistanceManualCorrection"].HeaderText    = "Correction";
            gridLog.Columns["DistanceManualCorrection"].IsVisible     = true;
            gridLog.Columns["DistanceManualCorrection"].MinWidth      = 54;
            gridLog.Columns["DistanceManualCorrection"].AutoSizeMode  = BestFitColumnMode.DisplayedCells;

            gridLog.Columns.Move(gridLog.Columns["Comment"].Index, 6);
            gridLog.Columns["Comment"].TextAlignment = ContentAlignment.MiddleCenter;
            gridLog.Columns["Comment"].HeaderText    = "Comment";
            gridLog.Columns["Comment"].IsVisible     = true;
            gridLog.Columns["Comment"].AutoSizeMode  = BestFitColumnMode.DisplayedCells;
            gridLog.Columns["Comment"].WrapText      = true;

            gridLog.AutoSizeRows = true;
            gridLog.BestFitColumns();

            this.RegisterObserver(
                AgentBroker.Instance.ObserveOne <RoadEventData>(this.ParentAgent.Id, "DataSource")
                .ObserveOn(WindowsFormsSynchronizationContext.Current)
                .Subscribe(
                    data =>
            {
                _log.Insert(0, data);
                gridLog.Rows[0].IsSelected = true;
                gridLog.BestFitColumns();
            }));

            // load RoadEvent groups
            foreach (var roadEvent in this.ParentAgent.ReadRoadEventConfiguration())
            {
                var groupControl = new RoadEventGroupControl(roadEvent.RoadEventDataDisplayInfos);
                groupControl.RoadEventClicked +=
                    (ss, ee) =>
                {
                    if (this.ParentAgent.ProviderState >= ProviderState.StartedRecord)
                    {
                        var data = this.ParentAgent.CloneRoadEvent(ee.Value.RoadEventDataTemplate);

                        if (!ee.Value.ShowEditDialog || (ee.Value.ShowEditDialog && ShowEditLogDataDialog(data) == DialogResult.OK))
                        {
#pragma warning disable 4014
                            this.ParentAgent.OnRoadEvent(data, isNew: true);
#pragma warning restore 4014
                        }
                    }
                };

                pnlEvents.Controls.Add(groupControl);
            }

            // set enabled/disabled
            SetEnabledState(this.ParentAgent.ProviderState >= ProviderState.InitializedRecord);

            this.RegisterObserver(
                AgentBroker.Instance.ObserveOne <ProviderState>(this.ParentAgent.Id, "ProviderStateDataSource", ignoreAgentState: true)
                .ObserveOn(WindowsFormsSynchronizationContext.Current)
                .Subscribe(
                    async state =>
            {
                SetEnabledState(this.ParentAgent.ProviderState >= ProviderState.InitializedRecord);

                if (this.ParentAgent.ProviderState < ProviderState.InitializedRecord)
                {
                    SetHotkeyMode(false);
                }

                if (state <= ProviderState.InitializingRecord)
                {
                    _log.Clear();

                    var roadEventControlsToReset = pnlEvents.Controls.OfType <RoadEventGroupControl>()
                                                   .Where(currentControl => !currentControl.RoadEventGroup.Any(item => item.RoadEventDataTemplate.IsSnapshot))
                                                   .Where(control => control.ActiveRoadEvent != control.RoadEventGroup.First());

                    foreach (var roadEventInfo in roadEventControlsToReset)
                    {
                        roadEventInfo.SetOrToggleActiveRoadEvent(roadEventInfo.RoadEventGroup.First());
                    }
                }
                else if (state == ProviderState.StartedRecord)
                {
                    // write initial state of each road event groups, except those that are snapshots
                    var allRoadEventControls        = pnlEvents.Controls.OfType <RoadEventGroupControl>();
                    var noSnapshotRoadEventControls = allRoadEventControls.Where(currentControl => !currentControl.RoadEventGroup.Any(item => item.RoadEventDataTemplate.IsSnapshot));

                    foreach (var roadEventInfo in noSnapshotRoadEventControls)
                    {
                        var data = this.ParentAgent.CloneRoadEvent(roadEventInfo.ActiveRoadEvent.RoadEventDataTemplate);
                        await this.ParentAgent.OnRoadEvent(data, isNew: true, progress: 0);
                    }
                }
            }));
        }