Exemplo n.º 1
0
 static CloudInfrastructureProviders CloudInfrastructureProviders(IComponentContext c)
 {
     return new CloudInfrastructureProviders(
         c.Resolve<CloudStorageProviders>(),
         c.ResolveOptional<IProvisioningProvider>(),
         c.ResolveOptional<ILog>());
 }
Exemplo n.º 2
0
 static RuntimeProviders RuntimeProviders(IComponentContext c)
 {
     return CloudStorage
         .ForAzureAccount(c.Resolve<CloudStorageAccount>())
         .WithObserver(c.Resolve<ICloudStorageObserver>())
         .WithRuntimeFinalizer(c.ResolveOptional<IRuntimeFinalizer>())
         .BuildRuntimeProviders(c.ResolveOptional<ILog>());
 }
Exemplo n.º 3
0
 static IQueueStorageProvider QueueStorageProvider(IComponentContext c)
 {
     return CloudStorage
         .ForAzureAccount(c.Resolve<CloudStorageAccount>())
         .WithDataSerializer(c.Resolve<IDataSerializer>())
         .WithObserver(c.Resolve<ICloudStorageObserver>())
         .WithRuntimeFinalizer(c.ResolveOptional<IRuntimeFinalizer>())
         .BuildQueueStorage();
 }
Exemplo n.º 4
0
        protected virtual TransactionalBus BuildMessageBus(IComponentContext c)
        {
            var bus = new MessageBus(
                c.Resolve <ITransportMessages>(),
                c.Resolve <IStoreSubscriptions>(),
                this.endpoints,
                c.ResolveOptional <IMessageContext>() ?? c.Resolve <NullMessageContext>(),
                c.Resolve <MessageBuilder>(),
                c.Resolve <IDiscoverMessageTypes>());

            return(new TransactionalBus(c.Resolve <IHandleUnitOfWork>(), bus));
        }
        protected virtual TransactionalBus BuildMessageBus(IComponentContext c)
        {
            var bus = new MessageBus(
                c.Resolve<ITransportMessages>(),
                c.Resolve<IStoreSubscriptions>(),
                this.endpoints,
                c.ResolveOptional<IMessageContext>() ?? c.Resolve<NullMessageContext>(),
                c.Resolve<MessageBuilder>(),
                c.Resolve<IDiscoverMessageTypes>());

            return new TransactionalBus(c.Resolve<IHandleUnitOfWork>(), bus);
        }
Exemplo n.º 6
0
        public IEnumerable <string> Resolve(string moduleName, string fromModule)
        {
            var configuration = _componentContext.ResolveOptional <IRequireConfiguration>();

            if (configuration == null)
            {
                return(Enumerable.Empty <string>());
            }

            var candidates = ResolveCandidates(configuration, moduleName);

            return(candidates.Select(c => ApplyMaps(configuration, fromModule, c)));
        }
Exemplo n.º 7
0
 public virtual object ResolveOptional(Type type, string name = null)
 {
     if (string.IsNullOrEmpty(name))
     {
         return(context.ResolveOptional(type));
     }
     else
     {
         object obj = null;
         context.TryResolveNamed(name, type, out obj);
         return(obj);
     }
 }
Exemplo n.º 8
0
        public static ConsumerConsumeContext <TConsumer, TMessage> GetConsumer <TConsumer, TMessage>(this IComponentContext componentContext, ConsumeContext <TMessage> consumeContext)
            where TConsumer : class
            where TMessage : class
        {
            var consumer = componentContext.ResolveOptional <TConsumer>();

            if (consumer == null)
            {
                throw new ConsumerException($"Unable to resolve consumer type '{TypeMetadataCache<TConsumer>.ShortName}'.");
            }

            return(consumeContext.PushConsumer(consumer));
        }
        private ContextConnection LookupContextConnection(IComponentContext componentContext, Type contextType)
        {
            var contextSettings = componentContext.ResolveOptional <ContextSettings>() ?? new ContextSettings();

            ContextConnection connection = contextSettings.Connections?
                                           .FirstOrDefault(c => c.ContextName == contextType.Name);

            if (connection == null)
            {
                throw new InvalidOperationException(
                          $"Context connection could not be found for the following entity context type: {contextType}.");
            }
            return(connection);
        }
Exemplo n.º 10
0
        public object Create(object request, ISpecimenContext context)
        {
            object result = new NoSpecimen();

            if (request is Type)
            {
                var type = request as Type;
                if (!type.IsAssignableTo <IEnumerable>() && _context.IsRegistered(type))
                {
                    result = _context.ResolveOptional(type) ?? result;
                }
            }
            return(result);
        }
Exemplo n.º 11
0
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, IComponentContext context, string name = "message",
                                    Action <ContainerBuilder, ConsumeContext> configureScope = null)
        {
            var registration = context.ResolveOptional <IRegistration>();

            if (registration != null)
            {
                registration.ConfigureConsumers(configurator);
                registration.ConfigureSagas(configurator);

                return;
            }

            LoadFrom(configurator, context.Resolve <ILifetimeScope>(), name, configureScope);
        }
Exemplo n.º 12
0
        private object GetHandler(IMessage message)
        {
            object handler     = null;
            var    messageType = message.GetType();

            if (message is IQueryBase)
            {
                var handlerType = typeof(IQueryHandler <,>).MakeGenericType(messageType, new QueryInfo(messageType).ResultType);
                handler = _serviceLocator.ResolveOptional(handlerType);
            }

            if (message is ICommand)
            {
                var handlerType = typeof(ICommandHandler <>).MakeGenericType(messageType);
                handler = _serviceLocator.ResolveOptional(handlerType);
            }

            if (handler == null)
            {
                throw new Exception($"Handler for message: {messageType.FullName} not found.");
            }

            return(handler);
        }
Exemplo n.º 13
0
        object[] GetParameters <T>(IComponentContext context)
            where T : class
        {
            ParameterInfo[] parameters = _cache.GetOrAdd(typeof(T), t => GetParameterInfos(t, context));
            var             result     = new object[parameters.Length];

            for (var i = 0; i < parameters.Length; i++)
            {
                var parameter = parameters[i];

                result[i] = parameter.IsOptional
                    ? context.ResolveOptional(parameter.ParameterType) ?? parameter.DefaultValue
                    : context.Resolve(parameter.ParameterType);
            }

            return(result);
        }
Exemplo n.º 14
0
            public RouteAction Handle(ICall call)
            {
                var property = call.GetMethodInfo().GetPropertyFromGetterCallOrNull();

                if (property is null)
                {
                    return(RouteAction.Continue());
                }

                var service = _context.ResolveOptional(call.GetReturnType());

                if (service is null)
                {
                    return(RouteAction.Continue());
                }

                return(RouteAction.Return(service));
            }
Exemplo n.º 15
0
        public async Task <TResult> DispatchInternal <TMessage, TResult>(TMessage command)
            where TMessage : IMessage <TResult>
        {
            var validator = _context.ResolveOptional <IValidator <TMessage, TResult> >();
            var handler   = _context.Resolve <IMessageHandler <TMessage, TResult> >();

            if (validator == null)
            {
                return(await handler.Handle(command));
            }

            var validationResult = await validator.Validate(command);

            if (validationResult != string.Empty)
            {
                Console.WriteLine(string.Format("Validation for message {0} did not pass. Message: {1}", typeof(TMessage), validationResult));
            }

            return(await handler.Handle(command));
        }
 public override IValidator CreateInstance(Type validatorType)
 {
     return((IValidator)_componentContext.ResolveOptional(validatorType));
 }
Exemplo n.º 17
0
 public override T ResolveOptional <T>()
 {
     return(componentContext.ResolveOptional <T>());
 }
Exemplo n.º 18
0
        protected SchedulerTaskScriptDependencies ResolveScriptDependency(ISchedulerTaskScript script, IComponentContext context)
        {
            if (script.DependencyClassType == null || script.DependencyClassType == typeof(void))
            {
                //TODO: return some default dependency
                return null;
            }

            var result = context.ResolveOptional(script.DependencyClassType) as SchedulerTaskScriptDependencies;

            //creating instance manually
            if (result == null)
            {
                result = Activator.CreateInstance(script.DependencyClassType)
                         as SchedulerTaskScriptDependencies;
                if (result == null) throw new Exception("Script Dependency can not be resolved. Check the dependency type");
                context.InjectProperties(result);
            }

            if(result==null) throw new Exception("Script Dependency can not be resolved");
            return result;
        }
 public T Resolve <T>() where T : class => _context.ResolveOptional <T>();
Exemplo n.º 20
0
 public static object ResolveOptional(this IComponentContext context, Type serviceType)
 {
     return(context.ResolveOptional(serviceType, NoParameters));
 }
Exemplo n.º 21
0
        public override void InitializePhysics(bool force, IComponentContext engineRegistrations)
        {
            if (force || !initialized)
            {
                var cache = engineRegistrations.Resolve<IResourceCache<Texture2D>>();
                var world = engineRegistrations.Resolve<PhysicsManager>().World;
                engine = engineRegistrations.ResolveOptional<EngineGame>();
                Physics = BodyFactory.CreateBody(world, Position, this);

                if (engine != null && engine.GamepadEnabled)
                {
                    ACTION_POPUP = InputManager.Instance.GamepadTextures[InputManager.ButtonActions.Interact];
                }

                float spriteWidthMeters = PhysicsConstants.PixelsToMeters(Width);
                float spriteHeightMeters = PhysicsConstants.PixelsToMeters(Height);

                var rect = FixtureFactory.AttachRectangle(
                    spriteWidthMeters,
                    PhysicsConstants.PixelsToMeters(10),
                    1.4f,
                    Vector2.Zero,
                    Physics);

                Physics.BodyType = BodyType.Static;
                Physics.IgnoreGravity = true;
                Physics.IsSensor = false;

                Physics.RegisterOnCollidedListener<UserControlledCharacter>(OnCollidedWith);
                Physics.RegisterOnSeparatedListener<UserControlledCharacter>(OnSeparation);

                popupTrigger = new ItemPopup(
                    ACTION_POPUP,
                    new Vector2(Physics.Position.X, Physics.Position.Y - PhysicsConstants.PixelsToMeters(100)),
                    cache);

                initialized = true;
            }

            base.InitializePhysics(false, engineRegistrations);
        }
Exemplo n.º 22
0
 public virtual void InitializePhysics(bool force, IComponentContext engineRegistrations)
 {
     TextureCache = engineRegistrations.Resolve<IResourceCache<Texture2D>>();
     Engine = engineRegistrations.ResolveOptional<EngineGame>();
 }
Exemplo n.º 23
0
 /// <summary>
 /// Retrieve a service from the context, or null if the service is not
 /// registered.
 /// </summary>
 /// <param name="context">The context from which to resolve the service.</param>
 /// <param name="parameters">Parameters for the service.</param>
 /// <typeparam name="TService">The service to resolve.</typeparam>
 /// <returns>
 /// The component instance that provides the service, or null.
 /// </returns>
 /// <exception cref="DependencyResolutionException"/>
 public static TService ResolveOptional <TService>(this IComponentContext context, params Parameter[] parameters)
     where TService : class
 {
     return(context.ResolveOptional <TService>((IEnumerable <Parameter>)parameters));
 }
Exemplo n.º 24
0
 public object CreateInstance(Type type)
 {
     return(_container.ResolveOptional(type) ?? Activator.CreateInstance(type));
 }
Exemplo n.º 25
0
 protected virtual NullMessageContext BuildNullMessageContext(IComponentContext c)
 {
     return new NullMessageContext(c.ResolveOptional<IReceiveFromEndpoints>().EndpointAddress);
 }
Exemplo n.º 26
0
 public override IValidator CreateInstance(Type validatorType)
 {
     // NOTE: componentContext.Resolve would error if the type wasn't registered (e.g. a dto)
     return(_componentContext.ResolveOptional(validatorType) as IValidator);
 }
Exemplo n.º 27
0
 /// <inheritdoc />
 public object Resolve(Type serviceType) => _container.ResolveOptional(serviceType);
Exemplo n.º 28
0
 public static TService ResolveOptional <TService>(this IComponentContext context) where TService : class
 {
     return(context.ResolveOptional <TService>(NoParameters));
 }
Exemplo n.º 29
0
        public override void InitializePhysics(bool force, IComponentContext engineRegistrations)
        {
            if (force || !initialized)
            {
                var world = engineRegistrations.Resolve<PhysicsManager>().World;
                levelManager = engineRegistrations.Resolve<LevelManager>();
                engineGame = engineRegistrations.ResolveOptional<EngineGame>();

                Physics = BodyFactory.CreateRectangle(
                    world,
                    PhysicsConstants.PixelsToMeters(Width),
                    PhysicsConstants.PixelsToMeters(Height),
                    1,
                    Position,
                    this);
                Physics.BodyType = BodyType.Static;
                Physics.IsSensor = true;
                _geom = Physics.FixtureList;

                RegisterCollisions();

                initialized = true;
            }

            base.InitializePhysics(false, engineRegistrations);
        }
Exemplo n.º 30
0
 protected virtual NullMessageContext BuildNullMessageContext(IComponentContext c)
 {
     return(new NullMessageContext(c.ResolveOptional <IReceiveFromEndpoints>().EndpointAddress));
 }
Exemplo n.º 31
0
 protected virtual IClock ResolveClock(IComponentContext context)
 {
     return(context.ResolveOptional <IClock>() ?? SystemClock.Instance);
 }
Exemplo n.º 32
0
 /// <summary>
 /// Retrieve a service from the context, or null if the service is not
 /// registered.
 /// </summary>
 /// <param name="context">The context from which to resolve the service.</param>
 /// <param name="parameters">Parameters for the service.</param>
 /// <param name="serviceType">The type of the service.</param>
 /// <returns>
 /// The component instance that provides the service, or null.
 /// </returns>
 /// <exception cref="DependencyResolutionException"/>
 public static object ResolveOptional(this IComponentContext context, Type serviceType, params Parameter[] parameters)
 {
     return(context.ResolveOptional(serviceType, (IEnumerable <Parameter>)parameters));
 }
Exemplo n.º 33
0
 public override IValidator CreateInstance(Type validatorType)
 {
     return(_context.ResolveOptional(validatorType) as IValidator);
 }
Exemplo n.º 34
0
        public override void InitializePhysics(bool force, IComponentContext engineRegistrations)
        {
            if (force || !initialized)
            {
                var cache = engineRegistrations.Resolve<IResourceCache<Texture2D>>();
                var texture = cache.GetResource(TextureName);
                var world = engineRegistrations.Resolve<PhysicsManager>().World;
                game = engineRegistrations.ResolveOptional<EngineGame>();

                if (game != null && game.GamepadEnabled)
                {
                    ACTION_POPUP = InputManager.Instance.GamepadTextures[InputManager.ButtonActions.Pickup];
                }

                //Width = texture.Width;
                //Height = texture.Height;
                Physics = BodyFactory.CreateRectangle(
                    world,
                    PhysicsConstants.PixelsToMeters(Width),
                    PhysicsConstants.PixelsToMeters(Height),
                    1,
                    Position);
                Physics.FixedRotation = true;
                Physics.BodyType = BodyType.Static;
                Physics.UserData = this;

                var fix = Physics.FixtureList[0];
                fix.CollisionCategories = Category.Cat3;
                fix.CollidesWith = Category.Cat1;

                HitSensor = BodyFactory.CreateRectangle(
                    world,
                    PhysicsConstants.PixelsToMeters(Width) * 2,
                    PhysicsConstants.PixelsToMeters(Height),
                    1,
                    Position);
                HitSensor.IsSensor = true;
                HitSensor.CollisionCategories = Category.Cat2;
                HitSensor.CollidesWith = Category.Cat2;

                HitSensor.RegisterOnCollidedListener<UserControlledCharacter>(OnCollidedWith);
                HitSensor.RegisterOnSeparatedListener<UserControlledCharacter>(OnSeparation);

                popup = new ItemPopup(ACTION_POPUP,
                    Physics.Position + new Vector2(0, -PhysicsConstants.PixelsToMeters(Height / 2 + POPUP_OFFSET)),
                    cache);

                initialized = true;
            }

            base.InitializePhysics(false, engineRegistrations);
        }
Exemplo n.º 35
0
 /// <summary>
 /// Resolve instance of type.
 /// </summary>
 /// <typeparam name="T">Instance of type we want to resolve.</typeparam>
 /// <param name="parameters">Parameters for resolving.</param>
 /// <returns></returns>
 public T Resolve <T>(params IResolverParameter[] parameters) where T : class
 => componentContext.ResolveOptional <T>(GetParams(parameters));
Exemplo n.º 36
0
 public object GetService(Type t, params Parameter[] parameters)
 {
     return(_componentContext.ResolveOptional(t, GetResolvedParameters(parameters)));
 }
Exemplo n.º 37
0
        public override void InitializePhysics(bool force, IComponentContext engineRegistrations)
        {
            if (force || !initialized)
            {
                var cache = engineRegistrations.Resolve<IResourceCache<Texture2D>>();
                var world = engineRegistrations.Resolve<PhysicsManager>().World;
                engine = engineRegistrations.ResolveOptional<EngineGame>();
                Physics = BodyFactory.CreateBody(world, Position, this);

                if (engine != null && engine.GamepadEnabled)
                {
                    UP_POPUP = InputManager.Instance.GamepadTextures[InputManager.ButtonActions.UpAction];
                    DOWN_POPUP = InputManager.Instance.GamepadTextures[InputManager.ButtonActions.DownAction];
                }

                float spriteWidthMeters = PhysicsConstants.PixelsToMeters(Width);
                float spriteHeightMeters = PhysicsConstants.PixelsToMeters(Height);

                var rect = FixtureFactory.AttachRectangle(
                    spriteWidthMeters,
                    spriteHeightMeters,
                    1.4f,
                    Vector2.Zero,
                    Physics);

                Physics.BodyType = BodyType.Static;
                Physics.IsSensor = true;

                Physics.RegisterOnCollidedListener<UserControlledCharacter>(OnCollidedWith);
                Physics.RegisterOnSeparatedListener<UserControlledCharacter>(OnSeparation);

                if (DoorType == DoorType.Up)
                {
                    popup = new ItemPopup(
                        UP_POPUP,
                        Physics.Position + new Vector2(0, -PhysicsConstants.PixelsToMeters(Height / 2)),
                        cache);
                }
                else if (DoorType == DoorType.Down)
                {
                    popup = new ItemPopup(
                        DOWN_POPUP,
                        Physics.Position + new Vector2(0, -PhysicsConstants.PixelsToMeters(Height / 2)),
                        cache);
                }
                else
                {
                    popup = null;
                }

                initialized = true;
            }

            base.InitializePhysics(false, engineRegistrations);
        }
Exemplo n.º 38
0
 public object GetService(Type serviceType)
 {
     return(_componentContext.ResolveOptional(serviceType));
 }
Exemplo n.º 39
0
        public override void InitializePhysics(bool force, IComponentContext engineRegistrations)
        {
            if (force || !initialized)
            {
                var cache = engineRegistrations.Resolve<IResourceCache<Texture2D>>();
                var world = engineRegistrations.Resolve<PhysicsManager>().World;
                engine = engineRegistrations.ResolveOptional<EngineGame>();
                var texture = cache.GetResource(EDITOR_PREVIEW);
                previewScale = new Vector2(Width / texture.Width, Height / texture.Height);

                Physics = BodyFactory.CreateBody(world, Position, this);

                float spriteWidthMeters = PhysicsConstants.PixelsToMeters(Width);
                float spriteHeightMeters = PhysicsConstants.PixelsToMeters(Height);

                string texture1 = InputTextureLookup(Key1, engine);

                if (Key2 != 999)
                {
                    string texture2 = InputTextureLookup(Key2, engine);
                    display2 = new ItemPopup(texture2, Vector2.Zero, cache, new Vector2(40, -90));

                    plusCombine = new ItemPopup("Textures/Keys/plusCombine", Vector2.Zero, cache, new Vector2(0, -90));

                    display1 = new ItemPopup(texture1, Vector2.Zero, cache, new Vector2(-40, -90));
                }
                else
                {
                    display2 = null;

                    display1 = new ItemPopup(texture1, Vector2.Zero, cache, new Vector2(0, -90));
                }

                var rect = FixtureFactory.AttachRectangle(
                    spriteWidthMeters,
                    spriteHeightMeters,
                    1.4f,
                    Vector2.Zero,
                    Physics);

                Physics.BodyType = BodyType.Static;
                Physics.IsSensor = true;

                Physics.RegisterOnCollidedListener<UserControlledCharacter>(OnCollidedWith);
                Physics.RegisterOnSeparatedListener<UserControlledCharacter>(OnSeparation);

                initialized = true;
            }

            base.InitializePhysics(false, engineRegistrations);
        }