Exemplo n.º 1
0
 HandyAnimator(ValueAnimator coreAnim, int duration)
 {
     core = coreAnim;
     core.SetDuration(duration);
     core.Update       += (sender, e) => Update?.Invoke(e.Animation.AnimatedValue);
     core.AnimationEnd += (sender, e) => After?.Invoke();
     core.AnimationEnd += (sender, e) => animators.Remove(this);
     animators.Add(this);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Event handler for when the <see cref="AfterRouting"/> event is raised
 /// </summary>
 /// <param name="context">The <see cref="IHttpContext"/> being routed</param>
 protected void OnAfterRouting(IHttpContext context)
 {
     After?.Invoke(context);
     if (AfterRouting == null)
     {
         return;
     }
     foreach (var action in AfterRouting.GetInvocationList().Reverse().Cast <RoutingEventHandler>())
     {
         action(context);
     }
 }
Exemplo n.º 3
0
        public bool Route(IHttpContext context, IList <IRoute> routing)
        {
            if (routing == null || !routing.Any())
            {
                throw new RouteNotFoundException(context);
            }
            if (context.WasRespondedTo)
            {
                return(true);
            }

            var routeContext = context;
            var totalRoutes  = routing.Count;
            var routeCounter = 0;

            Logger.BeginRouting($"{context.Request.Id} - {context.Request.Name} has {totalRoutes} routes");

            if (Before != null)
            {
                routeContext = Before.Invoke(routeContext);
            }

            try
            {
                foreach (var route in routing.Where(route => route.Enabled))
                {
                    routeCounter++;
                    routeContext = route.Invoke(routeContext);

                    Logger.RouteInvoked($"{context.Request.Id} - {routeCounter}/{totalRoutes} {route.Name}");
                    if (ContinueRoutingAfterResponseSent)
                    {
                        continue;
                    }
                    if (routeContext.WasRespondedTo)
                    {
                        break;
                    }
                }
            }
            finally
            {
                if (After != null)
                {
                    routeContext = After.Invoke(routeContext);
                }
                Logger.EndRouting($"{context.Request.Id} - {routeCounter} of {totalRoutes} routes invoked");
            }

            return(routeContext.WasRespondedTo);
        }
Exemplo n.º 4
0
        public bool Route(IHttpContext context, IList <IRoute> routing)
        {
            if (routing == null || !routing.Any())
            {
                throw new RouteNotFoundException(context);
            }
            if (context.WasRespondedTo)
            {
                return(true);
            }

            LogBeginRequestRouting(context, routing.Count);
            var routeContext = context;
            var routeCounter = 0;

            if (Before != null)
            {
                routeContext = Before.Invoke(routeContext);
            }

            try
            {
                foreach (var route in routing.Where(route => route.Enabled))
                {
                    routeCounter++;
                    routeContext = route.Invoke(routeContext);

                    LogRouteInvoked(context, route, routeCounter);
                    if (ContinueRoutingAfterResponseSent)
                    {
                        continue;
                    }
                    if (routeContext.WasRespondedTo)
                    {
                        break;
                    }
                }
            }
            finally
            {
                if (After != null)
                {
                    routeContext = After.Invoke(routeContext);
                }
                LogEndRequestRouting(routeContext, routing.Count, routeCounter);
            }

            return(routeContext.WasRespondedTo);
        }
Exemplo n.º 5
0
        public IResult <TOutput> Parse(IParseState <TInput> state)
        {
            Assert.ArgumentNotNull(state, nameof(state));
            var startCheckpoint = state.Input.Checkpoint();
            var startConsumed   = state.Input.Consumed;

            Before?.Invoke(new Context(Inner, state, null));
            var result = Inner.Parse(state);

            After?.Invoke(new Context(Inner, state, result));
            var totalConsumed = state.Input.Consumed - startConsumed;

            // The callbacks have access to Input, so the user might consume data. Make sure
            // to report that if it happens.
            if (!result.Success)
            {
                startCheckpoint.Rewind();
                return(result);
            }

            return(result.AdjustConsumed(totalConsumed));
        }
Exemplo n.º 6
0
 private void OnAfter()
 {
     After?.Invoke(this, new EventArgs());
 }
Exemplo n.º 7
0
        /// <summary>
        /// Execute the job and trigger a completion event when complete.
        /// </summary>
        /// <param name="sender">Owner or input argument to job.</param>
        /// <param name="after">Completion event.</param>
        /// <returns>A Task class containing the job result.</returns>
        public virtual async Task Act(TSender sender, After after)
        {
            TResult result = await Task.Run(() => _job(sender));

            after?.Invoke(this, result);
        }