コード例 #1
0
ファイル: StateMachine.cs プロジェクト: shoematt/StormState
        /// <summary>
        ///     Transitions this instance.
        /// </summary>
        public bool Transition( )
        {
            if (!_isStarted)
            {
                throw new StateMachineException("The state machine has not been started");
            }

            lock ( _syncObject )
            {
                if (_logging.IsDebugEnabled)
                {
                    _logging.Debug("StateMachine Transition Request - Started");
                }

                var transitions = _stateMap.GetTransitionsForStates(ActiveStates);

                ActiveStates.Clear( );

                foreach (IStateTransition transition in transitions)
                {
                    transition.DoTransition(OnTransition);
                }

                if (_logging.IsDebugEnabled)
                {
                    _logging.Debug("StateMachine Transition Request - Complete");
                }
            }

            return(ActiveStates.Count != 0);
        }
コード例 #2
0
ファイル: StateMachine.cs プロジェクト: shoematt/StormState
        /// <summary>
        ///     Transitions to (effectively a JUMP operation, which will bypass predefined transitions)
        /// </summary>
        /// <param name="TO"> The TO. </param>
        /// <returns> </returns>
        public bool TransitionTo(IState TO)
        {
            if (!_isStarted)
            {
                throw new StateMachineException("The state machine has not been started");
            }

            lock ( _syncObject )
            {
                if (_logging.IsDebugEnabled)
                {
                    _logging.Debug("StateMachine Transition Request - Started");
                }

                foreach (IState fromState in ActiveStates)
                {
                    try
                    {
                        fromState.Leave.CallOnEach(x => x.Execute(StateContainer, _stateMap));
                    }
                    catch (Exception ex)
                    {
                        throw new StateMachineException(ex.Message);
                    }
                }

                ActiveStates.Clear( );

                try
                {
                    if (TO != null)
                    {
                        ActiveStates.Add(TO);

                        foreach (IState toState in ActiveStates)
                        {
                            if (toState.Enter != null)
                            {
                                toState.Enter.CallOnEach(x => x.Execute(StateContainer, _stateMap));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new StateMachineException(ex.Message);
                }

                if (_logging.IsDebugEnabled)
                {
                    _logging.Debug("StateMachine Transition Request - Complete");
                }
            }

            return(ActiveStates.Count != 0);
        }
コード例 #3
0
ファイル: StateMachine.cs プロジェクト: shoematt/StormState
        /// <summary>
        ///     Called when [transition].
        /// </summary>
        /// <param name="TO"> The TO. </param>
        /// <param name="FROM"> The FROM. </param>
        /// <param name="transition"> The transition. </param>
        // ReSharper disable InconsistentNaming
        private void OnTransition(List <IState> TO, IState FROM, IStateTransition transition)   // ReSharper restore InconsistentNaming
        {
            try
            {
                if (FROM.Leave != null)
                {
                    foreach (IState toState in ActiveStates)
                    {
                        if (_logging.IsDebugEnabled)
                        {
                            _logging.DebugFormat("StateMachine Transition Activated From {0} to {1}", FROM.Name, toState.Name);
                        }
                    }

                    FROM.Leave.CallOnEach(x => x.Execute(StateContainer, _stateMap));
                }
            }
            catch (Exception ex)
            {
                throw new StateMachineException(ex.Message);
            }

            try
            {
                if (TO != null)
                {
                    ActiveStates.AddRange(TO);

                    foreach (IState toState in ActiveStates)
                    {
                        if (toState.Enter != null)
                        {
                            toState.Enter.CallOnEach(x => x.Execute(StateContainer, _stateMap));
                        }

                        if (_logging.IsDebugEnabled)
                        {
                            _logging.DebugFormat("StateMachine Transition Completed From {0} to {1}", FROM.Name, toState.Name);
                        }
                    }
                }
                else
                {
                    if (_logging.IsDebugEnabled)
                    {
                        _logging.DebugFormat("StateMachine has Transitioned To A Final State From {0}", FROM.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new StateMachineException(ex.Message);
            }
        }
コード例 #4
0
ファイル: TorrentInfo.cs プロジェクト: deaddog/BitTorrent
 public TorrentInfo(InfoHash hash, string name, int priority, ActiveStates activestate, DownloadStates downloadstate, IEnumerable<string> labels, ulong size, ulong remaining, ulong uploaded)
 {
     Hash = hash;
     Name = name;
     Priority = priority;
     ActiveState = activestate;
     DownloadState = downloadstate;
     Labels = new ReadOnlyCollection<string>(new List<string>(labels));
     Size = size;
     Remaining = remaining;
     Uploaded = uploaded;
 }
コード例 #5
0
        public IActionResult Index([FromRoute] ActiveStates active = ActiveStates.All, [FromQuery] int page = 1,
                                   [FromQuery] int size            = 5)
        {
            PagedResult <Campaign> campaigns = active == ActiveStates.Active
                ? _service.ActiveList(page, size)
                : _service.List(page, size);
            var productsOutput = campaigns.Data.Select(CampaignOutputModel.FromEntity).ToList();
            PagedResult <CampaignOutputModel> campaignsOutputPage = new PagedResult <CampaignOutputModel>
            {
                Data        = productsOutput,
                Page        = campaigns.Page,
                PageCount   = campaigns.PageCount,
                PageSize    = campaigns.PageCount,
                RecordCount = campaigns.RecordCount
            };

            ViewData["active"] = active;
            return(View(campaignsOutputPage));
        }
コード例 #6
0
ファイル: StateMachine.cs プロジェクト: shoematt/StormState
        /// <summary>
        ///     Stops this instance.
        /// </summary>
        public void Stop( )
        {
            try
            {
                if (_isStarted)
                {
                    ActiveStates.Clear( );

                    _isStarted = false;

                    if (StopEvent != null)
                    {
                        StopEvent.Execute(StateContainer, _stateMap);
                    }

                    _stateMap.Transitions.CallOnEach(x => x.Reset( ));
                }
            }
            catch (Exception ex)
            {
                throw new StateMachineException(ex.Message);
            }
        }
コード例 #7
0
ファイル: StateMachine.cs プロジェクト: shoematt/StormState
        /// <summary>
        ///     Starts the specified initial state.
        /// </summary>
        /// <param name="initialState"> The initial state. </param>
        public void Start(IState initialState)
        {
            try
            {
                if (_isStarted)
                {
                    return;
                }

                _isStarted = true;

                if (!_stateMap.States.Contains(initialState))
                {
                    throw new StateMachineException("The specified start state does not exist in the state map");
                }

                ActiveStates.Add(initialState);

                if (StartEvent != null)
                {
                    StartEvent.Execute(StateContainer, _stateMap);
                }

                foreach (IState state in ActiveStates)
                {
                    if (state.Enter != null)
                    {
                        state.Enter.CallOnEach(x => x.Execute(StateContainer, _stateMap));
                    }
                }
            }
            catch (Exception ex)
            {
                throw new StateMachineException(ex.Message);
            }
        }
コード例 #8
0
 private string getStateAllUrl(ActiveStates state)
 {
     if (state == ActiveStates.Stopped)
         return POSTURL + "pauseAll";
     else if (state == ActiveStates.Started)
         return POSTURL + "resumeAll";
     else
         throw new KeyNotFoundException($@"The qBitTorrent state ""{state}"" was not recognized.");
 }
コード例 #9
0
        public async Task SetStateAll(ActiveStates state)
        {
            string url = getStateAllUrl(state);

            await req.Post(url);
        }
コード例 #10
0
        public async Task SetState(IEnumerable<InfoHash> torrents, ActiveStates state)
        {
            foreach (InfoHash torrentHash in torrents)
            {
                string url = getStateUrl(state);

                var response = await req.Post<JObject>(url, $"hash={torrentHash.ToString()}");
            }
        }
コード例 #11
0
        public override void Update(GameTime gameTime)
        {
            //Update Keyboard and Mouse States
            PreviousKeyboardState = CurrentKeyboardState;
            CurrentKeyboardState  = Keyboard.GetState();
            PreviousMouseState    = CurrentMouseState;
            CurrentMouseState     = Mouse.GetState();

            //Clear Data Structures
            ActiveActions.Clear();
            ActiveStates.Clear();
            ActiveRanges.Clear();
            MappedKeyboardKeys.Clear();
            MappedMouseButtons.Clear();
            MappedMouseRanges.Clear();
            RangeValues.Clear();

            MouseScreenLocation = new Point(CurrentMouseState.X, CurrentMouseState.Y);

            //Sort EntityList by InputMap Priority
            EntityList.Sort((Entity x, Entity y) =>
            {
                if (x.GetComponent <CInputMap>().Priority < y.GetComponent <CInputMap>().Priority)
                {
                    return(-1);
                }
                else if (x.GetComponent <CInputMap>().Priority > y.GetComponent <CInputMap>().Priority)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            });

            //Map Raw Inputs to Actions, States and Ranges
            foreach (Entity e in EntityList)
            {
                var inputMap = e.GetComponent <CInputMap>();

                //KEYBOARD KEY TO ACTION
                foreach (KeyValuePair <Keys, int> pair in inputMap.KeyboardKeyToAction)
                {
                    if (!MappedKeyboardKeys.Contains(pair.Key))
                    {
                        if (PreviousKeyboardState.IsKeyUp(pair.Key) && CurrentKeyboardState.IsKeyDown(pair.Key))
                        {
                            ActiveActions.Add(pair.Value);
                            MappedKeyboardKeys.Add(pair.Key);
                        }
                    }
                }

                //KEYBOARD KEY TO STATE
                foreach (KeyValuePair <Keys, int> pair in inputMap.KeyboardKeyToState)
                {
                    if (!MappedKeyboardKeys.Contains(pair.Key))
                    {
                        if (CurrentKeyboardState.IsKeyDown(pair.Key))
                        {
                            ActiveStates.Add(pair.Value);
                            MappedKeyboardKeys.Add(pair.Key);
                        }
                    }
                }

                //MOUSE BUTTON TO ACTION
                foreach (KeyValuePair <MouseButtons, int> pair in inputMap.MouseButtonToAction)
                {
                    if (!MappedMouseButtons.Contains(pair.Key))
                    {
                        if (pair.Key == MouseButtons.LeftButton)
                        {
                            if (PreviousMouseState.LeftButton == ButtonState.Released && CurrentMouseState.LeftButton == ButtonState.Pressed)
                            {
                                ActiveActions.Add(pair.Value);
                                MappedMouseButtons.Add(pair.Key);
                            }
                        }
                        if (pair.Key == MouseButtons.RightButton)
                        {
                            if (PreviousMouseState.RightButton == ButtonState.Released && CurrentMouseState.RightButton == ButtonState.Pressed)
                            {
                                ActiveActions.Add(pair.Value);
                                MappedMouseButtons.Add(pair.Key);
                            }
                        }
                        if (pair.Key == MouseButtons.MiddleButton)
                        {
                            if (PreviousMouseState.MiddleButton == ButtonState.Released && CurrentMouseState.MiddleButton == ButtonState.Pressed)
                            {
                                ActiveActions.Add(pair.Value);
                                MappedMouseButtons.Add(pair.Key);
                            }
                        }
                        if (pair.Key == MouseButtons.XButton1)
                        {
                            if (PreviousMouseState.XButton1 == ButtonState.Released && CurrentMouseState.XButton1 == ButtonState.Pressed)
                            {
                                ActiveActions.Add(pair.Value);
                                MappedMouseButtons.Add(pair.Key);
                            }
                        }
                        if (pair.Key == MouseButtons.XButton2)
                        {
                            if (PreviousMouseState.XButton2 == ButtonState.Released && CurrentMouseState.XButton2 == ButtonState.Pressed)
                            {
                                ActiveActions.Add(pair.Value);
                                MappedMouseButtons.Add(pair.Key);
                            }
                        }
                    }
                }

                //MOUSE BUTTON TO STATE
                foreach (KeyValuePair <MouseButtons, int> pair in inputMap.MouseButtonToState)
                {
                    if (!MappedMouseButtons.Contains(pair.Key))
                    {
                        if (pair.Key == MouseButtons.LeftButton)
                        {
                            if (CurrentMouseState.LeftButton == ButtonState.Pressed)
                            {
                                ActiveStates.Add(pair.Value);
                                MappedMouseButtons.Add(pair.Key);
                            }
                        }
                        if (pair.Key == MouseButtons.RightButton)
                        {
                            if (CurrentMouseState.RightButton == ButtonState.Pressed)
                            {
                                ActiveStates.Add(pair.Value);
                                MappedMouseButtons.Add(pair.Key);
                            }
                        }
                        if (pair.Key == MouseButtons.MiddleButton)
                        {
                            if (CurrentMouseState.MiddleButton == ButtonState.Pressed)
                            {
                                ActiveStates.Add(pair.Value);
                                MappedMouseButtons.Add(pair.Key);
                            }
                        }
                        if (pair.Key == MouseButtons.XButton1)
                        {
                            if (CurrentMouseState.XButton1 == ButtonState.Pressed)
                            {
                                ActiveStates.Add(pair.Value);
                                MappedMouseButtons.Add(pair.Key);
                            }
                        }
                        if (pair.Key == MouseButtons.XButton2)
                        {
                            if (CurrentMouseState.XButton2 == ButtonState.Pressed)
                            {
                                ActiveStates.Add(pair.Value);
                                MappedMouseButtons.Add(pair.Key);
                            }
                        }
                    }
                }

                //MOUSE RANGE TO RANGE
                foreach (KeyValuePair <MouseRanges, int> pair in inputMap.MouseRangeToRange)
                {
                    if (!MappedMouseRanges.Contains(pair.Key))
                    {
                        if (pair.Key == MouseRanges.ScrollDelta)
                        {
                            ActiveRanges.Add(pair.Value);
                            RangeValues.Add(pair.Value, CurrentMouseState.ScrollWheelValue - PreviousMouseState.ScrollWheelValue);
                            MappedMouseRanges.Add(pair.Key);
                        }
                        if (pair.Key == MouseRanges.MouseHorizontalDelta)
                        {
                            float hCenter = ViewPort.Width / 2;
                            ActiveRanges.Add(pair.Value);
                            RangeValues.Add(pair.Value, CurrentMouseState.X - hCenter);
                            MappedMouseRanges.Add(pair.Key);
                        }
                        if (pair.Key == MouseRanges.MouseVerticalDelta)
                        {
                            float vCenter = ViewPort.Height / 2;
                            ActiveRanges.Add(pair.Value);
                            RangeValues.Add(pair.Value, CurrentMouseState.Y - vCenter);
                            MappedMouseRanges.Add(pair.Key);
                        }
                    }
                }
            }

            //Given the Mapped Inputs, Call all Callbacks and see if they can use the Mapped Input
            foreach (Entity e in EntityList)
            {
                var inputHandlers = e.GetComponent <CInputHandlers>();

                foreach (int callbackID in inputHandlers.InputHandlerIDs)
                {
                    GameRegistry.FetchInputCallback(callbackID)(e, gameTime, ActiveActions, ActiveStates, ActiveRanges, RangeValues);
                }
            }
        }