예제 #1
0
        private void toolStripMenuItemAddStage_Click(object sender, EventArgs e)
        {
            string assemblyName = Path.Combine(Application.StartupPath, "Stage.dll");
            IEntry instance     = ApplicationDispatcher.GetInstance(assemblyName, new String[] { "" });
            Form   objForm      = instance.GetSearchDialog(null);

            if (objForm.ShowDialog() == DialogResult.OK)
            {
                var objForm1 = objForm as frmBase;
                if (objForm1 != null)
                {
                    foreach (DataGridViewRow item in objForm1.SelectedRows())
                    {
                        StageAllocationCalcEntity entity = new StageAllocationCalcEntity();
                        entity.StageCode = ConvertUtil.ToString(item.Cells["stageCodeColumn"].Value);
                        entity.StageName = ConvertUtil.ToString(item.Cells["stageNameColumn"].Value);
                        entity.Percent   = ConvertUtil.ToDouble(item.Cells["percentColumn"].Value);
                        entity.Worth     = stageCalcTabControl1.Worth * entity.Percent / 100;

                        if (!string.IsNullOrEmpty(entity.StageCode))
                        {
                            this.stageCalcTabControl1.AddCalcControl(entity);
                            break;
                        }
                    }
                }
            }
        }
예제 #2
0
        private void MenuItemChanged()
        {
            UserMenuItem menuItem = Core.CoreData[CoreDataType.MenuItemSelected] as UserMenuItem;

            if (!string.IsNullOrEmpty(menuItem.Shell))
            {
                List <DockContent> contents = null;
                if (!_openedContents.ContainsKey(menuItem.Shell))
                {
                    //if not exists
                    string assemblyName = Path.Combine(Application.StartupPath, menuItem.Shell);
                    IEntry instance     = ApplicationDispatcher.GetInstance(assemblyName, new String[] { "" });
                    contents = instance.GetContents(null);
                    _openedContents.Add(menuItem.Shell, contents);
                }

                if (_openedContents.ContainsKey(menuItem.Shell))
                {
                    //if exists
                    contents = _openedContents[menuItem.Shell];
                }

                if (contents != null)
                {
                    foreach (var item in contents)
                    {
                        item.Show(this.dockPanel);
                    }
                }
            }
        }
예제 #3
0
        private void btnProjectLeader2_Click(object sender, EventArgs e)
        {
            string assemblyName = Path.Combine(Application.StartupPath, "Worker.dll");
            IEntry instance     = ApplicationDispatcher.GetInstance(assemblyName, new String[] { "" });
            Form   objForm      = instance.GetSearchDialog(null);

            if (objForm.ShowDialog() == DialogResult.OK)
            {
                var objForm1 = objForm as frmBase;
                if (objForm1 != null)
                {
                    foreach (DataGridViewRow item in objForm1.SelectedRows())
                    {
                        WorkerEntity entity = new WorkerEntity();
                        entity.WorkerCode = ConvertUtil.ToString(item.Cells["workerCodeColumn"].Value);
                        entity.WorkerName = ConvertUtil.ToString(item.Cells["workerNameColumn"].Value);

                        if (!string.IsNullOrEmpty(entity.WorkerCode))
                        {
                            this.txtProjectLeader2.Text = entity.WorkerName;
                            this.txtProjectLeader2.Tag  = entity.WorkerCode;
                            break;
                        }
                    }
                }
            }
        }
 public ProductApplicationService(ISelectInvoiceService selectInvoiceService,
                                  IConfidentialInvoiceService confidentialInvoiceWebService,
                                  IBusinessLoansService businessLoansService)
 {
     _dispatcher = new ApplicationDispatcher(selectInvoiceService, confidentialInvoiceWebService,
                                             businessLoansService);
 }
        public void WhenAddInvoke_ShouldExecuteImmediately()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.Invoke(actionTester.TestAction);
            actionTester.WasCalled.Should().BeTrue();
        }
        public void GivenException_WhenInvoke_ShouldLogInnerException()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTesterWithException();

            Action act = () => testee.Invoke(actionTester.TestAction);

            act.ShouldThrow <Exception>().Where(e => e.Message.Contains("originExceptionTest"));
        }
예제 #7
0
        public void AddBinding <TSource>(BindingList <TSource> source)
            where TSource : IMenuOption
        {
            source.ListChanged += (object sender, ListChangedEventArgs e)
                                  => ApplicationDispatcher.Invoke(() => BindingChanged(e, source));
            var menuItems = source.Select(MapToItem).ToArray();

            this.DropDownItems.AddRange(menuItems);
        }
        public void WhenAddNegativeDelayedAction_ShouldExecuteImmediately()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.AddDelayedAction(-10, actionTester.TestAction);
            testee.ExecuteInvokes();

            actionTester.WasCalled.Should().BeTrue();
        }
예제 #9
0
 private void SetTimeout(TimeSpan delay, Action action)
 {
     _timer?.Stop();
     _timer = new System.Timers.Timer
     {
         AutoReset = false,
         Interval  = delay.TotalMilliseconds
     };
     _timer.Elapsed += (sender, e) => ApplicationDispatcher.BeginInvoke(action);
     _timer.Start();
 }
        public void WhenAddNestedAction_ShouldWork()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.AddActionAfterPolls(1, () => testee.AddActionAfterPolls(1, actionTester.TestAction));

            testee.ExecuteInvokes();
            actionTester.WasCalled.Should().BeFalse();
            testee.ExecuteInvokes();
            actionTester.WasCalled.Should().BeTrue();
        }
        public void WhenAddMultipleActionsWithRemainingPolls_ShouldExecuteInRightOrder()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new OrderedActionTester();

            testee.AddActionAfterPolls(1, actionTester.TestAction2);
            testee.AddActionAfterPolls(1, actionTester.TestAction1);

            testee.ExecuteInvokes();

            actionTester.FirstCalledAction.Should().Be(2, "TestAction2 was added first");
        }
        public void WhenAddActions_ShouldExecuteInRightOrder()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new OrderedActionTester();

            testee.AddActionAfterPolls(1, actionTester.TestAction2);
            testee.AddActionAfterPolls(1, actionTester.TestAction1);

            testee.ExecuteInvokes();

            actionTester.FirstCalledAction.Should().Be(2);
        }
예제 #13
0
 private void DoButton3Proc()
 {
     try {
         ApplicationDispatcher.BeginInvoke(() => OutputText.Value = "Action 3 background.");
         // continue the long operation asynchronous.
         Thread.Sleep(5000);
     }
     finally {
         BusyManager.Instance.EndAsync(Button3Action);
         ApplicationDispatcher.BeginInvoke(() => OutputText.Value = "Action 3 done.");
     }
 }
        public void GivenSimpleAction_WhenInvokedTwice_ShouldExecuteJustOnce()
        {
            var testee = new ApplicationDispatcher();

            var parallelActions =
                (from exec in Enumerable.Range(0, 100)
                 let at = new CountActionTester()
                          select new { Tester = at, Action = (Action)(() => testee.Invoke(at.TestAction)) }).ToArray();

            Parallel.Invoke(parallelActions.Select(a => a.Action).ToArray());

            parallelActions.Any(a => a.Tester.ActionCalled != 1).Should().BeFalse();
        }
        public void TestActionWithArguments()
        {
            var testee = new ApplicationDispatcher();

            object receivedArgument = null;

            testee.Invoke(x => receivedArgument = x, "test");
            testee.ExecuteInvokes();

            var receivedString = receivedArgument as string;

            receivedString.Should().Be("test");
        }
        public void WhenAddActionWithRemainingPolls_ShouldExecuteOnRightPollCount()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.AddActionAfterPolls(2, actionTester.TestAction);

            testee.ExecuteInvokes();
            actionTester.WasCalled.Should().BeFalse();

            testee.ExecuteInvokes();
            actionTester.WasCalled.Should().BeTrue();
        }
 public void NotifyCollectionChanged()
 {
     //OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
     if (_lastDispatcherOperation != null)
     {
         //Pending: The operation is pending and is still in the System.Windows.Threading.Dispatcher queue.
         if (_lastDispatcherOperation.Status == DispatcherOperationStatus.Pending)
         {
             return;
         }
     }
     _lastDispatcherOperation = ApplicationDispatcher.BeginInvoke(DispatcherPriority.Background, OnCollectionChanged, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
 }
예제 #18
0
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var handler = PropertyChanged;

            if (handler == null)
            {
                return;
            }

            ApplicationDispatcher.Invoke(() =>
                                         handler(this, new PropertyChangedEventArgs(propertyName))
                                         );
        }
예제 #19
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ApplicationDispatcher.Configure();
            Startup(new ExecutionParameters(args));

            var navigator = IoCConfig.Container.GetInstance <IViewNavigator>();
            var mainView  = navigator.Get <MainViewModel>() as Form;

            Application.Run(mainView);
            Log.CloseAndFlush();
        }
        public void WhenClearActions_ShouldExecuteNothing()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.AddDelayedAction(5, actionTester.TestAction);
            testee.AddActionAfterPolls(1, actionTester.TestAction);

            testee.CancellAll();
            Thread.Sleep(25);
            testee.ExecuteInvokes();

            actionTester.WasCalled.Should().BeFalse();
        }
        public void WhenAddMixedActions_AfterPoll_ShouldExecuteAll()
        {
            var testee = new ApplicationDispatcher();

            var action1 = new ActionTester();
            var action2 = new ActionTester();

            testee.AddDelayedAction(-1, action1.TestAction);
            testee.AddActionAfterPolls(1, action2.TestAction);

            testee.ExecuteInvokes();

            action1.WasCalled.Should().BeTrue();
            action2.WasCalled.Should().BeTrue();
        }
        public void WhenAddDelayedAction_ShouldExecuteDelayed()
        {
            var testee       = new ApplicationDispatcher();
            var actionTester = new ActionTester();

            testee.AddDelayedAction(20, actionTester.TestAction);
            testee.ExecuteInvokes();

            actionTester.WasCalled.Should().BeFalse();

            Thread.Sleep(25);
            testee.ExecuteInvokes();

            actionTester.WasCalled.Should().BeTrue();
        }
예제 #23
0
        //Helper method that executes the Pressed or Released event for a button on the UI thread.
        private void ExecuteButtonChangedEvent(ControllerButtons button, bool isPressed)
        {
            ButtonEventArgs eventArgs = new ButtonEventArgs()
            {
                AffectedButton = button
            };

            if (isPressed && ButtonPressed != null)
            {
                ApplicationDispatcher.Invoke(delegate { ButtonPressed(this, eventArgs); });
            }
            else if (!isPressed && ButtonReleased != null)
            {
                ApplicationDispatcher.Invoke(delegate { ButtonReleased(this, eventArgs); });
            }
        }
        public void WhenAddMultipleActionsWithDifferentDelays_ShouldExecuteInRightOrder()
        {
            var testee  = new ApplicationDispatcher();
            var action1 = new ActionTester();
            var action2 = new ActionTester();

            testee.AddDelayedAction(-1, action1.TestAction);
            testee.AddDelayedAction(5, action2.TestAction);

            testee.ExecuteInvokes();
            action1.WasCalled.Should().BeTrue();
            action2.WasCalled.Should().BeFalse();

            Thread.Sleep(25);
            testee.ExecuteInvokes();
            action2.WasCalled.Should().BeTrue();
        }
예제 #25
0
        public async Task Load()
        {
            try
            {
                this.Loading = true;
                var users = await _roleRepository.GetAll();

                var mappedRoles = users.Select(_mapper.Map <RoleListItemDto>).ToList();
                ApplicationDispatcher.Invoke(() => Roles.AddRange(mappedRoles));
            }
            catch (Exception ex)
            {
                _messageDialog.ShowError(title: General.ErrorLoadingRolesTitle, message: ex.Message);
            }
            finally
            {
                this.Loading = false;
            }
        }
예제 #26
0
        public SscOperations(ISsmsOperations ssmsOperations,
            ApplicationDispatcher dispatcher, 
            ICredentialsManager credentialsManager,
            IDialogController dialogController,
            SscEndpoints sscEndpoints,
            IFavoriteScriptsStore favoriteStore)
        {
            m_SsmsOperations = ssmsOperations;
            m_Dispatcher = dispatcher;
            m_CredentialsManager = credentialsManager;
            m_DialogController = dialogController;
            m_SscEndpoints = sscEndpoints;
            m_FavoriteStore = favoriteStore;

            #if DEBUG
            //Trust all SSL issues when debugging. Obviously this is terrible as we are now susceptible to MITM attacks.
            ServicePointManager.ServerCertificateValidationCallback =
                ((sender, certificate, chain, sslPolicyErrors) => true);
            #endif
        }
        internal static ApplicationDispatcher GetApplicationDispatcher([NotNull] Dispatcher dispatcher)
        {
            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }
            IDispatcher wrapper;

            if (s_Map.TryGetValue(dispatcher, out wrapper))
            {
                if (wrapper is ApplicationDispatcher)
                {
                    return((ApplicationDispatcher)wrapper);
                }
                s_Map.Remove(dispatcher);                 //remove the existing wrapper, to create an ApplicationDispatcher
            }
            wrapper = new ApplicationDispatcher(dispatcher);
            s_Map.Add(dispatcher, wrapper);
            return((ApplicationDispatcher)wrapper);
        }
예제 #28
0
        private void btnProject_Click(object sender, EventArgs e)
        {
            string assemblyName = Path.Combine(Application.StartupPath, "Project.dll");
            IEntry instance     = ApplicationDispatcher.GetInstance(assemblyName, new String[] { "" });
            Form   objForm      = instance.GetSearchDialog(null);

            if (objForm.ShowDialog() == DialogResult.OK)
            {
                var objForm1 = objForm as frmBase;
                if (objForm1 != null)
                {
                    foreach (DataGridViewRow item in objForm1.SelectedRows())
                    {
                        ProjectEntity entity = new ProjectEntity();
                        entity.ProjectCode = ConvertUtil.ToString(item.Cells["projectCodeColumn"].Value);
                        entity.ProjectName = ConvertUtil.ToString(item.Cells["projectNameColumn"].Value);

                        if (!string.IsNullOrEmpty(entity.ProjectCode))
                        {
                            this.txtProjectName.Text = entity.ProjectName;
                            this.txtProjectName.Tag  = entity.ProjectCode;

                            // 查询该项目的计算产值记录
                            ProjectAllocationCalcManager manager = new ProjectAllocationCalcManager();
                            ProjectAllocationCalcEntity  projectAllocationCalcEntity = manager.GetProjectAllocationCalcEntity(OnProgressChanged, entity.ProjectCode);

                            // 如果没有找到的话
                            if (projectAllocationCalcEntity == null)
                            {
                                projectAllocationCalcEntity             = new ProjectAllocationCalcEntity();
                                projectAllocationCalcEntity.ProjectCode = entity.ProjectCode;
                                projectAllocationCalcEntity.ProjectName = entity.ProjectName;
                                projectAllocationCalcEntity.Worth       = 0.0;
                            }
                            this.ProjectAllocationCalcEntity = projectAllocationCalcEntity;
                            break;
                        }
                    }
                }
            }
        }
예제 #29
0
        public SscOperations(ISsmsOperations ssmsOperations,
                             ApplicationDispatcher dispatcher,
                             ICredentialsManager credentialsManager,
                             IDialogController dialogController,
                             SscEndpoints sscEndpoints,
                             IFavoriteScriptsStore favoriteStore)
        {
            m_SsmsOperations     = ssmsOperations;
            m_Dispatcher         = dispatcher;
            m_CredentialsManager = credentialsManager;
            m_DialogController   = dialogController;
            m_SscEndpoints       = sscEndpoints;
            m_FavoriteStore      = favoriteStore;


#if DEBUG
            //Trust all SSL issues when debugging. Obviously this is terrible as we are now susceptible to MITM attacks.
            ServicePointManager.ServerCertificateValidationCallback =
                ((sender, certificate, chain, sslPolicyErrors) => true);
#endif
        }
		public static void ContinueWithUIDispatcher(this Task task, Action<Task> continuationAction) {
			task.ContinueWith(task1 => { ApplicationDispatcher.BeginInvoke(continuationAction, task1); });
		}
예제 #31
0
        //The entry point to the thread that listens for changes in Xbox controllers attached to the computer.
        private void ControllerListenerThread()
        {
            //Stores the previous state of the gamepad for comparison against the new state.
            GamePadState lastState = GamePad.GetState(PlayerIndex.One);
            //A dictionary of each controller button and whether or not it has changed to pressed or released.
            Dictionary <ControllerButtons, bool?> buttonStates = new Dictionary <ControllerButtons, bool?>();

            // ReSharper disable once NotAccessedVariable
            Timer           disconnectTimer = null;
            ConnectionState connState;

            if (lastState.IsConnected)
            {
                connState = ConnectionState.Connected;
            }
            else
            {
                connState = ConnectionState.InitDisconnect;
            }

            //While this separate worker thread is running...
            while (IsListeningThreadRunning)
            {
                //Sleep for whatever listener sleep delay is so the UI thread isn't flooded with events.
                Thread.Sleep(_listenerSleepDelay);

                //Get the current gamepad state.
                GamePadState currentState = GamePad.GetState(PlayerIndex.One);

                //Detect if the controller has been disconnected or was never connected since the listening thread
                //was started. This can save some troubleshooting headaches.
                switch (connState)
                {
                case ConnectionState.Connected:
                    //Controller is connected since the last call to get state. Make sure it is still connected.
                    if (!currentState.IsConnected)
                    {
                        //Controller seems to have been disconnected.
                        connState = ConnectionState.InitDisconnect;

                        //Instantiate the disconnect timer. If more than 5 seconds passes since the controller was
                        //disconnected, the ControllerDisconnected event will be fired.
                        disconnectTimer = new Timer(delegate
                        {
                            //Execution here means 5 seconds have passed. If connState is still set to disconnected,
                            //the controller wasn't found in 5 seconds.
                            // ReSharper disable once AccessToModifiedClosure
                            if (connState == ConnectionState.InitDisconnect && ControllerDisconnected != null)
                            {
                                connState = ConnectionState.FullDisconnect;
                                ApplicationDispatcher.Invoke(
                                    delegate { ControllerDisconnected(this, EventArgs.Empty); });
                            }

                            //After the timer executes, set its value back to null.
                            disconnectTimer = null;
                        }, null, 2000, Timeout.Infinite);
                    }
                    break;

                case ConnectionState.InitDisconnect:
                    //The controller was disconnected since the last call to get state, and a timer thread has been
                    //initiated. Check if the controller has been found since then.
                    if (currentState.IsConnected)
                    {
                        //The controller was found again. Change connection state to connected so when the timer
                        //finishes, it won't fire the ControllerDisconnected event. Also note that I won't fire
                        //the ControllerReconnected event because the 5 seconds of disconnection did not pass. This
                        //is so clients are not alerted of a disconnect that was really just a small "hiccup" in
                        //the connection.
                        connState = ConnectionState.Connected;
                    }
                    //Controller has still not been found. Sleep again.
                    continue;

                case ConnectionState.FullDisconnect:
                    //The controller was fully disconnected, and the ControllerDisconnected event was fired. Just
                    //keep checking for reconnection infinitely.
                    if (currentState.IsConnected)
                    {
                        //Controller reconnected.
                        connState = ConnectionState.Connected;
                        //Fire the ControllerReconnected event.
                        if (ControllerReconnected != null)
                        {
                            ApplicationDispatcher.Invoke(
                                delegate { ControllerReconnected(this, EventArgs.Empty); });
                        }
                    }
                    else
                    {
                        continue;     //Sleep again.
                    }
                    break;
                }

                //Check if the actual state of the controller has changed since the last call to GetState. If it hasn't
                //changed, make the thread sleep again. Additionally, if the controller isn't connected, just sleep.
                if (currentState.PacketNumber == lastState.PacketNumber)
                {
                    continue;
                }

                //Store the current pressed, released or no change values of each button in the dictionary. This helps
                //reduce the amount of repetitive, copy pasted code.
                buttonStates[ControllerButtons.A] = CompareButtonStates(lastState.Buttons.A, currentState.Buttons.A);
                buttonStates[ControllerButtons.B] = CompareButtonStates(lastState.Buttons.B, currentState.Buttons.B);
                buttonStates[ControllerButtons.X] = CompareButtonStates(lastState.Buttons.X, currentState.Buttons.X);
                buttonStates[ControllerButtons.Y] = CompareButtonStates(lastState.Buttons.Y, currentState.Buttons.Y);

                buttonStates[ControllerButtons.Start]         = CompareButtonStates(lastState.Buttons.Start, currentState.Buttons.Start);
                buttonStates[ControllerButtons.Back]          = CompareButtonStates(lastState.Buttons.Back, currentState.Buttons.Back);
                buttonStates[ControllerButtons.RightShoulder] = CompareButtonStates(lastState.Buttons.RightShoulder, currentState.Buttons.RightShoulder);
                buttonStates[ControllerButtons.LeftShoulder]  = CompareButtonStates(lastState.Buttons.LeftShoulder, currentState.Buttons.LeftShoulder);

                buttonStates[ControllerButtons.Guide]      = CompareButtonStates(lastState.Buttons.Guide, currentState.Buttons.Guide);
                buttonStates[ControllerButtons.RightStick] = CompareButtonStates(lastState.Buttons.RightStick, currentState.Buttons.RightStick);
                buttonStates[ControllerButtons.LeftStick]  = CompareButtonStates(lastState.Buttons.LeftStick, currentState.Buttons.LeftStick);

                buttonStates[ControllerButtons.DPadUp]    = CompareButtonStates(lastState.DPad.Up, currentState.DPad.Up);
                buttonStates[ControllerButtons.DPadDown]  = CompareButtonStates(lastState.DPad.Down, currentState.DPad.Down);
                buttonStates[ControllerButtons.DPadLeft]  = CompareButtonStates(lastState.DPad.Left, currentState.DPad.Left);
                buttonStates[ControllerButtons.DPadRight] = CompareButtonStates(lastState.DPad.Right, currentState.DPad.Right);

                //Loop through the dictionary calling the button pressed or released events as necessary for buttons.
                foreach (var keyValPair in buttonStates)
                {
                    //A value of true for the keyValPair means the button is pressed, false means it has been released,
                    //and null means there has been no change.
                    if (keyValPair.Value != null)
                    {
                        ExecuteButtonChangedEvent(keyValPair.Key, (bool)keyValPair.Value);
                    }
                }

                //Note that all deadzone and threshold calculations have been taken care of by the the XInput library
                //being used by our project.
                var prevLeftThumb  = lastState.ThumbSticks.Left;
                var prevRightThumb = lastState.ThumbSticks.Right;
                var curLeftThumb   = currentState.ThumbSticks.Left;
                var curRightThumb  = currentState.ThumbSticks.Right;

                //Range change calculations from http://stackoverflow.com/questions/929103/convert-a-number-range-to-another-range-maintaining-ratio

                //Is the new left thumbstick value outside of the deadzone?
                //Has the left thumbstick moved?
                if (Math.Abs(curLeftThumb.X - prevLeftThumb.X) > float.Epsilon ||
                    Math.Abs(curLeftThumb.Y - prevLeftThumb.Y) > float.Epsilon)
                {
                    if (ThumbstickMoved != null)
                    {
                        ThumbAxisEventArgs args = new ThumbAxisEventArgs();
                        //Change the thumbstick ranges from [-1, 1] to [-100, 100]
                        args.XValue = (((curLeftThumb.X - ThumbstickStandardRangeMin) * Thumbstick100Range) /
                                       ThumbstickStandardRange) + Thumbstick100RangeMin;
                        args.YValue = (((curLeftThumb.Y - ThumbstickStandardRangeMin) * Thumbstick100Range) /
                                       ThumbstickStandardRange) + Thumbstick100RangeMin;
                        args.Side = ControllerSide.Left;
                        ApplicationDispatcher.Invoke(delegate { ThumbstickMoved(this, args); });
                    }
                }

                //Has the right thumbstick moved?
                if (Math.Abs(curRightThumb.X - prevRightThumb.X) > float.Epsilon ||
                    Math.Abs(curRightThumb.Y - prevRightThumb.Y) > float.Epsilon)
                {
                    if (ThumbstickMoved != null)
                    {
                        ThumbAxisEventArgs args = new ThumbAxisEventArgs();
                        //Change the thumbstick ranges from [-1, 1] to [-100, 100]
                        args.XValue = (((curRightThumb.X - ThumbstickStandardRangeMin) * Thumbstick100Range) /
                                       ThumbstickStandardRange) + Thumbstick100RangeMin;
                        args.YValue = (((curRightThumb.Y - ThumbstickStandardRangeMin) * Thumbstick100Range) /
                                       ThumbstickStandardRange) + Thumbstick100RangeMin;
                        args.Side = ControllerSide.Right;
                        ApplicationDispatcher.Invoke(delegate { ThumbstickMoved(this, args); });
                    }
                }

                //Has the left trigger changed?
                if (Math.Abs(currentState.Triggers.Left - lastState.Triggers.Left) > float.Epsilon)
                {
                    if (TriggerMoved != null)
                    {
                        TriggerAxisEventArgs args = new TriggerAxisEventArgs();
                        //Change the trigger range from [0, 1] to [0, 100].
                        args.Side   = ControllerSide.Left;
                        args.ZValue = (((currentState.Triggers.Left - TriggerStandardRangeMin) * Trigger100Range) /
                                       TriggerStandardRange) + Trigger100RangeMin;
                        ApplicationDispatcher.Invoke(delegate { TriggerMoved(this, args); });
                    }
                }
                //Has the right trigger changed?
                if (Math.Abs(currentState.Triggers.Right - lastState.Triggers.Right) > float.Epsilon)
                {
                    if (TriggerMoved != null)
                    {
                        TriggerAxisEventArgs args = new TriggerAxisEventArgs();
                        //Change the trigger range from [0, 1] to [0, 100].
                        args.Side   = ControllerSide.Right;
                        args.ZValue = (((currentState.Triggers.Right - TriggerStandardRangeMin) * Trigger100Range) /
                                       TriggerStandardRange) + Trigger100RangeMin;
                        ApplicationDispatcher.Invoke(delegate { TriggerMoved(this, args); });
                    }
                }

                lastState = currentState;
            }
        }
예제 #32
0
 public DialogController(ApplicationDispatcher applicationDispatcher)
 {
     m_ApplicationDispatcher = applicationDispatcher;
 }