public  Task Execute(Event state)
 {
     string connectionId;
     if (state.Properties.TryGetValue("signalr_connection_id", out connectionId))
     {
         return _hubContext.Clients.Client(connectionId).notify("Hi there from the NotificationHandler");
     }
     else {
         return _hubContext.Clients.All.notify("Hi EVERYBODY from the NotificationHandler");
     }
 }
        public virtual void Evaluate(Event state)
        {
            state.Properties["signalr_connection_id"] = Context.ConnectionId;

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                using (var nestedScope = Bootstrapper.Container.BeginLifetimeScope())
                {
                    var nestedEngine = nestedScope.Resolve<IRulesEngine>();
                    return nestedEngine.ExecuteAsync(state);
                }
            });  
        }
        public async Task<OperationResult> ExecuteAsync(Event state)
        {
            try
            {
                state.Date_Created = DateTime.UtcNow;
                _eventStore.AddEventItem(state);

                var ruleMapping =  _eventStore.GetRuleDefinitions().Where(r => r.Event_Type == state.Event_Type);

                if (!ruleMapping.Any())
                {
                    return new OperationResult(OperationStatus.Failure, String.Format("A mapping for {0} does not exisit.", state.Event_Type));
                }

                //this looks over every rule definition
                var evaluations = ruleMapping.Select(c =>
                {
                    var evaluator = _specs.Where(e => e.Metadata.Code == c.Spec_Code).Select(e => e.Value).SingleOrDefault();

                    var task = (evaluator == null ? Task.FromResult(false) : evaluator.IsSatisfiedBy(state));

                    return task.ContinueWith(t =>
                                 {
                                     if (!t.IsFaulted && t.Result)
                                     {
                                         var handler = _handlers.Where(e => e.Metadata.Code == c.Handler_Code).Select(e => e.Value).SingleOrDefault();
                                         if (handler != null) handler.Execute(state);
                                     }
                                 }, TaskContinuationOptions.ExecuteSynchronously);

                });

                await Task.WhenAll(evaluations).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                return new OperationResult(OperationStatus.Failure, "Unable to evaluate event");
            }

            return new OperationResult(OperationStatus.Success, "Works, I guess?");
        }
        public IHttpActionResult Evaluate(Event state)
        {
            // Don't make this habbit in your production application
            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                try
                {
                    using (var nestedScope = Bootstrapper.Container.BeginLifetimeScope())
                    {
                        var nestedEngine = nestedScope.Resolve<IRulesEngine>();
                        return nestedEngine.ExecuteAsync(state);
                    }
                }
                catch (Exception e) {

                    return Task.FromException(e);
                }
            });

            return StatusCode(HttpStatusCode.Accepted);
        }
 public virtual void AddEventItem(Event state)
 {
     var result = _r.db(DATABASE_NAME).table(EVENTS_TABLE_NAME)
         .insert(state).run(_conn);
 }
 public Task Execute(Event state)
 {
     return Task.CompletedTask;
 }
 public virtual Task<bool> IsSatisfiedBy(Event instance)
 {
     return Task.FromResult(true);
 }
    public Task<bool> IsSatisfiedBy(Event instance)
 {
     return Task.FromResult<bool>(false);
 }