public async Task <T> Trigger()
        {
            if (!Enabled)
            {
                Logger.Error(GetType(), "Not really running remote action because action is disabled");
                throw new Exception("trying to trigger disabled action");
            }

            Logger.Debug(GetType(), "Running remote action");
            ResultHolder <T> resultAsHolder;

            try {
                StartedExecution();
                var result = await _remoteAction();

                resultAsHolder = ResultHolder <T> .CreateSuccess(result);

                await ExecOnUiThread.Exec(() => ActionExecuted?.Invoke(resultAsHolder));

                return(result);
            } catch (Exception ex) {
                resultAsHolder = ResultHolder <T> .CreateFailure(ex.Message, ex);

                await ExecOnUiThread.Exec(() => ActionExecuted?.Invoke(resultAsHolder));

                throw;
            } finally {
                Logger.Debug(GetType(), "Remote action ended");
                EndedExecution();
            }
        }
Example #2
0
        private static void MakeLessonFromArticle()
        {
            Article art = articles.ChooseRandomly();

            Lesson      = art;
            UnHighlight = false;
            ActionExecuted?.Invoke(CommandAction.lesson);
        }
Example #3
0
        private void Item_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;

            ListBoxItem item = (ListBoxItem)sender;

            UCEActionRow row = (UCEActionRow)item.Content;

            list.SelectedItem = null;
            row.Execute();

            ActionExecuted?.Invoke();
        }
Example #4
0
        internal static void ExecuteAction(HistoryAction action)
        {
            lock (Service.Locker)
            {
                Service._redoStack.Clear();
                Service._undoStack.Push(action);

                action.Execute();
                ActionExecuted?.Invoke(action);

                if (DebugSettings.LogHistoryActions)
                {
                    Service.Logger.Trace($"HistoryService: action pushed");
                }
            }
        }
Example #5
0
        public async Task <Unit> Trigger()
        {
            if (!Enabled)
            {
                Logger.Error(GetType(), "Not really running action because action is disabled");
                return(Unit.Instance);
            }

            Logger.Debug(GetType(), "Triggering local action?={0}", _localAction != null);

            if (_localAction != null)
            {
                try {
                    await _localAction.Invoke();
                } catch (Exception ex) {
                    ActionExecuted?.Invoke(ResultHolder <Unit> .CreateFailure(ex.Message, ex));
                    throw;
                }
            }

            ActionExecuted?.Invoke(ResultHolder <Unit> .CreateSuccess(Unit.Instance));

            return(Unit.Instance);
        }
Example #6
0
        private async static void Execute(List <CommandMapping> actions)
        {
            foreach (var v in actions)
            {
                if (Settings.GetSettings().IsTutorial == false && v.Command != CommandAction.lesson)
                {
                    continue;
                }
                switch (v.Command)
                {
                case CommandAction.highlightKeys:
                    HighlightedKeys = v.Parameter;
                    UnHighlight     = false;
                    break;

                case CommandAction.type:
                    // Text = dic.Value;
                    UnHighlight = false;
                    break;

                case CommandAction.print:
                    Text        = v.Parameter;
                    UnHighlight = false;
                    break;

                case CommandAction.highlight:
                    Highlighted = v.Parameter;
                    UnHighlight = false;
                    break;

                case CommandAction.showBoard:
                    View        = DesiredView.Board;
                    UnHighlight = false;
                    break;

                case CommandAction.showView:
                    View        = DesiredView.View;
                    UnHighlight = false;
                    break;

                case CommandAction.lesson:
                    string[] splitString = v.Parameter.Split("<<");
                    if (splitString.Length != 2)
                    {
                        splitString = new string[] { v.Parameter, $"Tutor Lesson {Settings.GetSettings().MachineLessonIndex}" }
                    }
                    ;

                    Lesson = new Lesson()
                    {
                        Text = splitString[0],
                        Name = splitString[1]
                    };
                    UnHighlight = false;
                    break;

                case CommandAction.disableUI:
                    UnHighlight = false;
                    UiEnabled   = false;
                    break;

                case CommandAction.enableUI:
                    UnHighlight = false;
                    UiEnabled   = true;
                    break;

                case CommandAction.showKeyboard:
                    UnHighlight = false;
                    Keyboard    = true;
                    break;

                case CommandAction.hideKeyboard:
                    UnHighlight = false;
                    Keyboard    = false;
                    break;

                case CommandAction.unHiglight:
                    UnHighlight = true;
                    break;

                case CommandAction.speak:
                    await Speaker.SpeakAsync(v.Parameter, tokenSource.Token);

                    UnHighlight = false;
                    break;

                case CommandAction.delay:
                    try
                    {
                        await Task.Delay(int.Parse(v.Parameter), tokenSource.Token);
                    }
                    catch { }
                    UnHighlight = false;
                    break;

                default:
                    break;
                }
                ActionExecuted?.Invoke(v.Command);

                if (tokenSource.Token.IsCancellationRequested)
                {
                    tokenSource = new CancellationTokenSource();
                    //break;
                }
            }
        }
Example #7
0
        public async Task TickAsync(IGame game)
        {
            if (_ended)
            {
                return;
            }


            // if no factions are on the same map then pause operations
            var maps = Combatants.Keys.Select(c => c.Map.Id).Distinct();

            if (maps.Count() == Combatants.Keys.Count())
            {
                // no combatants are on the same map... skip
                return;
            }

            // any pending actions from not dead combatant?
            var entities = Combatants.Keys.Where(k => !Dead.Contains(k)).Select(o => o).ToList();

            foreach (var entity in entities)
            {
                // player offline?
                if (entity.IsPlayer() && !game.Players.Contains((IPlayer)entity))
                {
                    // are there any players left? pause combat
                    // i dont like making the specific decision about no offline combat here..
                    // needs configuration in future
                    if (Combatants.Keys.Count(k => k.IsPlayer() && game.Players.Contains((IPlayer)k)) == 0)
                    {
                        return;
                    }
                }

                var combatant = (ICombatant <GridTargetAction>)Combatants[entity];
                if (combatant.CanAttack)
                {
                    var nextAction = await combatant.GetNextActionAsync(this);

                    if (nextAction == null)
                    {
                        continue;
                    }

                    if (nextAction.SourceEntity == null)
                    {
                        nextAction.SourceEntity = (GridEntity)entity;
                    }

                    if (nextAction.TargetEntities.Count == 0)
                    {
                        await nextAction.SetDefaultTargetAsync(this);
                    }

                    var executed = await nextAction.Execute();

                    if (executed)
                    {
                        LastAction = DateTime.Now;
                        ActionLog.Add(nextAction);

                        if (ActionExecuted != null)
                        {
                            await ActionExecuted.Invoke(this, nextAction);
                        }
                    }
                }
            }
        }
Example #8
0
 protected void OnActionExecuted(ActionEventArgs e) => ActionExecuted?.Invoke(this, e);
Example #9
0
 void OnActionExecuted(ActionEventArgs e)
 {
     ActionExecuted?.Invoke(this, e);
 }
Example #10
0
 private void HandleSuccess(IMessage obj)
 {
     ActionExecuted.Invoke(this);
 }