private void RegisterReadModelIndexes()
        {
            /*var indexes = from @type in this.GetType().Assembly.GetTypes()
             *  where
             *      @type.Namespace != null && @type.Namespace.Contains("ReadModel") && [email protected] &&
             *      typeof(AbstractIndexCreationTask).IsAssignableFrom(@type)
             *  select @type;
             *
             * foreach (var task in indexes.Select(index => (AbstractIndexCreationTask)FastActivator.Create(index)))
             * {
             *  task.Execute(this.factory.ReadModel);
             * }*/

            var transformers = from @type in this.GetType().Assembly.GetTypes()
                               where
                               [email protected] &&
                               typeof(AbstractTransformerCreationTask).IsAssignableFrom(@type)
                               select @type;

            foreach (
                var task in
                transformers.Select(
                    transformer => (AbstractTransformerCreationTask)FastActivator.Create(transformer)))
            {
                task.Execute(this.factory.ReadModel);
            }
        }
Exemplo n.º 2
0
 public void DefaultConstructor(int iterations)
 {
     for (int i = 0; i < iterations; i++)
     {
         ClassWithDefaultConstructor item = FastActivator <ClassWithDefaultConstructor> .Create();
     }
 }
Exemplo n.º 3
0
 public void SingleArgumentConstructor(int iterations)
 {
     for (int i = 0; i < iterations; i++)
     {
         ClassWithOneConstructorArg item = FastActivator <ClassWithOneConstructorArg> .Create(47);
     }
 }
Exemplo n.º 4
0
        public void The_generic_arguments_should_be_used_to_build_the_type()
        {
            var obj = FastActivator.Create(typeof(ClassWithOneGenericArgument <>), new[] { typeof(int) });

            obj.ShouldNotBeNull();
            obj.ShouldBeAnInstanceOf <ClassWithOneGenericArgument <int> >();
        }
Exemplo n.º 5
0
        protected virtual UnsubscribeAction Connect <TComponent, TMessage>(ISubscriberContext context)
            where TMessage : class
            where TComponent : class, Observes <TMessage, TComponent>, ISaga
        {
            MessageRouterConfigurator routerConfigurator = MessageRouterConfigurator.For(context.Pipeline);

            var router = routerConfigurator.FindOrCreate <TMessage>();

            var instance = (Observes <TMessage, TComponent>) FastActivator <TComponent> .Create(Guid.Empty);

            Expression <Func <TComponent, TMessage, bool> > selector = instance.GetBindExpression();

            var repository = context.Builder.GetInstance <ISagaRepository <TComponent> >();
            var policy     = new ExistingSagaPolicy <TComponent, TMessage>(x => false);
            var sink       = new PropertySagaMessageSink <TComponent, TMessage>(context, context.Data as IServiceBus, repository, policy, selector);

            if (sink == null)
            {
                throw new ConfigurationException("Could not build the message sink for " + typeof(TComponent).FullName);
            }

            var result = router.Connect(sink);

            UnsubscribeAction remove = context.SubscribedTo <TMessage>();

            return(() => result() && (router.SinkCount == 0) && remove());
        }
Exemplo n.º 6
0
        private static IObjectSerializer CreateEnumerableSerializerFor(Type type)
        {
            if (type.IsArray)
            {
                return((IObjectSerializer)FastActivator.Create(typeof(ArraySerializer <>).MakeGenericType(type.GetElementType())));
            }

            Type[] genericArguments = type.GetDeclaredGenericArguments().ToArray();
            if (genericArguments == null || genericArguments.Length == 0)
            {
                Type elementType = type.IsArray ? type.GetElementType() : typeof(object);

                Type serializerType = typeof(ArraySerializer <>).MakeGenericType(elementType);

                return((IObjectSerializer)FastActivator.Create(serializerType));
            }

            if (type.ImplementsGeneric(typeof(IDictionary <,>)))
            {
                Type serializerType = typeof(DictionarySerializer <,>).MakeGenericType(genericArguments);

                return((IObjectSerializer)FastActivator.Create(serializerType));
            }

            if (type.ImplementsGeneric(typeof(IList <>)) || type.ImplementsGeneric(typeof(IEnumerable <>)))
            {
                Type serializerType = typeof(ListSerializer <>).MakeGenericType(genericArguments[0]);

                return((IObjectSerializer)FastActivator.Create(serializerType));
            }

            throw new InvalidOperationException("enumerations not yet supported");
        }
Exemplo n.º 7
0
 public MakeMCEuropeanHestonEngine <RNG, S> withAbsoluteTolerance(double tolerance)
 {
     Utils.QL_REQUIRE(samples_ == null, () => "number of samples already set");
     Utils.QL_REQUIRE(FastActivator <RNG> .Create().allowsErrorEstimate != 0, () => "chosen random generator policy does not allow an error estimate");
     tolerance_ = tolerance;
     return(this);
 }
Exemplo n.º 8
0
 /// <summary>
 ///		Returns a collection of instances
 ///		of a certain type
 /// </summary>
 public static IEnumerable <T> Populate <T>(int count)
 {
     for (var i = 0; i < count; i++)
     {
         yield return(FastActivator.Create <T>());
     }
 }
Exemplo n.º 9
0
 public void DynamicGenerateCodeConstructor()
 {
     for (int i = 0; i < IterationCount; i++)
     {
         FastActivator <Node> .Create();
     }
 }
        public static UnsubscribeAction ConnectEndpoint(this IMessagePipeline pipeline, Type messageType, IEndpoint endpoint)
        {
            object sink = FastActivator.Create(typeof(EndpointMessageSink <>).MakeGenericType(messageType),
                                               new object[] { endpoint });

            return(pipeline.FastInvoke <IMessagePipeline, UnsubscribeAction>("ConnectToRouter", sink));
        }
Exemplo n.º 11
0
    public static GameAction Create(int actionId)
    {
        GameAction gameAction = null;
        string     name       = string.Format(ActionFormat, actionId);

        try
        {
            var type = (Type)lookupType[name];
            lock (lookupType)
            {
                if (type == null)
                {
                    type             = Type.GetType(name);
                    lookupType[name] = type;
                }
            }
            if (type != null)
            {
                gameAction = FastActivator.Create(type) as GameAction;
            }
        }
        catch (Exception ex)
        {
            UnityEngine.Debug.LogError("GameAction create error:" + ex);
        }
        return(gameAction);
    }
Exemplo n.º 12
0
        // factory
        public IRNG make_sequence_generator(int dimension, ulong seed)
        {
            URSG g = (URSG)FastActivator <URSG> .Create().factory(dimension, seed);

            return(icInstance != null ? new InverseCumulativeRsg <URSG, IC>(g, icInstance)
                 : new InverseCumulativeRsg <URSG, IC>(g));
        }
Exemplo n.º 13
0
        public void Load()
        {
            var interceptorNodes = section.TryGetNodes("interceptors/interceptor");

            foreach (var node in interceptorNodes)
            {
                var entityAttr = node.Attributes.TryGetValue("entity");
                var typeAttr   = node.Attributes.TryGetValue("type");
                try
                {
                    if (String.IsNullOrEmpty(entityAttr))
                    {
                        RegisterInterceptor((IRepositoryFrameworkInterceptor)FastActivator.Create(typeAttr));
                    }
                    else
                    {
                        RegisterInterceptor(Type.GetType(entityAttr), (IRepositoryFrameworkInterceptor)FastActivator.Create(typeAttr));
                    }
                }
                catch (Exception ex)
                {
                    throw new PlatformException("加载拦截器错误。entity:{0}, type:{1}。\r\n详细错误:\r\n{2} ", entityAttr, typeAttr, ex);
                }
            }
        }
Exemplo n.º 14
0
        void Create()
        {
            try
            {
                _controllerChannel = new OutboundChannel(_controllerAddress, _controllerPipeName);

                Type type = FindBootstrapperImplementationType(_bootstrapperType);

                _log.DebugFormat("[{0}] Creating bootstrapper: {1}", _serviceName, type.ToShortTypeName());

                object bootstrapper = FastActivator.Create(type);

                Type serviceType = bootstrapper.GetType()
                                   .GetInterfaces()
                                   .First()
                                   .GetGenericArguments()
                                   .First();

                _log.DebugFormat("[{0}] Creating configurator for service type: {1}", _serviceName, serviceType.ToShortTypeName());

                InitializeAndCreateService(serviceType, bootstrapper);
            }
            catch (Exception ex)
            {
                SendFault(ex);
            }
        }
Exemplo n.º 15
0
        static IConsumerConnector ConsumerConnectorFactory(Type type)
        {
            var args      = new object[] {};
            var connector = (IConsumerConnector)FastActivator.Create(typeof(ConsumerConnector <>), new[] { type }, args);

            return(connector);
        }
Exemplo n.º 16
0
        public ObservesSagaSubscriptionConnector(ISagaRepository <TSaga> sagaRepository)
            : base(sagaRepository, new ExistingOrIgnoreSagaPolicy <TSaga, TMessage>(x => false))
        {
            var instance = (Observes <TMessage, TSaga>) FastActivator <TSaga> .Create(Guid.Empty);

            _selector = instance.GetBindExpression();
        }
Exemplo n.º 17
0
        private static IObjectSerializer CreateSerializerFor(Type type)
        {
            if (type.IsEnum)
            {
                return((IObjectSerializer)FastActivator.Create(typeof(EnumSerializer <>).MakeGenericType(type)));
            }

            if (typeof(IEnumerable).IsAssignableFrom(type))
            {
                return(CreateEnumerableSerializerFor(type));
            }

            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                Type nullableType = type.GetGenericArguments().First();

                return(_serializers.Retrieve(nullableType, () => CreateSerializerFor(nullableType)));
            }

            Type serializerType = typeof(ObjectSerializer <>).MakeGenericType(type);

            var serializer = (IObjectSerializer)FastActivator.Create(serializerType);

            return(serializer);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 注册元数据定义
        /// </summary>
        /// <param name="assembly"></param>
        public void RegisterDefineMetadata(Assembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            Type[] types = assembly.GetExportedTypes();
            foreach (Type type in types)
            {
                var v = type.GetInterface(typeof(ICacheMetadataProvider).FullName);
                if (v != null)
                {
                    var active   = FastActivator.Create(type);
                    var metadata = ((ICacheMetadataProvider)active).GetCacheMetadata();

                    if (metadatas.ContainsKey(metadata.EntityType))
                    {
                        throw new PlatformException("重复的类型定义。\r\nEntityType:{0}, DefineType:{1}", metadata.EntityType.FullName, type.FullName);
                    }

                    //验证方法virtual
                    EntityUtil.CheckVirtualType(metadata.EntityType);

                    metadatas.Add(metadata.EntityType, metadata);
                }
            }
        }
Exemplo n.º 19
0
        public static void Init(IEnumerable <string> assemblyStrings)
        {
            var mappings = new List <Type>();
            var baseType = typeof(MongoMap);

            foreach (var assemblyString in assemblyStrings)
            {
                try
                {
                    var assembly = Assembly.Load(assemblyString);
                    if (!assembly.IsDynamic)
                    {
                        mappings.AddRange(
                            assembly.GetExportedTypes()
                            .Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(baseType))
                            .ToList()
                            );
                    }
                }
                catch (System.IO.FileNotFoundException ex)
                {
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            foreach (var type in mappings)
            {
                FastActivator.Create(type);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// 注册类型的分区策略
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="shardStragegyType"></param>
        /// <param name="attributes"></param>
        public IShardStrategy RegisterShardStragety(Type entityType, Type shardStragegyType, IDictionary <string, string> attributes = null)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }
            if (shardStragegyType == null)
            {
                throw new ArgumentNullException("shardStragegyType");
            }

            IShardStrategy strategy = (IShardStrategy)FastActivator.Create(shardStragegyType);

            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            if (strategy is AbstractShardStrategy && attributes != null)
            {
                ((AbstractShardStrategy)strategy).Init(attributes);
            }

            if (stategies.ContainsKey(entityType))
            {
                stategies[entityType] = strategy;
            }
            else
            {
                stategies.Add(entityType, strategy);
            }
            return(strategy);
        }
Exemplo n.º 21
0
        public object Deserialize(IDeserializerContext context)
        {
            T instance = FastActivator <T> .Create();

            if (context.IsEmptyElement)
            {
                context.Read();
                return(instance);
            }

            if (!context.Read())
            {
                return(instance);
            }

            while (context.NodeType != XmlNodeType.EndElement && context.NodeType != XmlNodeType.None)
            {
                if (context.NodeType == XmlNodeType.Element)
                {
                    ReadProperty(context, instance);
                    continue;
                }

                if (!context.Read())
                {
                    break;
                }
            }

            context.ExitElement();

            return(instance);
        }
Exemplo n.º 22
0
 public void TwoArgumentConstructor(int iterations)
 {
     for (int i = 0; i < iterations; i++)
     {
         ClassWithTwoConstructorArgs item = FastActivator <ClassWithTwoConstructorArgs> .Create(47, "The Name");
     }
 }
Exemplo n.º 23
0
 /// <summary>
 ///		Populates a new collection
 ///		of instances of a certain type
 /// </summary>
 public static IEnumerable <object> Populate(this Type type, int count)
 {
     for (var i = 0; i < count; i++)
     {
         yield return(FastActivator.Create(type));
     }
 }
Exemplo n.º 24
0
        public void Should_copy_the_arguments_into_the_class()
        {
            object arguments = FastActivator <MoveCommandArguments> .Create();

            var properties = arguments.GetType()
                             .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                             .Where(x => x.GetGetMethod(true) != null)
                             .Where(x => x.GetSetMethod(true) != null)
                             .Select(x => new FastProperty(x));

            properties
            .Each(property =>
            {
                object value = Elements.GetDefinitionElement(property.Property.PropertyType, property.Property.Name);
                if (value != null)
                {
                    property.Set(arguments, value);
                    return;
                }
            });


            var test = (MoveCommandArguments)arguments;

            Assert.AreEqual("source.txt", test.From);
            Assert.AreEqual("destination.txt", test.To);
            Assert.IsTrue(test.Overwrite);
        }
Exemplo n.º 25
0
 public PiecewiseDefaultCurve(Date referenceDate, List <CdsHelper> instruments,
                              DayCounter dayCounter, List <Handle <Quote> > jumps,
                              List <Date> jumpDates, double accuracy)
     : this(referenceDate, instruments, dayCounter, jumps, jumpDates, accuracy, FastActivator <Interpolator> .Create(),
            FastActivator <BootStrap> .Create())
 {
 }
Exemplo n.º 26
0
        /// <summary>
        /// Creates the provider by using the factory (if present) or directly instantiating by type name
        /// </summary>
        /// <returns></returns>
        public T CreateInstance()
        {
            //check if we have a factory
            if (this.factoryInstance == null)
            {
                var type = this.Factory;
                if (type != null)
                {
                    this.factoryInstance = (IProviderFactory <T>)FastActivator.Create(type);
                    this.factoryInstance.Initialize(this.parameters);
                }
            }

            // no factory, use the provider type
            if (this.factoryInstance == null)
            {
                var type = this.Type;

                if (type == null)
                {
                    return(null);
                }

                return((T)FastActivator.Create(type));
            }

            return(factoryInstance.Create());
        }
Exemplo n.º 27
0
 public void testBMACurveConsistency <T, I, B>(CommonVars vars)
     where T : ITraits <YieldTermStructure>, new ()
     where I : IInterpolationFactory, new ()
     where B : IBootStrap <PiecewiseYieldCurve>, new ()
 {
     testBMACurveConsistency <T, I, B>(vars, FastActivator <I> .Create(), 1.0e-7);
 }
Exemplo n.º 28
0
 public MakeMCDiscreteArithmeticASEngine <RNG, S> withTolerance(double tolerance)
 {
     Utils.QL_REQUIRE(samples_ == null, () => "number of samples already set");
     Utils.QL_REQUIRE(FastActivator <RNG> .Create().allowsErrorEstimate != 0, () =>
                      "chosen random generator policy " + "does not allow an error estimate");
     tolerance_ = tolerance;
     return(this);
 }
Exemplo n.º 29
0
        public override void Consume(TMessage message)
        {
            base.Consume(message);

            var reply = FastActivator <TReplyMessage> .Create(message.CorrelationId);

            Bus.Publish(reply);
        }
Exemplo n.º 30
0
        public override void Consume(TMessage message)
        {
            base.Consume(message);

            var reply = FastActivator <TReplyMessage> .Create(message.CorrelationId);

            ContextStorage.Context().Respond(reply);
        }