public BackgroundAction(ActionPerformer actionPerformer, ISettingsService settingsService)
		{
			syncContext = SynchronizationContext.Current;
			var culture = settingsService.CurrentSettings.Language.Culture;
			thread = new Thread(state => RunWorker(actionPerformer))
			         {IsBackground = true, CurrentCulture = culture, CurrentUICulture = culture};
		}
    public static void Main()
    {
        ActionManager   manager   = new ActionManager();
        ActionPerformer performer = new ActionPerformer();

        manager.DoSomething(performer);
    }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="InvokeObject"></param>
 /// <param name="Name"></param>
 /// <param name="Type"></param>
 /// <param name="Processor"></param>
 /// <param name="Performer"></param>
 public Action(object InvokeObject, string Name, ActionType Type, Delegate Processor, ActionPerformer Performer)
 {
     this.name        = Name;
     this.type        = Type;
     this.processor   = Processor;
     this.invokobject = InvokeObject;
     this.performer   = Performer;
 }
Beispiel #4
0
        private void Start()
        {
            actionOnSolve = GetComponent <ActionPerformer>();
            puzzles       = GetComponentsInChildren <Puzzle>().ToList();
            puzzles.RemoveAt(0);// removing self

            puzzles.ForEach(p => p.OnPuzzleSolved += CompositePuzzleSolved);
        }
Beispiel #5
0
        public void Performer_UndoAction_IsOriginal()
        {
            var action          = Substitute.For <IAction>();
            var actionPerformer = new ActionPerformer();

            actionPerformer.PerformAction(action);

            Assert.Equal(action, actionPerformer.UndoPreviousAction());
        }
Beispiel #6
0
        public void Update(ConsoleKeyInfo key)
        {
            switch (key.Key)
            {
            case ConsoleKey.UpArrow:
            case ConsoleKey.DownArrow:
                if (Modal == null)
                {
                    FocusedPanel.Update(key);
                }
                else
                {
                    Modal.ListView.Update(key);
                    Modal.ListView.Render();
                }
                break;

            case ConsoleKey.Enter:
                if (Modal == null)
                {
                    goto default;
                }
                else
                {
                    FileSystemInfo fileSystemInfo = Modal.ListView.SelectedItem.Item;

                    if (fileSystemInfo is FileInfo file)
                    {
                        Process.Start(file.FullName);
                        FocusedPanel.Current = new DirectoryInfo(Path.GetPathRoot(fileSystemInfo.FullName));
                    }
                    else
                    {
                        FocusedPanel.Current = new DirectoryInfo(fileSystemInfo.FullName);
                    }

                    Modal = null;
                    RefreshScreen();
                }
                break;

            case ConsoleKey.Escape:
                if (Modal != null)
                {
                    Modal = null;
                    RefreshScreen();
                }
                break;

            default:
                ActionPerformerArgs args = new ActionPerformerArgs(key, this);
                ActionPerformer = ActionPerformer.GetActionPerformer(args);
                ActionPerformer.Do(args);
                break;
            }
        }
Beispiel #7
0
        public void Performer_UndoAction_WithNoAction_IsNull()
        {
            var action          = Substitute.For <IAction>();
            var actionPerformer = new ActionPerformer();

            actionPerformer.PerformAction(action);
            actionPerformer.UndoPreviousAction();

            Assert.Null(actionPerformer.UndoPreviousAction());
        }
Beispiel #8
0
 void setActionForPerformer()
 {
     if (Data.MoveType == Data.Move.BALL || Data.MoveType == Data.Move.DESTROYER)
     {
         performer = new FlyableActionPerformer(currentlyAdded);
     }
     else
     {
         performer = new BarrierActionPerformer(currentlyAdded);
     }
 }
Beispiel #9
0
 public ZWAction(Action config, ActionPerformer af, EventPart ep, bool high, SkillContext context = null)
 {
     this.High             = high;
     this.startTime        = GameTimer.time;
     this.config           = config;
     this.LifeTime         = this.config.LifeTime;
     this.eventpart        = ep;
     this.ActionPerformer_ = af;
     this.actionEvents     = new PList();
     this.context          = context;
     this.Initialize(af.owerObject);
 }
Beispiel #10
0
 private void RunWorker(ActionPerformer actionPerformer)
 {
     try
     {
         ActionArgs args = new ActionArgs();
         actionPerformer(args);
         Post(state => OnCompleted(args.Result));
     }
     catch (Exception e)
     {
         Post(state => OnErrorOccurred(e));
     }
 }
        public void TestSlowListener()
        {
            MessageLog log = new MessageLog();
            ActionPerformer performer = new ActionPerformer(log);
            EventManager eventManager = new EventManager();

            const string eventType = "ET";

            eventManager.Start();

            eventManager.Watch(eventType, performer.SlowAction);

            log.Log("Event fired.");
            eventManager.Notify(eventType);

            Thread.Sleep(150);

            const int eventsCount = 10000;

            Stopwatch sw = Stopwatch.StartNew();
            log.Log($"Starting to fire a series of {eventsCount} events.");
            for (int i = 0; i < eventsCount; i++)
            {
                eventManager.Notify(eventType);
            }
            log.Log($"Finished to fire a series of {eventsCount} events.");
            Assert.That(sw.ElapsedMilliseconds, Is.LessThan(100));

            Thread.Sleep(1000);

            eventManager.Stop();

            Assert.That(log.GetLog(), Is.EqualTo(new string[]
            {
                "Event fired.",
                "SlowAction started.",
                $"Starting to fire a series of {eventsCount} events.",
                $"Finished to fire a series of {eventsCount} events.",
                "SlowAction completed.",
                "SlowAction started.",
                "SlowAction completed."
            }));
        }
        public void TestBrokenListener()
        {
            MessageLog log = new MessageLog();
            ActionPerformer performer1 = new ActionPerformer(log);
            ActionPerformer performer2 = new ActionPerformer(log);
            EventManager eventManager = new EventManager();

            const string eventType = "ET";

            eventManager.Start();

            eventManager.Watch(eventType, performer1.BrokenAction);
            eventManager.Watch(eventType, performer2.BrokenAction);

            log.Log("Event fired.");
            eventManager.Notify(eventType);

            Thread.Sleep(200);

            Assert.That(log.GetLog(), Is.EqualTo(new string[]
            {
                "Event fired.",
                "BrokenAction invoked.",
                "BrokenAction invoked."
            }));

            log.Log("Event fired.");
            eventManager.Notify(eventType);

            Thread.Sleep(200);

            Assert.That(log.GetLog(), Is.EqualTo(new string[]
            {
                "Event fired.",
                "BrokenAction invoked.",
                "BrokenAction invoked.",
                "Event fired.",
                "BrokenAction invoked.",
                "BrokenAction invoked."
            }));
        }
		private void RunWorker(ActionPerformer actionPerformer)
		{
			try
			{
				Send(state => OnReady());
				var args = new ActionArgs();
				actionPerformer(args);
				RunContinuations();
				Send(state => OnCompleted(args.Result));
			}
			catch (Exception e)
			{
				Send(state => OnErrorOccurred(e));
			}
			finally
			{
				Send(state => OnDone());
				if (syncEvent != null)
				{
					syncEvent.Release();
				}
			}
		}
Beispiel #14
0
        /// <summary>
        /// 创建动作
        /// </summary>
        /// <param name="ActionName">动作名称</param>
        /// <param name="Type">动作类型</param>
        /// <param name="InvokeObject">调用的对象</param>
        /// <param name="InvokeProcessor">对象处理者委托</param>
        /// <param name="Performer">注销动作时的回调函数</param>
        /// <returns></returns>
        public bool CreateAction(string ActionName, ActionType Type, object InvokeObject, Delegate InvokeProcessor, ActionPerformer Performer = null)
        {
            bool    iscmp     = false;
            IAction newAction = new Action(InvokeObject, ActionName, Type, InvokeProcessor, Performer);
            //查找是否已经存在上下文
            var f = this.contexts.Find(delegate(IActionContext ac) { return(ac.ContextProcessType == Lemon.GetObjType(InvokeObject)); });

            if (f == null)
            {
                //不存在则创建新的
                if (this.contexttemplates.Count > 0)
                {
                    //创建新的上下文
                    IActionContext newAc = Lemon.GetInstance <IActionContext>(Lemon.GetObjType(this.MatcherContextTemplate(newAction)));
                    newAc.ContextProcessType = Lemon.GetObjType(InvokeObject);
                    f = newAc;
                    //加入上下文实例的集合
                    this.contexts.Add(f);
                }
            }
            if (f != null)
            {
                //判断是否是单一动作
                if (newAction.Type == Lemonade.Frame.Running.ActionType.Single)
                {
                    this.Remove(newAction.InvokeObject, newAction.ActionName, ActionType.Single);
                }
                else
                {
                    f.RemoveAction(newAction);
                }
                f.AddAction(newAction);
                iscmp = true;
            }

            return(iscmp);
        }
Beispiel #15
0
 public BackgroundAction(ActionPerformer actionPerformer)
 {
     syncContext = SynchronizationContext.Current;
     thread = new Thread(state => RunWorker(actionPerformer)) {IsBackground = true};
 }
Beispiel #16
0
        ///// <summary>
        ///// 是否已经存在调用者对象
        ///// </summary>
        ///// <param name="InvokeObject"></param>
        ///// <returns></returns>
        //public bool HasInvokeObject(object InvokeObject)
        //{
        //    bool result = false;
        //    var f = this.contexts.Find(delegate(IActionContext ac) { return ac.GetInvokeObjectIndex(InvokeObject) > -1; });
        //    if (f != null)
        //    {
        //        result = true;
        //    }
        //    return result;
        //}
        /// <summary>
        ///
        /// </summary>
        /// <param name="ActionName"></param>
        /// <param name="Type"></param>
        /// <param name="InvokeObject"></param>
        /// <param name="InvokeProcessor"></param>
        /// <param name="Performer"></param>
        /// <returns></returns>
        public bool HasAction(string ActionName, ActionType Type, object InvokeObject, Delegate InvokeProcessor, ActionPerformer Performer = null)
        {
            IAction        newAction = new Action(InvokeObject, ActionName, Type, InvokeProcessor, Performer);
            IActionContext context   = this.MatcherContext(newAction);

            if (context == null)
            {
                return(false);
            }
            else
            {
                if (context.GetInvokeObjectIndex(InvokeObject) > -1)
                {
                    int account = context.GetActionCount(InvokeObject);
                    if (account > 0)
                    {
                        for (int i = 0; i < account; i++)
                        {
                            IAction tmpac = context[InvokeObject, i];
                            if (tmpac != null)
                            {
                                if (tmpac.ActionName == ActionName &&
                                    tmpac.InvokeProcessor == InvokeProcessor)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
                return(false);
                //context.
            }
        }
Beispiel #17
0
 public PrincessGameLauncher()
 {
     _actionPerformer = new ActionPerformer();
     _fieldFiller     = new FieldFiller();
 }
        public void TestSmoke()
        {
            MessageLog log = new MessageLog();
            ActionPerformer performer = new ActionPerformer(log);
            EventManager eventManager = new EventManager();

            const string eventType1 = "ET1";
            const string eventType2 = "ET2";

            eventManager.Watch(eventType1, performer.Action1);
            eventManager.Watch(eventType2, performer.Action2);

            eventManager.Start();

            log.Log($"Fired {eventType1} event.");
            eventManager.Notify(eventType1);

            Thread.Sleep(200);

            log.Log($"Fired {eventType2} event.");
            eventManager.Notify(eventType2);

            Thread.Sleep(200);

            Assert.That(log.GetLog(), Is.EqualTo(new string[]
            {
                $"Fired {eventType1} event.",
                $"Action1 invoked.",
                $"Fired {eventType2} event.",
                $"Action2 invoked."
            }));

            // testing that attempt to remove non-existent event listeners does not affect existing watchers
            eventManager.Unwatch(eventType1, performer.Action2);
            eventManager.Unwatch(eventType2, performer.Action1);

            log.Clear();
            log.Log("Attempted to remove non-existent event listeners.");

            log.Log($"Fired {eventType1} event.");
            eventManager.Notify(eventType1);

            Thread.Sleep(200);

            log.Log($"Fired {eventType2} event.");
            eventManager.Notify(eventType2);

            Thread.Sleep(200);

            Assert.That(log.GetLog(), Is.EqualTo(new string[]
            {
                $"Attempted to remove non-existent event listeners.",
                $"Fired {eventType1} event.",
                $"Action1 invoked.",
                $"Fired {eventType2} event.",
                $"Action2 invoked."
            }));

            eventManager.Unwatch(eventType1, performer.Action1);

            log.Clear();
            log.Log($"Removed event-listener for {eventType1}.");

            log.Log($"Fired {eventType1} event.");
            eventManager.Notify(eventType1);

            log.Log($"Fired {eventType2} event.");
            eventManager.Notify(eventType2);

            Thread.Sleep(200);

            Assert.That(log.GetLog(), Is.EqualTo(new string[]
            {
                $"Removed event-listener for {eventType1}.",
                $"Fired {eventType1} event.",
                $"Fired {eventType2} event.",
                $"Action2 invoked."
            }));
        }
Beispiel #19
0
        /// <summary>
        /// 使用框架动作管理器向调用者添加动作,自动响应内置的动作处理机制,注册后自动激活动作
        /// </summary>
        /// <param name="InvokeObject">调用者</param>
        /// <param name="ActionName">动作名称</param>
        /// <param name="Type">动作类型</param>
        /// <param name="InvokeProcessor">处理者</param>
        /// <param name="Performer">在动作注销时执行的委托</param>
        public static bool ActionAppend(object InvokeObject, string ActionName, ActionType Type, Delegate InvokeProcessor, ActionPerformer Performer = null)
        {
            bool isCup = LemonEnvironment.GetInstance().ActionsManager.CreateAction(ActionName, Type, InvokeObject, InvokeProcessor, Performer);

            if (isCup)
            {
                Lemon.ActionActivate(InvokeObject);
            }
            return(isCup);
        }
Beispiel #20
0
 /// <summary>
 /// 使用框架动作管理器向调用者添加动作,按顺序执行的多个执行
 /// </summary>
 /// <param name="InvokeObject"></param>
 /// <param name="ActionName"></param>
 /// <param name="InvokeProcessor"></param>
 /// <param name="Performer"></param>
 public static void ActionAppendMulti(this object InvokeObject, string ActionName, Delegate InvokeProcessor, ActionPerformer Performer = null)
 {
     Lemon.ActionAppend(InvokeObject, ActionName, ActionType.Sequence, InvokeProcessor, Performer);
 }
Beispiel #21
0
        public void Performer_PerformNullAction_ThrowsArgumentNullException()
        {
            var actionPerformer = new ActionPerformer();

            Assert.Throws <ArgumentNullException>(() => actionPerformer.PerformAction(null));
        }