public ServiceConfigurationBuilder(INavigationService navigationService, IActionInvokerFactory invokerFactory)
 {
     _navigationService = navigationService;
     _configuration     = ServiceConfiguration.CreateSilently(
         "My configuration name", "http://baseuri",
         _navigationService, invokerFactory);
 }
Ejemplo n.º 2
0
        public MvcEndpointDataSource(IActionInvokerFactory actionInvokerFactory,
                                     IActionDescriptorProvider actionDiscriptorProvider,
                                     RoutePatternTransformer transformer)
        {
            _actionInvokerFactory = actionInvokerFactory;

            _endpoints = new Lazy <IReadOnlyList <Endpoint> >(Create());

            List <Endpoint> Create()
            {
                var Descriptors = actionDiscriptorProvider.GetActionDescriptors;

                return(Descriptors.Select(CreateEndpoint).ToList());
            }

            Endpoint CreateEndpoint(ActionDescriptor actionDiscriptor)
            {
                var routePattern    = RoutePatternFactory.Parse(actionDiscriptor.RouteInfo.Template);
                var newRoutePattern = transformer.SubstituteRequiredValues(routePattern, new Dictionary <string, string>
                {
                    ["controller"] = actionDiscriptor.ControllerName,
                    ["action"]     = actionDiscriptor.ActionName
                });

                routePattern = routePattern ?? newRoutePattern;
                var endPointBuilder = new RouteEndpointBuilder(InvokeAsync, routePattern, actionDiscriptor.RouteInfo.Order ?? 0);

                endPointBuilder.Metadata.Add(actionDiscriptor);
                return(endPointBuilder.Build());
            }
        }
Ejemplo n.º 3
0
        private void EnsureServices(HttpContext context)
        {
            if (_actionContextAccessor == null)
            {
                _actionContextAccessor = context.RequestServices.GetRequiredService <IActionContextAccessor>();
            }

            if (_actionInvokerFactory == null)
            {
                _actionInvokerFactory = context.RequestServices.GetRequiredService <IActionInvokerFactory>();
            }

            if (_actionSelector == null)
            {
                _actionSelector = context.RequestServices.GetRequiredService <IActionSelector>();
            }

            if (_logger == null)
            {
                var factory = context.RequestServices.GetRequiredService <ILoggerFactory>();
                _logger = factory.CreateLogger <MvcRouteHandler>();
            }

            if (_diagnosticSource == null)
            {
                _diagnosticSource = context.RequestServices.GetRequiredService <DiagnosticSource>();
            }
        }
Ejemplo n.º 4
0
 private ServiceConfiguration(INavigationService navigationService, IActionInvokerFactory invokerFactory, bool editMode) : base(editMode)
 {
     _navigationService    = navigationService;
     _invokerFactory       = invokerFactory;
     ActionGroups          = new ObservableCollectionWithAddRange <ActionGroup>();
     AddActionGroupCommand = new RelayCommand(() =>
     {
         ActionGroups.Add(ActionGroup.CreateSilently("", this, _navigationService, EditMode));
         NotifyThatSomethingIsChanged();
     });
     InvokeUriCommand = new RelayCommand <ServiceAction>(async action =>
     {
         if (EditMode)
         {
             _navigationService.NavigateTo(ActionPage.Key, action);
         }
         else
         {
             action.Processing = true;
             Messenger.Default.Send(new ActionProcessingMessage());
             ((RelayCommand <ServiceAction>)InvokeUriCommand).RaiseCanExecuteChanged();
             await InvokeRestActionAsync(action);
             action.Processing = false;
             ((RelayCommand <ServiceAction>)InvokeUriCommand).RaiseCanExecuteChanged();
             await Task.Delay(1000); //The spinner animation should run at least 1 second
             Messenger.Default.Send(new ActionCompletedMessage());
         }
     }, action => action != null && !action.Processing);
     DeleteActionGroupCommand = new RelayCommand <ActionGroup>(group =>
     {
         ActionGroups.Remove(group);
         NotifyThatSomethingIsChanged();
     });
 }
Ejemplo n.º 5
0
        private void EnsureServices(HttpContext context)
        {
            if (_servicesRetrieved)
            {
                return;
            }

            var services = context.RequestServices;

            // Verify if AddMvc was done before calling UseMvc
            // We use the MvcMarkerService to make sure if all the services were added.
            MvcServicesHelper.ThrowIfMvcNotRegistered(services);

            // The IActionContextAccessor is optional. We want to avoid the overhead of using CallContext
            // if possible.
            _actionContextAccessor = services.GetService <IActionContextAccessor>();

            _actionInvokerFactory = services.GetRequiredService <IActionInvokerFactory>();
            _actionSelector       = services.GetRequiredService <IActionSelector>();
            _diagnosticSource     = services.GetRequiredService <DiagnosticSource>();

            var factory = services.GetRequiredService <ILoggerFactory>();

            _logger = factory.CreateLogger <MvcRouteHandler>();

            _servicesRetrieved = true;
        }
 public ServiceConfigurationBuilder(INavigationService navigationService, IActionInvokerFactory invokerFactory)
 {
     _navigationService = navigationService;
     _configuration = ServiceConfiguration.CreateSilently(
         "My configuration name", "http://baseuri",
         _navigationService, invokerFactory);
 }
Ejemplo n.º 7
0
 public MainViewModel(IConfigurationStore configurationStore, INavigationService navigationService, IActionInvokerFactory invokerFactory,
                      IDialog dialog, IFilePicker filePicker)
 {
     _configurationStore = configurationStore;
     _navigationService  = navigationService; //For some reason, the navigation does not work if not kept as a member
     _invokerFactory     = invokerFactory;
     _dialog             = dialog;
     _filePicker         = filePicker;
     LoadData();
     _dispatcher = Window.Current.Dispatcher;
     InitHandlers();
     Messenger.Default.Register <SomethingIsChangedMessage>(this, async _ => await StoreDataAsync());
     Messenger.Default.Register <UpdateButtonSizeMessage>(this, UpdateButtonSizes);
     NavigateToLogCommand       = new RelayCommand(() => _navigationService.NavigateTo(LogPage.Key));
     EditModeCommand            = new RelayCommand(() => EditMode = true);
     EditCompletedCommand       = new RelayCommand(() => EditMode = false);
     DeleteConfigurationCommand = new RelayCommand <ServiceConfiguration>(async configuration =>
     {
         Configurations.Remove(configuration);
         await StoreDataAsync();
     });
     AddConfigurationCommand     = new RelayCommand(AddEmptyServiceConfiguration);
     ExportConfigurationsCommand = new RelayCommand(async() => await ExportConfigurationsAsync());
     ImportConfigurationsCommand = new RelayCommand(async() => await PickFileAndImportSerficeConfigurationsAsync());
     NavigateToAboutPageCommand  = new RelayCommand(() => _navigationService.NavigateTo(AboutPage.Key));
 }
Ejemplo n.º 8
0
 public OeRouter(IActionInvokerFactory actionInvokerFactory, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider,
                 IEdmModel edmModel)
 {
     _actionInvokerFactory = actionInvokerFactory;
     _actionDescriptors    = actionDescriptorCollectionProvider.ActionDescriptors;
     _edmModel             = edmModel;
 }
        private MvcRouteHandler CreateMvcRouteHandler(
            ActionDescriptor actionDescriptor    = null,
            IActionSelector actionSelector       = null,
            IActionInvokerFactory invokerFactory = null,
            ILoggerFactory loggerFactory         = null,
            object diagnosticListener            = null)
        {
            var actionContextAccessor = new ActionContextAccessor();

            if (actionDescriptor == null)
            {
                var mockAction = new Mock <ActionDescriptor>();
                actionDescriptor = mockAction.Object;
            }

            if (actionSelector == null)
            {
                var mockActionSelector = new Mock <IActionSelector>();
                mockActionSelector
                .Setup(a => a.SelectCandidates(It.IsAny <RouteContext>()))
                .Returns(new ActionDescriptor[] { actionDescriptor });

                mockActionSelector
                .Setup(a => a.SelectBestCandidate(It.IsAny <RouteContext>(), It.IsAny <IReadOnlyList <ActionDescriptor> >()))
                .Returns(actionDescriptor);
                actionSelector = mockActionSelector.Object;
            }

            if (loggerFactory == null)
            {
                loggerFactory = NullLoggerFactory.Instance;
            }

            var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore");

            if (diagnosticListener != null)
            {
                diagnosticSource.SubscribeWithAdapter(diagnosticListener);
            }

            if (invokerFactory == null)
            {
                var mockInvoker = new Mock <IActionInvoker>();
                mockInvoker.Setup(i => i.InvokeAsync())
                .Returns(Task.FromResult(true));

                var mockInvokerFactory = new Mock <IActionInvokerFactory>();
                mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny <ActionContext>()))
                .Returns(mockInvoker.Object);

                invokerFactory = mockInvokerFactory.Object;
            }

            return(new MvcRouteHandler(
                       invokerFactory,
                       actionSelector,
                       diagnosticSource,
                       loggerFactory,
                       actionContextAccessor));
        }
Ejemplo n.º 10
0
        private MvcRouteHandler CreateMvcRouteHandler(
            ActionDescriptor actionDescriptor = null,
            IActionSelector actionSelector = null,
            IActionInvokerFactory invokerFactory = null,
            ILoggerFactory loggerFactory = null,
            object diagnosticListener = null)
        {
            var actionContextAccessor = new ActionContextAccessor();

            if (actionDescriptor == null)
            {
                var mockAction = new Mock<ActionDescriptor>();
                actionDescriptor = mockAction.Object;
            }

            if (actionSelector == null)
            {
                var mockActionSelector = new Mock<IActionSelector>();
                mockActionSelector
                    .Setup(a => a.SelectCandidates(It.IsAny<RouteContext>()))
                    .Returns(new ActionDescriptor[] { actionDescriptor });

                mockActionSelector
                    .Setup(a => a.SelectBestCandidate(It.IsAny<RouteContext>(), It.IsAny<IReadOnlyList<ActionDescriptor>>()))
                    .Returns(actionDescriptor);
                actionSelector = mockActionSelector.Object;
            }

            if (loggerFactory == null)
            {
                loggerFactory = NullLoggerFactory.Instance;
            }

            var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore");
            if (diagnosticListener != null)
            {
                diagnosticSource.SubscribeWithAdapter(diagnosticListener);
            }

            if (invokerFactory == null)
            {
                var mockInvoker = new Mock<IActionInvoker>();
                mockInvoker.Setup(i => i.InvokeAsync())
                    .Returns(Task.FromResult(true));

                var mockInvokerFactory = new Mock<IActionInvokerFactory>();
                mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>()))
                    .Returns(mockInvoker.Object);

                invokerFactory = mockInvokerFactory.Object;
            }

            return new MvcRouteHandler(
                invokerFactory,
                actionSelector,
                diagnosticSource,
                loggerFactory,
                actionContextAccessor);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultApiVersionRoutePolicy"/> class.
 /// </summary>
 /// <param name="actionInvokerFactory">The underlying <see cref="IActionInvokerFactory">action invoker factory</see>.</param>
 /// <param name="errorResponseProvider">The <see cref="IErrorResponseProvider">provider</see> used to create error responses.</param>
 /// <param name="reportApiVersions">The <see cref="IReportApiVersions">object</see> used to report API versions.</param>
 /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
 public DefaultApiVersionRoutePolicy(
     IActionInvokerFactory actionInvokerFactory,
     IErrorResponseProvider errorResponseProvider,
     IReportApiVersions reportApiVersions,
     ILoggerFactory loggerFactory)
     : this(actionInvokerFactory, errorResponseProvider, reportApiVersions, loggerFactory, null)
 {
 }
Ejemplo n.º 12
0
 public MvcRouteHandler(
     IActionInvokerFactory actionInvokerFactory,
     IActionSelector actionSelector,
     DiagnosticSource diagnosticSource,
     ILoggerFactory loggerFactory)
     : this(actionInvokerFactory, actionSelector, diagnosticSource, loggerFactory, actionContextAccessor: null)
 {
 }
Ejemplo n.º 13
0
 public MvcAttributeRouteHandler(
     IActionInvokerFactory actionInvokerFactory,
     IActionSelector actionSelector,
     DiagnosticListener diagnosticListener,
     ILoggerFactory loggerFactory)
     : this(actionInvokerFactory, actionSelector, diagnosticListener, loggerFactory, actionContextAccessor : null)
 {
 }
Ejemplo n.º 14
0
 public MvcRouteHandler(
     IActionInvokerFactory actionInvokerFactory,
     IActionSelector actionSelector,
     DiagnosticSource diagnosticSource,
     ILoggerFactory loggerFactory)
     : this(actionInvokerFactory, actionSelector, diagnosticSource, loggerFactory, actionContextAccessor : null)
 {
 }
Ejemplo n.º 15
0
 public OeRouter(IActionInvokerFactory actionInvokerFactory, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider,
                 IEdmModel edmModel, OeDataAdapter dataAdapter, IUrlHelperFactory urlHelperFactory)
 {
     _actionInvokerFactory = actionInvokerFactory;
     _actionDescriptors    = actionDescriptorCollectionProvider.ActionDescriptors;
     _edmModel             = edmModel;
     _dataAdapter          = dataAdapter;
 }
Ejemplo n.º 16
0
 public PlatoRouter(
     IActionInvokerFactory actionInvokerFactory,
     IActionSelector actionSelector,
     ILoggerFactory loggerFactory)
 {
     _logger = loggerFactory.CreateLogger <PlatoRouter>();
     _actionInvokerFactory = actionInvokerFactory;
     _actionSelector       = actionSelector;
 }
Ejemplo n.º 17
0
 public static ServiceConfiguration CreateSilently(string name, string baseUri, INavigationService navigationService,
                                                   IActionInvokerFactory invokerFactory, bool editMode = false)
 {
     return(new ServiceConfiguration(navigationService, invokerFactory, editMode)
     {
         _name = name,
         _baseUri = baseUri
     });
 }
Ejemplo n.º 18
0
 public static ServiceConfiguration CreateSilently(string name, string baseUri, INavigationService navigationService,
     IActionInvokerFactory invokerFactory, bool editMode = false)
 {
     return new ServiceConfiguration(navigationService, invokerFactory, editMode)
     {
         _name = name,
         _baseUri = baseUri
     };
 }
Ejemplo n.º 19
0
        public Task ExecuteAsync(IOwinContext context, IRouteData routeData)
        {
            var requestContext = new RequestContext(context, routeData);

            IActionInvokerFactory invokerFactory = _serviceProvider.GetService <IActionInvokerFactory>();

            var invoker = invokerFactory.CreateInvoker(requestContext);

            return(invoker.InvokeActionAsync());
        }
        public MvcEndpointInvokerFactory(
            IActionInvokerFactory invokerFactory,
            IActionContextAccessor actionContextAccessor)
        {
            _invokerFactory = invokerFactory;

            // The IActionContextAccessor is optional. We want to avoid the overhead of using CallContext
            // if possible.
            _actionContextAccessor = actionContextAccessor;
        }
Ejemplo n.º 21
0
        private RouteContext CreateRouteContext(
            IActionSelector actionSelector       = null,
            IActionInvokerFactory invokerFactory = null,
            ILoggerFactory loggerFactory         = null)
        {
            var mockContextAccessor = new Mock <IContextAccessor <ActionContext> >();

            mockContextAccessor.Setup(c => c.SetContextSource(
                                          It.IsAny <Func <ActionContext> >(),
                                          It.IsAny <Func <ActionContext, ActionContext> >()))
            .Returns(NullDisposable.Instance);


            if (actionSelector == null)
            {
                var mockAction = new Mock <ActionDescriptor>();

                var mockActionSelector = new Mock <IActionSelector>();
                mockActionSelector.Setup(a => a.SelectAsync(It.IsAny <RouteContext>()))
                .Returns(Task.FromResult(mockAction.Object));

                actionSelector = mockActionSelector.Object;
            }

            if (invokerFactory == null)
            {
                var mockInvoker = new Mock <IActionInvoker>();
                mockInvoker.Setup(i => i.InvokeActionAsync())
                .Returns(Task.FromResult <object>(null));

                var mockInvokerFactory = new Mock <IActionInvokerFactory>();
                mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny <ActionContext>()))
                .Returns(mockInvoker.Object);

                invokerFactory = mockInvokerFactory.Object;
            }

            if (loggerFactory == null)
            {
                loggerFactory = NullLoggerFactory.Instance;
            }

            var httpContext = new Mock <HttpContext>();

            httpContext.Setup(h => h.RequestServices.GetService(typeof(IContextAccessor <ActionContext>)))
            .Returns(mockContextAccessor.Object);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector)))
            .Returns(actionSelector);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory)))
            .Returns(invokerFactory);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory)))
            .Returns(loggerFactory);

            return(new RouteContext(httpContext.Object));
        }
Ejemplo n.º 22
0
 public MvcAttributeRouteHandler(
     IActionInvokerFactory actionInvokerFactory,
     IActionSelector actionSelector,
     DiagnosticListener diagnosticListener,
     ILoggerFactory loggerFactory)
 {
     _actionInvokerFactory = actionInvokerFactory;
     _actionSelector       = actionSelector;
     _diagnosticListener   = diagnosticListener;
     _logger = loggerFactory.CreateLogger <MvcAttributeRouteHandler>();
 }
Ejemplo n.º 23
0
 public AreaRouter(IActionInvokerFactory actionInvokerFactory, IActionSelector actionSelector, DiagnosticSource diagnosticSource,
                   ILoggerFactory loggerFactory, IActionContextAccessor actionContextAccessor)
     : base(actionInvokerFactory, actionSelector, diagnosticSource,
            loggerFactory, actionContextAccessor)
 {
     _actionContextAccessor = actionContextAccessor;
     _actionInvokerFactory  = actionInvokerFactory;
     _actionSelector        = actionSelector;
     _diagnosticSource      = diagnosticSource;
     _logger = loggerFactory.CreateLogger <MvcRouteHandler>();
 }
Ejemplo n.º 24
0
 public PlatoRouter(
     IActionInvokerFactory actionInvokerFactory,
     DiagnosticListener diagnosticListener,
     IActionSelector actionSelector,
     ILoggerFactory loggerFactory)
 {
     _logger = loggerFactory.CreateLogger <PlatoRouter>();
     _actionInvokerFactory = actionInvokerFactory;
     _diagnosticListener   = diagnosticListener;
     _actionSelector       = actionSelector;
 }
Ejemplo n.º 25
0
 internal DefaultActionHandler(
     IActionInvokerFactory actionInvokerFactory,
     IActionContextAccessor actionContextAccessor,
     ActionSelectionResult selectionResult,
     ActionDescriptorMatch match)
 {
     this.actionContextAccessor = actionContextAccessor;
     this.actionInvokerFactory  = actionInvokerFactory;
     this.selectionResult       = selectionResult;
     this.match = match;
 }
Ejemplo n.º 26
0
 public JsonApiRouteHandler(
     IActionInvokerFactory actionInvokerFactory,
     IActionSelector actionSelector,
     IActionContextAccessor actionContextAccessor)
 {
     // The IActionContextAccessor is optional. We want to avoid the overhead of using CallContext
     // if possible.
     _actionContextAccessor = actionContextAccessor;
     _actionInvokerFactory  = actionInvokerFactory;
     _actionSelector        = actionSelector;
 }
Ejemplo n.º 27
0
        public OeRouter(IActionInvokerFactory actionInvokerFactory, IActionSelector actionSelector, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider,
                        IEdmModel edmModel, OeDataAdapter dataAdapter)
        {
            _actionInvokerFactory = actionInvokerFactory;
            _actionSelector       = actionSelector;
            _actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
            _edmModel    = edmModel;
            _dataAdapter = dataAdapter;

            _operationDescriptors = GetOperationDescriptors(actionDescriptorCollectionProvider.ActionDescriptors.Items);
            _operationImports     = edmModel.EntityContainer.OperationImports().ToDictionary(o => o.Name);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultApiVersionRoutePolicy"/> class.
        /// </summary>
        /// <param name="actionInvokerFactory">The underlying <see cref="IActionInvokerFactory">action invoker factory</see>.</param>
        /// <param name="errorResponseProvider">The <see cref="IErrorResponseProvider">provider</see> used to create error responses.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
        /// <param name="actionContextAccessor">The associated <see cref="IActionContextAccessor">action context accessor</see>.</param>
        public DefaultApiVersionRoutePolicy(
            IActionInvokerFactory actionInvokerFactory,
            IErrorResponseProvider errorResponseProvider,
            ILoggerFactory loggerFactory,
            IActionContextAccessor actionContextAccessor)
        {
            Arg.NotNull(actionInvokerFactory, nameof(actionInvokerFactory));
            Arg.NotNull(errorResponseProvider, nameof(errorResponseProvider));
            Arg.NotNull(loggerFactory, nameof(loggerFactory));

            ErrorResponseProvider = errorResponseProvider;
            ActionInvokerFactory  = actionInvokerFactory;
            Logger = loggerFactory.CreateLogger(GetType());
            ActionContextAccessor = actionContextAccessor;
        }
Ejemplo n.º 29
0
        public MvcRouteHandler(
            IActionInvokerFactory actionInvokerFactory,
            IActionSelector actionSelector,
            DiagnosticSource diagnosticSource,
            ILoggerFactory loggerFactory,
            IActionContextAccessor actionContextAccessor)
        {
            // The IActionContextAccessor is optional. We want to avoid the overhead of using CallContext
            // if possible.
            _actionContextAccessor = actionContextAccessor;

            _actionInvokerFactory = actionInvokerFactory;
            _actionSelector = actionSelector;
            _diagnosticSource = diagnosticSource;
            _logger = loggerFactory.CreateLogger<MvcRouteHandler>();
        }
Ejemplo n.º 30
0
        public MvcRouteHandler(
            IActionInvokerFactory actionInvokerFactory,
            IActionSelector actionSelector,
            DiagnosticSource diagnosticSource,
            ILoggerFactory loggerFactory,
            IActionContextAccessor actionContextAccessor)
        {
            // The IActionContextAccessor is optional. We want to avoid the overhead of using CallContext
            // if possible.
            _actionContextAccessor = actionContextAccessor;

            _actionInvokerFactory = actionInvokerFactory;
            _actionSelector       = actionSelector;
            _diagnosticSource     = diagnosticSource;
            _logger = loggerFactory.CreateLogger <MvcRouteHandler>();
        }
        /// <summary>
        /// Creates an action invoker.
        /// </summary>
        ///
        /// <returns>
        /// An action invoker.
        /// </returns>
        protected virtual IActionInvoker CreateActionInvoker()
        {
            IAsyncActionInvokerFactory service1 = Resolver.GetService <IAsyncActionInvokerFactory>();

            if (service1 != null)
            {
                return(service1.CreateInstance());
            }

            IActionInvokerFactory service2 = Resolver.GetService <IActionInvokerFactory>();

            if (service2 != null)
            {
                return(service2.CreateInstance());
            }
            return(Resolver.GetService <IAsyncActionInvoker>() ?? Resolver.GetService <IActionInvoker>() ?? new AsyncControllerActionInvoker());
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultApiVersionRoutePolicy"/> class.
        /// </summary>
        /// <param name="actionInvokerFactory">The underlying <see cref="IActionInvokerFactory">action invoker factory</see>.</param>
        /// <param name="errorResponseProvider">The <see cref="IErrorResponseProvider">provider</see> used to create error responses.</param>
        /// <param name="reportApiVersions">The <see cref="IReportApiVersions">object</see> used to report API versions.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
        /// <param name="actionContextAccessor">The associated <see cref="IActionContextAccessor">action context accessor</see>.</param>
        /// <param name="options">The <see cref="ApiVersioningOptions">options</see> associated with the route policy.</param>
        public DefaultApiVersionRoutePolicy(
            IActionInvokerFactory actionInvokerFactory,
            IErrorResponseProvider errorResponseProvider,
            IReportApiVersions reportApiVersions,
            ILoggerFactory loggerFactory,
            IActionContextAccessor actionContextAccessor,
            IOptions <ApiVersioningOptions> options = null)
        {
            Arg.NotNull(actionInvokerFactory, nameof(actionInvokerFactory));
            Arg.NotNull(errorResponseProvider, nameof(errorResponseProvider));
            Arg.NotNull(reportApiVersions, nameof(reportApiVersions));
            Arg.NotNull(loggerFactory, nameof(loggerFactory));

            ErrorResponseProvider = errorResponseProvider;
            ActionInvokerFactory  = actionInvokerFactory;
            ApiVersionReporter    = reportApiVersions;
            Logger = loggerFactory.CreateLogger(GetType());
            ActionContextAccessor = actionContextAccessor;
            this.options          = options ?? new OptionsWrapper <ApiVersioningOptions>(new ApiVersioningOptions());
        }
Ejemplo n.º 33
0
        public MvcDispatcherDataSource(
            IActionDescriptorCollectionProvider actions,
            IActionInvokerFactory invokerFactory)
        {
            if (actions == null)
            {
                throw new ArgumentNullException(nameof(actions));
            }

            if (invokerFactory == null)
            {
                throw new ArgumentNullException(nameof(invokerFactory));
            }

            _invokerFactory = invokerFactory;

            // note: this code has haxxx. This will only work in some constrained scenarios
            foreach (var action in actions.ActionDescriptors.Items)
            {
                Endpoints.Add(new HttpEndpoint(
                                  action.AttributeRouteInfo.Template,
                                  action.RouteValues,
                                  action.ActionConstraints?.OfType <HttpMethodActionConstraint>().FirstOrDefault()?.HttpMethods.FirstOrDefault(),
                                  async(context) =>
                {
                    var values    = context.Features.Get <IDispatcherFeature>().Values;
                    var routeData = new RouteData();
                    foreach (var kvp in values)
                    {
                        routeData.Values.Add(kvp.Key, kvp.Value);
                    }

                    var actionContext = new ActionContext(context, routeData, action);
                    var invoker       = _invokerFactory.CreateInvoker(actionContext);
                    await invoker.InvokeAsync();
                },
                                  action.DisplayName,
                                  action.FilterDescriptors.OrderBy(f => f, FilterDescriptorOrderComparer.Comparer).Select(f => f.Filter).ToArray()));
            }
        }
Ejemplo n.º 34
0
        protected virtual IActionInvoker CreateActionInvoker()
        {
            // Controller supports asynchronous operations by default.
            // Those factories can be customized in order to create an action invoker for each request.
            IAsyncActionInvokerFactory asyncActionInvokerFactory = Resolver.GetService <IAsyncActionInvokerFactory>();

            if (asyncActionInvokerFactory != null)
            {
                return(asyncActionInvokerFactory.CreateInstance());
            }
            IActionInvokerFactory actionInvokerFactory = Resolver.GetService <IActionInvokerFactory>();

            if (actionInvokerFactory != null)
            {
                return(actionInvokerFactory.CreateInstance());
            }

            // Note that getting a service from the current cache will return the same instance for every request.
            return(Resolver.GetService <IAsyncActionInvoker>() ??
                   Resolver.GetService <IActionInvoker>() ??
                   new AsyncControllerActionInvoker());
        }
Ejemplo n.º 35
0
        private void EnsureServices(HttpContext context)
        {
            if (_servicesRetrieved)
            {
                return;
            }

            var services = context.RequestServices;

            // The IActionContextAccessor is optional. We want to avoid the overhead of using CallContext
            // if possible.
            _actionContextAccessor = services.GetService <IActionContextAccessor>();

            _actionInvokerFactory = services.GetRequiredService <IActionInvokerFactory>();
            _actionSelector       = services.GetRequiredService <IActionSelector>();
            _diagnosticSource     = services.GetRequiredService <DiagnosticSource>();

            var factory = services.GetRequiredService <ILoggerFactory>();

            _logger = factory.CreateLogger <MvcRouteHandler>();

            _servicesRetrieved = true;
        }
Ejemplo n.º 36
0
        private void EnsureServices(HttpContext context)
        {
            if (_servicesRetrieved)
            {
                return;
            }

            var services = context.RequestServices;

            // Verify if AddMvc was done before calling UseMvc
            // We use the MvcMarkerService to make sure if all the services were added.
            MvcServicesHelper.ThrowIfMvcNotRegistered(services);

            // The IActionContextAccessor is optional. We want to avoid the overhead of using CallContext
            // if possible.
            _actionContextAccessor = services.GetService<IActionContextAccessor>();

            _actionInvokerFactory = services.GetRequiredService<IActionInvokerFactory>();
            _actionSelector = services.GetRequiredService<IActionSelector>();
            _diagnosticSource = services.GetRequiredService<DiagnosticSource>();

            var factory = services.GetRequiredService<ILoggerFactory>();
            _logger = factory.CreateLogger<MvcRouteHandler>();

            _servicesRetrieved = true;
        }
Ejemplo n.º 37
0
        private void EnsureServices(HttpContext context)
        {
            if (_actionContextAccessor == null)
            {
                _actionContextAccessor = context.RequestServices.GetRequiredService<IActionContextAccessor>();
            }

            if (_actionInvokerFactory == null)
            {
                _actionInvokerFactory = context.RequestServices.GetRequiredService<IActionInvokerFactory>();
            }

            if (_actionSelector == null)
            {
                _actionSelector = context.RequestServices.GetRequiredService<IActionSelector>();
            }

            if (_logger == null)
            {
                var factory = context.RequestServices.GetRequiredService<ILoggerFactory>();
                _logger = factory.CreateLogger<MvcRouteHandler>();
            }
            
            if (_diagnosticSource == null)
            {
                _diagnosticSource = context.RequestServices.GetRequiredService<DiagnosticSource>();
            }
        }
Ejemplo n.º 38
0
        private RouteContext CreateRouteContext(
            ActionDescriptor actionDescriptor = null,
            IActionSelector actionSelector = null,
            IActionInvokerFactory invokerFactory = null,
            ILoggerFactory loggerFactory = null,
            IOptions<MvcOptions> optionsAccessor = null,
            object diagnosticListener = null)
        {
            if (actionDescriptor == null)
            {
                var mockAction = new Mock<ActionDescriptor>();
                actionDescriptor = mockAction.Object;
            }

            if (actionSelector == null)
            {
                var mockActionSelector = new Mock<IActionSelector>();
                mockActionSelector.Setup(a => a.Select(It.IsAny<RouteContext>()))
                    .Returns(actionDescriptor);

                actionSelector = mockActionSelector.Object;
            }

            if (invokerFactory == null)
            {
                var mockInvoker = new Mock<IActionInvoker>();
                mockInvoker.Setup(i => i.InvokeAsync())
                    .Returns(Task.FromResult(true));

                var mockInvokerFactory = new Mock<IActionInvokerFactory>();
                mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>()))
                    .Returns(mockInvoker.Object);

                invokerFactory = mockInvokerFactory.Object;
            }

            if (loggerFactory == null)
            {
                loggerFactory = NullLoggerFactory.Instance;
            }

            if (optionsAccessor == null)
            {
                optionsAccessor = new TestOptionsManager<MvcOptions>();
            }

            var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore");
            if (diagnosticListener != null)
            {
                diagnosticSource.SubscribeWithAdapter(diagnosticListener);
            }

            var routingFeature = new RoutingFeature();

            var httpContext = new Mock<HttpContext>();
            httpContext
                .Setup(h => h.RequestServices.GetService(typeof(IActionContextAccessor)))
                .Returns(new ActionContextAccessor());
            httpContext
                .Setup(h => h.RequestServices.GetService(typeof(IActionSelector)))
                .Returns(actionSelector);
            httpContext
                .Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory)))
                .Returns(invokerFactory);
            httpContext
                .Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory)))
                .Returns(loggerFactory);
            httpContext
                .Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService)))
                .Returns(new MvcMarkerService());
            httpContext
                .Setup(h => h.RequestServices.GetService(typeof(IOptions<MvcOptions>)))
                .Returns(optionsAccessor);
            httpContext
                .Setup(h => h.RequestServices.GetService(typeof(DiagnosticSource)))
                .Returns(diagnosticSource);
            httpContext
                .Setup(h => h.Features[typeof(IRoutingFeature)])
                .Returns(routingFeature);

            var routeContext = new RouteContext(httpContext.Object);
            routingFeature.RouteData = routeContext.RouteData;
            return routeContext;
        }
Ejemplo n.º 39
0
        private RouteContext CreateRouteContext(
            IActionSelector actionSelector = null,
            IActionInvokerFactory invokerFactory = null,
            ILoggerFactory loggerFactory = null)
        {
            var mockContextAccessor = new Mock<IContextAccessor<ActionContext>>();
            mockContextAccessor.Setup(c => c.SetContextSource(
                It.IsAny<Func<ActionContext>>(),
                It.IsAny<Func<ActionContext, ActionContext>>()))
                .Returns(NullDisposable.Instance);


            if (actionSelector == null)
            {
                var mockAction = new Mock<ActionDescriptor>();

                var mockActionSelector = new Mock<IActionSelector>();
                mockActionSelector.Setup(a => a.SelectAsync(It.IsAny<RouteContext>()))
                    .Returns(Task.FromResult(mockAction.Object));

                actionSelector = mockActionSelector.Object;
            }

            if (invokerFactory == null)
            {
                var mockInvoker = new Mock<IActionInvoker>();
                mockInvoker.Setup(i => i.InvokeActionAsync())
                    .Returns(Task.FromResult<object>(null));

                var mockInvokerFactory = new Mock<IActionInvokerFactory>();
                mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>()))
                    .Returns(mockInvoker.Object);

                invokerFactory = mockInvokerFactory.Object;
            }

            if (loggerFactory == null)
            {
                loggerFactory = NullLoggerFactory.Instance;
            }

            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IContextAccessor<ActionContext>)))
                .Returns(mockContextAccessor.Object);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector)))
                .Returns(actionSelector);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory)))
                .Returns(invokerFactory);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory)))
                .Returns(loggerFactory);

            return new RouteContext(httpContext.Object);
        }
Ejemplo n.º 40
0
 public Deserializer(INavigationService navigationService, IActionInvokerFactory invokerFactory)
 {
     _navigationService = navigationService;
     _invokerFactory = invokerFactory;
 }
Ejemplo n.º 41
0
        private RouteContext CreateRouteContext(
            ActionDescriptor actionDescriptor = null,
            IActionSelector actionSelector = null,
            IActionInvokerFactory invokerFactory = null,
            ILoggerFactory loggerFactory = null,
            IOptions<MvcOptions> optionsAccessor = null,
            object notificationListener = null)
        {
            var mockContextAccessor = new Mock<IScopedInstance<ActionContext>>();

            if (actionDescriptor == null)
            {
                var mockAction = new Mock<ActionDescriptor>();
                actionDescriptor = mockAction.Object;
            }

            if (actionSelector == null)
            {
                var mockActionSelector = new Mock<IActionSelector>();
                mockActionSelector.Setup(a => a.SelectAsync(It.IsAny<RouteContext>()))
                    .Returns(Task.FromResult(actionDescriptor));

                actionSelector = mockActionSelector.Object;
            }

            if (invokerFactory == null)
            {
                var mockInvoker = new Mock<IActionInvoker>();
                mockInvoker.Setup(i => i.InvokeAsync())
                    .Returns(Task.FromResult(true));

                var mockInvokerFactory = new Mock<IActionInvokerFactory>();
                mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>()))
                    .Returns(mockInvoker.Object);

                invokerFactory = mockInvokerFactory.Object;
            }

            if (loggerFactory == null)
            {
                loggerFactory = NullLoggerFactory.Instance;
            }

            if (optionsAccessor == null)
            {
                optionsAccessor = new MockMvcOptionsAccessor();
            }

            var notifier = new Notifier(new NotifierMethodAdapter());
            if (notificationListener != null)
            {
                notifier.EnlistTarget(notificationListener);
            }

            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IScopedInstance<ActionContext>)))
                .Returns(mockContextAccessor.Object);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector)))
                .Returns(actionSelector);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory)))
                .Returns(invokerFactory);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory)))
                .Returns(loggerFactory);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService)))
                 .Returns(new MvcMarkerService());
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions<MvcOptions>)))
                 .Returns(optionsAccessor);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(INotifier)))
                .Returns(notifier);

            return new RouteContext(httpContext.Object);
        }
Ejemplo n.º 42
0
        private RouteContext CreateRouteContext(
            IActionSelector actionSelector = null,
            IActionInvokerFactory invokerFactory = null,
            ILoggerFactory loggerFactory = null,
            IOptions<MvcOptions> optionsAccessor = null)
        {
            var mockContextAccessor = new Mock<IScopedInstance<ActionContext>>();

            if (actionSelector == null)
            {
                var mockAction = new Mock<ActionDescriptor>();

                var mockActionSelector = new Mock<IActionSelector>();
                mockActionSelector.Setup(a => a.SelectAsync(It.IsAny<RouteContext>()))
                    .Returns(Task.FromResult(mockAction.Object));

                actionSelector = mockActionSelector.Object;
            }

            if (invokerFactory == null)
            {
                var mockInvoker = new Mock<IActionInvoker>();
                mockInvoker.Setup(i => i.InvokeAsync())
                    .Returns(Task.FromResult(true));

                var mockInvokerFactory = new Mock<IActionInvokerFactory>();
                mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>()))
                    .Returns(mockInvoker.Object);

                invokerFactory = mockInvokerFactory.Object;
            }

            if (loggerFactory == null)
            {
                loggerFactory = NullLoggerFactory.Instance;
            }

            if (optionsAccessor == null)
            {
                var options = new Mock<IOptions<MvcOptions>>();
                options.SetupGet(o => o.Options)
                                   .Returns(new MvcOptions());

                optionsAccessor = options.Object;
            }

            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IScopedInstance<ActionContext>)))
                .Returns(mockContextAccessor.Object);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector)))
                .Returns(actionSelector);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory)))
                .Returns(invokerFactory);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory)))
                .Returns(loggerFactory);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService)))
                 .Returns(new MvcMarkerService());
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions<MvcOptions>)))
                 .Returns(optionsAccessor);

            return new RouteContext(httpContext.Object);
        }
Ejemplo n.º 43
0
        private RouteContext CreateRouteContext(
            ActionDescriptor actionDescriptor = null,
            IActionSelector actionSelector = null,
            IActionInvokerFactory invokerFactory = null,
            ILoggerFactory loggerFactory = null,
            IOptions<MvcOptions> optionsAccessor = null,
            object telemetryListener = null)
        {
            if (actionDescriptor == null)
            {
                var mockAction = new Mock<ActionDescriptor>();
                actionDescriptor = mockAction.Object;
            }

            if (actionSelector == null)
            {
                var mockActionSelector = new Mock<IActionSelector>();
                mockActionSelector.Setup(a => a.SelectAsync(It.IsAny<RouteContext>()))
                    .Returns(Task.FromResult(actionDescriptor));

                actionSelector = mockActionSelector.Object;
            }

            if (invokerFactory == null)
            {
                var mockInvoker = new Mock<IActionInvoker>();
                mockInvoker.Setup(i => i.InvokeAsync())
                    .Returns(Task.FromResult(true));

                var mockInvokerFactory = new Mock<IActionInvokerFactory>();
                mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>()))
                    .Returns(mockInvoker.Object);

                invokerFactory = mockInvokerFactory.Object;
            }

            if (loggerFactory == null)
            {
                loggerFactory = NullLoggerFactory.Instance;
            }

            if (optionsAccessor == null)
            {
                optionsAccessor = new TestOptionsManager<MvcOptions>();
            }

            var telemetry = new TelemetryListener("Microsoft.AspNet");
            if (telemetryListener != null)
            {
                telemetry.SubscribeWithAdapter(telemetryListener);
            }

            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionContextAccessor)))
                .Returns(new ActionContextAccessor());
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector)))
                .Returns(actionSelector);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory)))
                .Returns(invokerFactory);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory)))
                .Returns(loggerFactory);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService)))
                 .Returns(new MvcMarkerService());
            httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions<MvcOptions>)))
                 .Returns(optionsAccessor);
            httpContext.Setup(h => h.RequestServices.GetService(typeof(TelemetrySource)))
                .Returns(telemetry);

            return new RouteContext(httpContext.Object);
        }
Ejemplo n.º 44
-1
 private ServiceConfiguration(INavigationService navigationService, IActionInvokerFactory invokerFactory, bool editMode) : base(editMode)
 {
     _navigationService = navigationService;
     _invokerFactory = invokerFactory;
     ActionGroups = new ObservableCollectionWithAddRange<ActionGroup>();
     AddActionGroupCommand = new RelayCommand(() =>
     {
         ActionGroups.Add(ActionGroup.CreateSilently("", this, _navigationService, EditMode));
         NotifyThatSomethingIsChanged();
     });
     InvokeUriCommand = new RelayCommand<ServiceAction>(async action =>
     {
         if (EditMode)
         {
             _navigationService.NavigateTo(ActionPage.Key, action);
         }
         else
         {
             action.Processing = true;
             Messenger.Default.Send(new ActionProcessingMessage());
             ((RelayCommand<ServiceAction>) InvokeUriCommand).RaiseCanExecuteChanged();
             await InvokeRestActionAsync(action);
             action.Processing = false;
             ((RelayCommand<ServiceAction>) InvokeUriCommand).RaiseCanExecuteChanged();
             await Task.Delay(1000); //The spinner animation should run at least 1 second
             Messenger.Default.Send(new ActionCompletedMessage());
         }
     }, action => action != null && !action.Processing);
     DeleteActionGroupCommand = new RelayCommand<ActionGroup>(group =>
     {
         ActionGroups.Remove(group);
         NotifyThatSomethingIsChanged();
     });
 }