Exemplo n.º 1
0
#pragma warning disable 4014
    async Task _AsyncTest2(Action result)
    {
        //値ありのawait
        var ret = await Trigger.Time(1f);

        Assert.IsTrue(ret);

        var            trigger = new Trigger();
        ITriggerAction action  = trigger.Action;

        Trigger.Time(1f).Add(x => trigger.Fire());

        var tmp = Time.time;
        //値なしのITriggerActionでもawait出来る
        await action;

        Assert.IsTrue(tmp + 0.9f < Time.time);

        //発火済みでも正常に動作する
        tmp = Time.time;
        ret = false;
        ret = await Trigger.Successed;
        Assert.AreEqual(tmp, Time.time);
        Assert.IsTrue(ret);

        result();
    }
Exemplo n.º 2
0
        public static ITriggerAction <T> Then <T>(this ITriggerAction <ITriggerAction <T> > self)
        {
            Trigger <T> trigger = new Trigger <T>(oneShot: self.OneShot);

            self.Add((item1, ex1) =>
            {
                if (ex1 != null)
                {
                    trigger.Error(ex1);
                }
                else
                {
                    item1.Add((item2, ex2) =>
                    {
                        if (ex2 != null)
                        {
                            trigger.Error(ex2);
                        }
                        else
                        {
                            trigger.Fire(item2);
                        }
                    });
                }
            });
            return(trigger.Action);
        }
Exemplo n.º 3
0
        public static ITriggerAction <T[]> Combine <T>(params ITriggerAction <T>[] actions)
        {
            Trigger <T[]> trigger = new Trigger <T[]>();

            T[] ret = new T[actions.Length];
            if (actions == null || actions.Length == 0)
            {
                trigger.Fire(ret);
                return(trigger.Action);
            }
            int count = 0;

            for (int i = 0; i < actions.Length; i++)
            {
                int index = i;
                ITriggerAction <T> action = actions[i];
                action.Add((x) =>
                {
                    ret[index] = x;
                    count++;
                    if (count == ret.Length)
                    {
                        trigger.Fire(ret);
                    }
                });
                action.OnFail += trigger.Error;
            }
            return(trigger.Action);
        }
Exemplo n.º 4
0
        public static ITriggerAction <T> Select <T>(this ITriggerAction self, Func <T> func, bool oneShot = true)
        {
            Trigger <T> trigger = new Trigger <T>(oneShot: self.OneShot);

            self.OnFail += trigger.Error;
            self.Add(() => trigger.Fire(func()));
            return(trigger.Action);
        }
Exemplo n.º 5
0
        public bool IsActionOverlaps(ITriggerAction action)
        {
            if (Property == null)
            {
                throw new Granular.Exception("Setter.Property cannot be null");
            }

            return(action is Setter && this.TargetName == ((Setter)action).TargetName && this.Property.Equals(((Setter)action).Property));
        }
Exemplo n.º 6
0
        public bool IsActionOverlaps(ITriggerAction action)
        {
            if (Property == null)
            {
                throw new Granular.Exception("Setter.Property cannot be null");
            }

            return action is Setter && this.TargetName == ((Setter)action).TargetName && this.Property.Equals(((Setter)action).Property);
        }
Exemplo n.º 7
0
        public static ITriggerAction <bool> Any <T>(this ITriggerAction <T> self)
        {
            Trigger <bool> trigger = new Trigger <bool>(true);

            self.Add((item, ex) =>
            {
                if (ex != null)
                {
                    trigger.Fire(true);
                }
            });
            return(trigger.Action);
        }
Exemplo n.º 8
0
        public async Task Handle(HookEvent @event, ITriggerAction action)
        {
            var gitlabEvent = @event.Headers["X-Gitlab-Event"].FirstOrDefault();

            if (string.IsNullOrWhiteSpace(gitlabEvent))
            {
                Console.WriteLine($"[GitLab] Unhandled hook {gitlabEvent}");
                return;
            }

            if (gitlabEvent == "Merge Request Hook")
            {
                await HandleMergeRequest(ReadData(@event), action);
            }
        }
Exemplo n.º 9
0
        private async Task HandleMergeRequest(JObject @event, ITriggerAction trigger)
        {
            var projectId = @event.Property("project").Value.Value <JObject>().Property("id").Value.Value <int>();
            var reviewId  = @event.Property("object_attributes").Value.Value <JObject>().Property("iid").Value.Value <int>();

            var action = @event.Property("object_attributes").Value.Value <JObject>().Property("action").Value.Value <string>();

            if (action == "update")
            {
                await trigger.MergeRequestChanged(projectId, reviewId);
            }
            else if (action == "open")
            {
                await trigger.NewMergeRequest(projectId, reviewId);
            }
        }
Exemplo n.º 10
0
        public static ITriggerAction <T> Timeout <T>(this ITriggerAction <T> self, float time, bool realtime = false)
        {
            Trigger <T> trigger = new Trigger <T>(oneShot: self.OneShot);

            self.Add(trigger);
            var timeout = realtime ? TriggerBehaviour.Realtime(time) : TriggerBehaviour.Time(time);

            timeout.Add(ret =>
            {
                if (!trigger.Action.Fired)
                {
                    trigger.Error(new TimeoutException("trigger timeout"));
                }
            });
            return(trigger.Action);
        }
Exemplo n.º 11
0
        public static ITriggerAction <T> Where <T>(this ITriggerAction <T> self, Func <T, bool> func)
        {
            Trigger <T> trigger = new Trigger <T>(oneShot: false);

            self.Add((item, ex) =>
            {
                if (ex != null)
                {
                    trigger.Error(ex);
                }
                else if (func(item))
                {
                    trigger.Fire(item);
                }
            });
            return(trigger.Action);
        }
Exemplo n.º 12
0
        public static ITriggerAction <U> Select <T, U>(this ITriggerAction <T> self, Func <T, U> func, bool oneShot = true)
        {
            Trigger <U> trigger = new Trigger <U>(oneShot: self.OneShot);

            self.Add((item, ex) =>
            {
                if (ex != null)
                {
                    trigger.Error(ex);
                }
                else
                {
                    trigger.Fire(func(item));
                }
            });
            return(trigger.Action);
        }
Exemplo n.º 13
0
        public static ITriggerAction Then(this ITriggerAction <ITriggerAction> self)
        {
            Trigger trigger = new Trigger(oneShot: self.OneShot);

            self.Add((item1, ex1) =>
            {
                if (ex1 != null)
                {
                    trigger.Error(ex1);
                }
                else
                {
                    item1.Add(trigger.Fire);
                    item1.OnFail += trigger.Error;
                }
            });
            return(trigger.Action);
        }
Exemplo n.º 14
0
        public static ITriggerAction <T> Realtime <T>(this ITriggerAction <T> self, float time)
        {
            Trigger <T> trigger = new Trigger <T>(oneShot: self.OneShot);

            self.Add((item, ex) =>
            {
                if (ex != null)
                {
                    trigger.Error(ex);
                }
                else
                {
                    TriggerBehaviour.Realtime(time)
                    .Add(x => trigger.Fire(item))
                    .AddFail(trigger.Error);
                }
            });
            return(trigger.Action);
        }
Exemplo n.º 15
0
 public void Clear()
 {
     m_Owner  = null;
     m_Action = null;
     m_List   = null;
 }
Exemplo n.º 16
0
 public TriggerActionAwaiter(IHasTriggerAction <T> trigger)
 {
     m_Action = trigger.Action;
 }
Exemplo n.º 17
0
 public ActionHolder(ITriggerAction owner)
 {
     m_Owner = owner;
 }
Exemplo n.º 18
0
 public bool IsActionOverlaps(ITriggerAction action)
 {
     return action is EventSetter && this.Event == ((EventSetter)action).Event;
 }
Exemplo n.º 19
0
 public TriggerActionAwaiter(ITriggerAction <T> action)
 {
     m_Action = action;
 }
Exemplo n.º 20
0
 public bool IsActionOverlaps(ITriggerAction action)
 {
     return(action is EventSetter && this.Event == ((EventSetter)action).Event);
 }
Exemplo n.º 21
0
 public bool IsActionOverlaps(ITriggerAction action)
 {
     return false;
 }
Exemplo n.º 22
0
 public static TriggerActionAwaiter GetAwaiter(this ITriggerAction self)
 {
     return(new TriggerActionAwaiter(self));
 }
Exemplo n.º 23
0
 public bool IsActionOverlaps(ITriggerAction action)
 {
     return(false);
 }
Exemplo n.º 24
0
 public static TriggerActionAwaiter <T> GetAwaiter <T>(this ITriggerAction <T> self, CancellationToken cancellation)
 {
     cancellation.Register(() => { self.Cancel(); });
     return(self.GetAwaiter());
 }
Exemplo n.º 25
0
 public static ITriggerAction <T> Add <T>(this ITriggerAction <T> self, Trigger <T> trigger)
 {
     self.Add(trigger.Fire);
     self.AddFail(trigger.Error);
     return(self);
 }
Exemplo n.º 26
0
 public static ITriggerAction Then <T>(this ITriggerAction <T> self, Func <T, ITriggerAction> func, bool oneShot = true)
 {
     return(self.Select(func, oneShot: oneShot).Then());
 }
Exemplo n.º 27
0
 public bool IsActionOverlaps(ITriggerAction action)
 {
     return this.Key == ((TestTriggerAction)action).Key;
 }
 internal void AddAction(ITriggerAction triggerAction)
 => ActionExpressions.Add(triggerAction);
Exemplo n.º 29
0
 public bool IsActionOverlaps(ITriggerAction action)
 {
     return(this.Key == ((TestTriggerAction)action).Key);
 }
Exemplo n.º 30
0
 public SplitAxisAction(ITriggerAction positive, ITriggerAction negative)
 {
     _positive = positive;
     _negative = negative;
 }