public void exceptionHandledBehavior(Action <IActionBehavior> behaviorAction)
        {
            if (InsideBehavior == null)
            {
                return;
            }

            try
            {
                behaviorAction(InsideBehavior);
            }
            catch (Exception exception)
            {
                _logger.LogError("An API action threw an exception.", exception);

                if (!AspNetSettings.IsCustomErrorsEnabled || _requestData.IsAjaxRequest())
                {
                    throw;
                }

                var request = new T {
                    Exception = exception
                };
                _request.Set(request);

                _fubuPartialService.Invoke(typeof(T));

                _writer.WriteResponseCode(HttpStatusCode.InternalServerError);
            }
        }
Пример #2
0
        protected override DoNext performInvoke()
        {
            TOutput output = _action(_controller);

            _request.Set(output);
            return(DoNext.Continue);
        }
Пример #3
0
        public virtual void Execute(object message)
        {
            var inputType = message.GetType();

            _request.Set(inputType, message);

            var chain = _graph.ChainFor(inputType);

            if (chain == null)
            {
                throw new NoHandlerException(inputType);
            }

            try
            {
                _factory.BuildPartial(chain).InvokePartial();
                _logger.DebugMessage(() => new InlineMessageProcessed
                {
                    Envelope = _envelope,
                    Message  = message
                });
            }
            catch (Exception e)
            {
                _logger.Error(_envelope.CorrelationId, "Failed processing inline message " + message, e);
                throw;
            }

            _request.Clear(inputType);
        }
Пример #4
0
        public void Render <T>(IFubuPage view, T viewModel, string prefix, TextWriter writer, int?index = null) where T : class
        {
            var page = new Page();

            page.Controls.Add(view as Control);

            if (viewModel != null)
            {
                _request.Set(viewModel.GetType(), viewModel);
            }
            _activator.Activate(view);

            setParentPageIfNotAlreadySet(view, page);

            if (index.HasValue)
            {
                prefix = "{0}[{1}]".ToFormat(prefix, index);
            }

            view.ElementPrefix = prefix;

            _builder.ExecuteControl(page, writer);

            writer.Flush();
        }
Пример #5
0
        public string InvokeObject(object model, bool withModelBinding = false, string categoryOrHttpMethod = null)
        {
            var output = string.Empty;

            if (_authorization.IsAuthorized(model))
            {
                var requestType = _types.ResolveType(model);
                if (withModelBinding)
                {
                    _setterBinder.BindProperties(requestType, model);
                }
                _request.Set(requestType, model);
                output = invokeWrapped(requestType, categoryOrHttpMethod);
            }
            return(output);
        }
        private FormRequest requestFor <T>() where T : class, new()
        {
            var services = new InMemoryServiceLocator();

            services.Add <IChainResolver>(new ChainResolutionCache(theGraph));
            services.Add <IChainUrlResolver>(new ChainUrlResolver(new OwinHttpRequest()));

            theRequest      = new InMemoryFubuRequest();
            theNotification = Notification.Valid();
            theRequest.Set(theNotification);

            services.Add(theRequest);

            var request = new FormRequest(new ChainSearch {
                Type = typeof(T)
            }, new T());

            request.Attach(services);
            request.ReplaceTag(new FormTag("test"));

            theContinuation = AjaxContinuation.Successful();
            theContinuation.ShouldRefresh = true;

            var resolver = MockRepository.GenerateStub <IAjaxContinuationResolver>();

            resolver.Stub(x => x.Resolve(theNotification)).Return(theContinuation);

            services.Add(resolver);

            return(request);
        }
        public void exceptionHandledBehavior(Action <IActionBehavior> behaviorAction)
        {
            if (InsideBehavior == null)
            {
                return;
            }

            try
            {
                behaviorAction(InsideBehavior);
            }
            catch (Exception exception)
            {
                _logger.LogError("An API action threw an exception.", exception);

                if (!AspNetSettings.IsCustomErrorsEnabled)
                {
                    throw;
                }

                var request = new T {
                    Exception = exception
                };
                _request.Set(request);
                var partial = _factory.BuildPartial(request.GetType());
                partial.InvokePartial();

                _writer.WriteResponseCode(HttpStatusCode.InternalServerError);
            }
        }
            public string get_partial(PartialInput input)
            {
                var builder       = new StringBuilder();
                var partialModels = new[]
                {
                    new PartialViewModel {
                        Name = "Item1"
                    },
                    new PartialViewModel {
                        Name = "Item2"
                    },
                    new PartialViewModel {
                        Name = "Item3"
                    }
                };

                partialModels.Each(m =>
                {
                    _request.Set(m);
                    var page = new Core.UI.FubuHtmlDocument <PartialViewModel>(_locator, _request);
                    builder.AppendLine(SourceModifier(page).ToString());
                    //builder.AppendLine();
                });

                return(builder.ToString());
            }
Пример #9
0
        protected override DoNext performInvoke()
        {
            // Might already be there from a different way
            if (_request.Has <T>())
            {
                return(DoNext.Continue);
            }

            var mimeTypes = _request.Get <CurrentMimeType>();


            var reader = ChooseReader(mimeTypes);

            _logger.DebugMessage(() => new ReaderChoice(mimeTypes, reader));

            if (reader == null)
            {
                failWithInvalidMimeType();
                return(DoNext.Stop);
            }

            var target = reader.Read(mimeTypes.ContentType);

            _request.Set(target);

            return(DoNext.Continue);
        }
Пример #10
0
        public void Handle(Notification notification)
        {
            var continuation = _resolver.Resolve(notification);

            _output.WriteResponseCode(_settings.StatusCode);

            _request.Set(continuation);
        }
Пример #11
0
        protected override DoNext performInvoke()
        {
            var input = _reader.Read <T>();

            _request.Set(input);

            return(DoNext.Continue);
        }
Пример #12
0
        protected override DoNext performInvoke()
        {
            var item   = _request.Get <ItemRequest>();
            var entity = _repository.FindRequired <TEntity>(item.Id);

            _request.Set(entity);
            return(DoNext.Continue);
        }
Пример #13
0
        protected override DoNext performInvoke()
        {
            var     input  = _request.Get <TInput>();
            TOutput output = _action(_controller, input);

            _request.Set(output);

            return(DoNext.Continue);
        }
Пример #14
0
 public void InvokeObject(object model)
 {
     if (_authorization.IsAuthorized(model))
     {
         var requestType = _types.ResolveType(model);
         _request.Set(requestType, model);
         _factory.BuildPartial(requestType).InvokePartial();
     }
 }
Пример #15
0
        protected override AuthorizationRight findAnswerFromResolver(object model, Func <IChainResolver, BehaviorChain> finder)
        {
            if (model != null)
            {
                _request.Set(_types.ResolveType(model), model);
            }

            BehaviorChain chain = finder(resolver);

            return(rightsFor(chain));
        }
Пример #16
0
        public void Handle()
        {
            var requestModel = new RecordedRequestRequestModel {
                Id = _report.Id
            };

            _request.Set(requestModel);
            _partialFactory
            .BuildPartial(requestModel.GetType())
            .InvokePartial();
        }
Пример #17
0
        public AuthorizationRight Authorize(BehaviorChain chain, object model)
        {
            if (model != null)
            {
                _request.Set(_types.ResolveType(model), model);
            }

            var endpoint = _services.GetInstance <IEndPointAuthorizor>(chain.UniqueId.ToString());

            return(endpoint.IsAuthorized(_request));
        }
Пример #18
0
        public AuthorizationRight Authorize(BehaviorChain chain, object model)
        {
            if (model != null)
            {
                _request.Set(_types.ResolveType(model), model);
            }

            var endpoint = _factory.AuthorizorFor(chain.UniqueId);

            return(endpoint.IsAuthorized(_request));
        }
Пример #19
0
        public void Handle(Type modelType, Notification notification)
        {
            var jsonResponse = new JsonResponse();

            jsonResponse.RegisterErrors(notification.ToValidationErrors());

            _request.Set(jsonResponse);

            _factory
            .BuildPartial(jsonResponse.GetType())
            .InvokePartial();
        }
Пример #20
0
        protected override DoNext performInvoke()
        {
            // create the PrivateMessage object
            var message = createPrivateMessage();

            // store the PrivateMessage in
            // IFubuRequest where other Behavior's
            // could find it later
            _request.Set(message);

            return(DoNext.Continue);
        }
Пример #21
0
        public string InvokeObject(object model)
        {
            var output = string.Empty;

            if (_authorization.IsAuthorized(model))
            {
                var requestType = _types.ResolveType(model);
                _request.Set(requestType, model);
                output = invokeWrapped(requestType);
            }
            return(output);
        }
        protected override DoNext performInvoke()
        {
            try
            {
                var message = _request.Get <T>();
                _serviceBus.Send(message);

                _request.Set(AjaxContinuation.Successful());
            }
            catch (Exception e)
            {
                _request.Set(new AjaxContinuation
                {
                    Success = false
                });

                _logger.Error("Error trying to publish message of type " + typeof(T).FullName, e);
            }

            return(DoNext.Continue);
        }
Пример #23
0
        public string get_fast_partial()
        {
            var input = new FastInput {
                Name = "Malcolm Reynolds"
            };

            _request.Set(input);

            var chain  = _resolver.FindUniqueByType(typeof(FastInput));
            var output = _partialInvoker.InvokeFast(chain, input).As <FastOutput>();

            return("The name was " + output.Name);
        }
        public QueueMessageVisualization get_message_details_Port_QueueName_SourceInstanceId_MessageId(
            MessageInputModel input)
        {
            var messageId = new MessageId
            {
                MessageIdentifier = input.MessageId,
                SourceInstanceId  = input.SourceInstanceId
            };
            var message = RetrieveMessage(messageId, input.Port, input.QueueName);

            if (message == null)
            {
                _fubuRequest.Set(new QueueMessageNotFound
                {
                    Id        = messageId,
                    QueueName = input.QueueName
                });

                return(null);
            }

            var envelope = message.ToEnvelope();

            envelope.UseSerializer(_serializer);

            return(new QueueMessageVisualization
            {
                MessageId = messageId,
                QueueName = message.Queue,
                SubQueueName = message.SubQueue,
                Status = message.Status,
                SentAt = message.SentAt,
                Headers = message.Headers,
                Payload = envelope.Message
            });
        }
Пример #25
0
        protected override DoNext performInvoke()
        {
            var inputModel   = _request.Get <T>();
            var notification = _provider.Validate(inputModel);

            if (notification.IsValid())
            {
                return(DoNext.Continue);
            }

            _request.Set(notification);
            _failureHandler.Handle(typeof(T));

            return(DoNext.Stop);
        }
        protected override DoNext performInvoke()
        {
            var input = _request.Get <CharacterInput>();

            if (input.Race == "Ogre" && input.CharacterClass == "Paladin")
            {
                var continuation = new AjaxContinuation();
                continuation.Errors.Add(new AjaxError {
                    field = "Character", message = "Ogres cannot be Paladins!"
                });
                _request.Set(continuation);

                return(DoNext.Stop);
            }

            return(DoNext.Continue);
        }
        public void Failure()
        {
            var login   = _request.Get <T>();
            var request = new LoginRequest
            {
                Url     = login.Url,
                Message = LoginKeys.Unknown.ToString()
            };

            _request.Set(request);

            var chain = _graph.BehaviorFor(typeof(LoginRequest));

            _factory
            .BuildPartial(chain)
            .InvokePartial();
        }
Пример #28
0
        protected override DoNext performInvoke()
        {
            var mimeTypes = _request.Get <CurrentMimeType>();
            var reader    = ChooseReader(mimeTypes);

            if (reader == null)
            {
                failWithInvalidMimeType();
                return(DoNext.Stop);
            }

            var target = reader.Read(mimeTypes.ContentType);

            _request.Set(target);

            return(DoNext.Continue);
        }
Пример #29
0
        public async Task <string> InvokeObject(object model, bool withModelBinding = false, string categoryOrHttpMethod = null)
        {
            var output = string.Empty;

            if (_authorization.IsAuthorized(model))
            {
                var requestType = model.GetType();
                if (withModelBinding)
                {
                    _setterBinder.BindProperties(requestType, model);
                }
                _request.Set(requestType, model);
                output = await invokeWrapped(requestType, categoryOrHttpMethod).ConfigureAwait(false);
            }
            return(output);
        }
Пример #30
0
        public AuthorizationRight RightsFor(IFubuRequest request)
        {
            var authToken = request.Get <AuthenticationTokenRequest>();

            //Workaround: RightsFor is getting called multiple times because of a Fubu bug
            if (request.Has <IAuthenticationToken>())
            {
                return(AuthorizationRight.Allow);
            }

            var token = authToken.authToken;

            if (token.IsEmpty())
            {
                if (_currentSdkUser.IsAuthenticated)
                {
                    _logger.LogDebug("No AuthToken was found in this request but a user is authenticated. Using the current user's credentials.");
                    return(AuthorizationRight.Allow);
                }

                return(AuthorizationRight.Deny);
            }

            _logger.LogDebug("Authentication token {0} found.", token);

            var authenticationToken = _tokenRepository.RetrieveByToken(token);

            if (authenticationToken == null)
            {
                return(AuthorizationRight.Deny);
            }

            _logger.LogDebug("Authentication token {0} found and validated for user {1}.", authenticationToken, authenticationToken);
            request.Set(authenticationToken);

            _currentSdkUser.SetUser(_principalFactory.CreatePrincipal(authenticationToken.Username));

            return(AuthorizationRight.Allow);
        }
        public AuthorizationRight RightsFor(IFubuRequest request)
        {
            var authToken = request.Get<AuthenticationTokenRequest>();

            //Workaround: RightsFor is getting called multiple times because of a Fubu bug
            if(request.Has<IAuthenticationToken>()) return AuthorizationRight.Allow;

            var token = authToken.authToken;

            if(token.IsEmpty())
            {
                if(_currentSdkUser.IsAuthenticated)
                {
                    _logger.LogDebug("No AuthToken was found in this request but a user is authenticated. Using the current user's credentials.");
                    return AuthorizationRight.Allow;
                }

                return AuthorizationRight.Deny;
            }

            _logger.LogDebug("Authentication token {0} found.", token);

            var authenticationToken = _tokenRepository.RetrieveByToken(token);
            if (authenticationToken == null)
            {
                return AuthorizationRight.Deny;

            }

            _logger.LogDebug("Authentication token {0} found and validated for user {1}.", authenticationToken, authenticationToken);
            request.Set(authenticationToken);

            _currentSdkUser.SetUser(_principalFactory.CreatePrincipal(authenticationToken.Username));

            return AuthorizationRight.Allow;
        }