Пример #1
0
        private static IApiDocumentation GetApiDocumentation(HttpUrl url)
        {
            string contentType;
            var    responseStream = new UnclosableStream(GetResponse(Method, url, out contentType));
            var    container      = UrsaConfigurationSection.InitializeComponentProvider();

            container.Register <IHttpServerConfiguration>(new StaticHttpServerConfiguration((Uri)url));
            var headers = new HeaderCollection();

            if (!String.IsNullOrEmpty(contentType))
            {
                ((IDictionary <string, string>)headers)[Header.Accept]      = contentType;
                ((IDictionary <string, string>)headers)[Header.ContentType] = contentType;
            }

            var apiDocumentationId = url.WithFragment(String.Empty);
            var httpRequest        = new RequestInfo(Verb.Parse(Method), apiDocumentationId, responseStream, new BasicClaimBasedIdentity(), headers);
            var converterProvider  = container.Resolve <IConverterProvider>();
            var converter          = converterProvider.FindBestInputConverter <IApiDocumentation>(httpRequest);

            if (converter == null)
            {
                throw new NotSupportedException(String.Format("Content type of '{0}' is not supported.", contentType));
            }

            converter.ConvertTo <IApiDocumentation>(httpRequest);
            return(_container.Resolve <IEntityContext>().Load <IApiDocumentation>((Uri)apiDocumentationId));
        }
Пример #2
0
        public void Build(IComponentProvider builder)
        {
            builder.RegisterSingleton <IEventAggregatorWrapper, EventAggregatorWrapper>();


            var controller = builder.Resolve <IAppController>();
            var aggregator = builder.Resolve <IEventAggregatorWrapper>();

            controller.GetType()
            .GetProperty(nameof(controller.Aggregator))
            .SetValue(controller, aggregator);
        }
Пример #3
0
        public static (IAppController, IEventAggregatorWrapper) BindMocksForMvp(this IComponentProvider builder)
        {
            if (!builder.IsRegistered <IEventAggregatorWrapper>())
            {
                builder.RegisterSingleton <IEventAggregatorWrapper, EventAggregatorWrapper>();
            }

            var controller = builder.Resolve <IAppController>();
            var aggregator = builder.Resolve <IEventAggregatorWrapper>();

            controller.GetType().GetProperty(nameof(controller.Aggregator))
            .SetValue(controller, aggregator);

            return(controller, aggregator);
        }
Пример #4
0
        private static IDictionary <string, Route> RegisterApi <T>(IComponentProvider container, ControllerInfo <T> description) where T : IController
        {
            var    handler                     = new UrsaHandler <T>(container.Resolve <IRequestHandler <RequestInfo, ResponseInfo> >());
            string globalRoutePrefix           = (description.EntryPoint != null ? description.EntryPoint.Url.ToString().Substring(1) + "/" : String.Empty);
            IDictionary <string, Route> routes = new Dictionary <string, Route>();

            routes[typeof(T).FullName + "DocumentationStylesheet"] = new Route(globalRoutePrefix + EntityConverter.DocumentationStylesheet, handler);
            routes[typeof(T).FullName + "PropertyIcon"]            = new Route(globalRoutePrefix + EntityConverter.PropertyIcon, handler);
            routes[typeof(T).FullName + "MethodIcon"] = new Route(globalRoutePrefix + EntityConverter.MethodIcon, handler);
            routes[typeof(T).FullName] = new Route(description.Url.ToString().Substring(1), handler);
            if (!String.IsNullOrEmpty(globalRoutePrefix))
            {
                routes[globalRoutePrefix] = new Route(globalRoutePrefix, handler);
            }

            foreach (var operation in description.Operations)
            {
                string routeTemplate = (operation.UrlTemplate ?? operation.Url.ToString()).Substring(1).Replace("{?", "{");
                int    indexOf       = routeTemplate.IndexOf('?');
                if (indexOf != -1)
                {
                    routeTemplate = routeTemplate.Substring(0, indexOf);
                }

                if (routes.All(route => String.Compare(route.Value.Url, routeTemplate, true) != 0))
                {
                    routes[typeof(T).FullName + "." + operation.UnderlyingMethod.Name] = new Route(routeTemplate, handler);
                }
            }

            return(routes);
        }
Пример #5
0
 private static void RegisterEntryPointControllerDescriptionBuilder(this IComponentProvider container, Url entryPoint)
 {
     container.Register <IHttpControllerDescriptionBuilder, EntryPointControllerDescriptionBuilder>(
         entryPoint.ToString().Substring(1),
         () => new EntryPointControllerDescriptionBuilder(entryPoint, container.Resolve <IDefaultValueRelationSelector>()),
         Lifestyles.Singleton);
 }
Пример #6
0
        /// <summary>Registers automatically discovered <see cref="IController" /> implementations.</summary>
        /// <param name="container">The container.</param>
        /// <param name="controllerDetailsAction">The controller details action.</param>
        /// <returns>The <paramref name="container" /> itself.</returns>
        public static IComponentProvider WithAutodiscoveredControllers(this IComponentProvider container, Action <Type, ControllerInfo> controllerDetailsAction = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            var assemblies = UrsaConfigurationSection.GetInstallerAssemblies();

            container.RegisterAll <IController>(assemblies);
            var controllers = container.ResolveAllTypes <IController>();

            container.RegisterControllerRelatedTypes(controllers);
            var registeredEntryPoints = new List <string>();

            foreach (var controller in controllers.Where(controller => !controller.IsDescriptionController()))
            {
                var descriptionBuilder = (IHttpControllerDescriptionBuilder)container.Resolve(typeof(IHttpControllerDescriptionBuilder <>).MakeGenericType(controller));
                var description        = descriptionBuilder.BuildDescriptor();
                if ((description.EntryPoint != null) && (!registeredEntryPoints.Contains(description.EntryPoint.ToString())))
                {
                    container.RegisterEntryPointControllerDescriptionBuilder(description.EntryPoint.Url);
                    registeredEntryPoints.Add(description.EntryPoint.ToString());
                }

                if (controllerDetailsAction != null)
                {
                    controllerDetailsAction(controller, description);
                }
            }

            return(container);
        }
Пример #7
0
        private Client()
        {
            IComponentProvider container = UrsaConfigurationSection.InitializeComponentProvider();

            _webRequestProvider = (from webRequestProvider in container.ResolveAll <IWebRequestProvider>()
                                   from supportedProtocol in webRequestProvider.SupportedProtocols
                                   join allowedProtocol in AllowedProtocols on supportedProtocol equals allowedProtocol
                                   select webRequestProvider).FirstOrDefault();
            if (_webRequestProvider == null)
            {
                throw new InvalidOperationException("Cannot create an HTTP client without proper web request provider.");
            }

            _converterProvider = container.Resolve <IConverterProvider>();
            _resultBinder      = container.Resolve <IResultBinder <RequestInfo> >();
        }
Пример #8
0
        /// <inheritdoc />
        public IController CreateInstance(Type type, IDictionary <string, object> arguments = null)
        {
            Type candidate = type;

            if (_container.CanResolve(candidate, arguments))
            {
                return((IController)_container.Resolve(candidate, arguments));
            }

            if ((type.IsGenericType) && (_container.CanResolve(candidate = type.GetGenericTypeDefinition(), arguments)))
            {
                return((IController)_container.Resolve(candidate, arguments));
            }

            candidate = type.GetInterfaces()
                        .Where(@interface => typeof(IController).IsAssignableFrom(@interface))
                        .OrderByDescending(@interface => @interface.GetGenericArguments().Length)
                        .First();
            return((IController)_container.Resolve(candidate, arguments));
        }
Пример #9
0
        public static void BindMocksForRgbPresenter(this IComponentProvider builder)
        {
            var(controller, aggregator) = builder.BindMocksForMvp();

            builder.RegisterTransientInstance <IRgbFormEventBinder>(Substitute.ForPartsOf <RgbFormEventBinder>(aggregator));

            var form = Substitute.ForPartsOf <RgbFormWrapper>(controller,
                                                              builder.Resolve <IRgbFormEventBinder>());

            builder.RegisterTransientInstance <IRgbView>(form)
            .RegisterTransientInstance <IRgbFormExposer>(form);

            builder.RegisterTransientInstance(
                Substitute.For <IRgbProvider>());

            builder.RegisterTransientInstance(
                Substitute.For <RgbPresenterWrapper>(controller,
                                                     builder.Resolve <IRgbProvider>(),
                                                     builder.Resolve <IAsyncOperationLocker>()
                                                     ));
        }
Пример #10
0
        public static void BindMocksForMainPresenter(this IComponentProvider builder)
        {
            var(controller, aggregator) = builder.BindMocksForMvp();

            var dialog = Substitute.ForPartsOf <NonBlockDialogServiceWrapper>(
                Substitute.For <IFileDialogService>(), Substitute.For <IStaTaskService>());

            builder
            .RegisterSingletonInstance <INonBlockDialogService>(dialog)
            .RegisterTransientInstance <ICacheService <Bitmap> >(Substitute.ForPartsOf <CacheService <Bitmap> >())
            .RegisterTransientInstance <IAsyncOperationLocker>(Substitute.ForPartsOf <AsyncOperationLocker>())
            .RegisterTransientInstance <IAwaitablePipeline>(Substitute.ForPartsOf <AwaitablePipeline>())
            .RegisterTransientInstance <IMainFormEventBinder>(Substitute.ForPartsOf <MainFormEventBinder>(aggregator))
            .RegisterTransientInstance <IMainFormContainerFactory>(Substitute.ForPartsOf <MainFormContainerFactory>())
            .RegisterTransientInstance <IMainFormUndoRedoFactory>(Substitute.ForPartsOf <MainFormUndoRedoFactory>())
            .RegisterTransientInstance <IMainFormZoomFactory>(Substitute.ForPartsOf <MainFormZoomFactory>())
            .RegisterTransientInstance <IMainFormRotationFactory>(Substitute.ForPartsOf <MainFormRotationFactory>())
            .RegisterTransientInstance <IScalingProvider>(Substitute.For <IScalingProvider>())
            .RegisterTransientInstance <IRotationProvider>(Substitute.For <IRotationProvider>());


            var form = Substitute.ForPartsOf <MainFormWrapper>(controller,
                                                               builder.Resolve <IMainFormEventBinder>(),
                                                               builder.Resolve <IMainFormContainerFactory>(),
                                                               builder.Resolve <IMainFormUndoRedoFactory>(),
                                                               builder.Resolve <IMainFormZoomFactory>(),
                                                               builder.Resolve <IMainFormRotationFactory>());

            builder.RegisterSingletonInstance(form)
            .RegisterSingletonInstance <IMainView>(form);

            builder.RegisterTransientInstance(Substitute.ForPartsOf <MainPresenterWrapper>(controller,
                                                                                           builder.Resolve <ICacheService <Bitmap> >(),
                                                                                           builder.Resolve <INonBlockDialogService>(),
                                                                                           builder.Resolve <IAwaitablePipeline>(),
                                                                                           builder.Resolve <IAsyncOperationLocker>(),
                                                                                           builder.Resolve <IScalingProvider>(),
                                                                                           builder.Resolve <IRotationProvider>()));
        }
Пример #11
0
        public void Build(IComponentProvider builder)
        {
            new MicrokernelStartup().Build(builder);

            builder
            .RegisterSingleton <IAppSettings, AppSettings>()
            .RegisterTransient <IConvolutionFactory, ConvolutionFactory>()
            .RegisterTransient <IMorphologyFactory, MorphologyFactory>()
            .RegisterTransient <IStructuringElementFactory, StructuringElementFactory>()
            .RegisterTransient <IDistributionFactory, DistributionFactory>()
            .RegisterTransient <IRgbFilterFactory, RgbFilterFactory>()
            .RegisterTransient <IScalingFactory, ScalingFactory>()
            .RegisterTransient <IColorMatrixFactory, ColorMatrixFactory>()
            .RegisterTransient <IRecommendationFactory, RecommendationFactory>()
            .RegisterTransient <IChannelFactory, ChannelFactory>()
            .RegisterTransient <IRotationFactory, RotationFactory>()
            .RegisterTransient <ITransformationFactory, TransformationFactory>();

            var colorMatrix    = Substitute.ForPartsOf <ColorMatrixFactoryWrapper>(builder.Resolve <IColorMatrixFactory>());
            var convolution    = Substitute.ForPartsOf <ConvoltuionFactoryWrapper>(builder.Resolve <IConvolutionFactory>());
            var distribution   = Substitute.ForPartsOf <DistributionFactoryWrapper>(builder.Resolve <IDistributionFactory>());
            var morphology     = Substitute.ForPartsOf <MorphologyFactoryWrapper>(builder.Resolve <IMorphologyFactory>());
            var rgb            = Substitute.ForPartsOf <RgbFactoryWrapper>(builder.Resolve <IRgbFilterFactory>());
            var rotation       = Substitute.ForPartsOf <RotationFactoryWrapper>(builder.Resolve <IRotationFactory>());
            var scaling        = Substitute.ForPartsOf <ScalingFactoryWrapper>(builder.Resolve <IScalingFactory>());
            var transformation = Substitute.ForPartsOf <TransformationFactoryWrapper>(builder.Resolve <ITransformationFactory>());

            builder
            .RegisterTransientInstance <IColorMatrixFactoryWrapper>(colorMatrix)
            .RegisterTransientInstance <IConvolutionFactoryWrapper>(convolution)
            .RegisterTransientInstance <IDistributionFactoryWrapper>(distribution)
            .RegisterTransientInstance <IMorphologyFactoryWrapper>(morphology)
            .RegisterTransientInstance <IRgbFactoryWrapper>(rgb)
            .RegisterTransientInstance <IRotationFactoryWrapper>(rotation)
            .RegisterTransientInstance <IScalingFactoryWrapper>(scaling)
            .RegisterTransientInstance <ITransformationFactoryWrapper>(transformation);
        }