Exemplo n.º 1
0
        private ParameterInfo[] GetConstructorParameters()
        {
            ConstructorInfo[] constructors = ImplementationType.GetConstructors();

            if (constructors.Length > 1)
            {
                ConstructorInfo injectionConstructor = null;

                foreach (ConstructorInfo constructor in constructors)
                {
                    if (!constructor.HasAttribute <InjectAttribute>())
                    {
                        continue;
                    }

                    if (injectionConstructor != null)
                    {
                        throw MultipleDependencyConstructorsException.MultipleInjectAttribute(ImplementationType);
                    }

                    injectionConstructor = constructor;
                }

                if (injectionConstructor == null)
                {
                    throw MultipleDependencyConstructorsException.MultipleConstructors(ImplementationType);
                }

                return(injectionConstructor.GetParameters());
            }

            return(constructors.First().GetParameters());
        }
Exemplo n.º 2
0
 private IProxyObject NhFindByExportGuid(ImplementationType implType, Guid exportGuid)
 {
     return((IProxyObject)_nhSession
            .CreateCriteria(ToProxyType(implType))
            .Add(global::NHibernate.Criterion.Restrictions.Eq("ExportGuid", exportGuid))
            .UniqueResult());
 }
Exemplo n.º 3
0
        public override void GenerateCode(GeneratedMethod method, ISourceWriter writer)
        {
            var arguments = _arguments.Select(x => x.Usage).Join(", ");
            var implementationTypeName = ImplementationType.FullNameInCode();

            var declaration = $"var {Variable.Usage} = new {implementationTypeName}({arguments})";

            if (IsDisposable)
            {
                if (Next is ConstructorFrame && Next.As <ConstructorFrame>().IsDisposable)
                {
                    writer.Write($"using ({declaration})");
                    Next?.GenerateCode(method, writer);
                }
                else
                {
                    writer.UsingBlock(declaration, w => Next?.GenerateCode(method, w));
                }
            }
            else
            {
                writer.Write(declaration + ";");
                Next?.GenerateCode(method, writer);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Serves as a hash function for a <see cref="T:CSF.FlexDi.Resolution.ServiceCacheKey"/> object.
        /// </summary>
        /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.</returns>
        public override int GetHashCode()
        {
            var typeHash = ImplementationType.GetHashCode();
            var nameHash = Name?.GetHashCode() ?? 0;

            return(typeHash ^ nameHash);
        }
Exemplo n.º 5
0
        public void LoadData(CLIFile pFile)
        {
            int token = 0;

            if (pFile.FileTable.Length > ImplementationTypeMax16BitRows ||
                pFile.AssemblyRefTable.Length > ImplementationTypeMax16BitRows ||
                pFile.ExportedTypeTable.Length > ImplementationTypeMax16BitRows)
            {
                token = pFile.ReadInt32();
            }
            else
            {
                token = pFile.ReadUInt16();
            }
            Type  = (ImplementationType)(token & ImplementationTypeMask);
            token = (token >> ImplementationTypeBits) - 1;
            if (token >= 0)
            {
                switch (Type)
                {
                case ImplementationType.File: File = pFile.FileTable[token]; break;

                case ImplementationType.AssemblyRef: AssemblyRef = pFile.AssemblyRefTable[token]; break;

                case ImplementationType.ExportedType: ExportedType = pFile.ExportedTypeTable[token]; break;

                default: throw new BadImageFormatException("Implementation Type");
                }
            }
        }
Exemplo n.º 6
0
        protected IServerCollectionHandler GetServerCollectionHandlerHelper(
            Type collectionHandlerType,
            ImplementationType aType,
            ImplementationType bType,
            RelationEndRole endRole)
        {
            if (Object.ReferenceEquals(aType, null)) { throw new ArgumentNullException("aType"); }
            if (Object.ReferenceEquals(bType, null)) { throw new ArgumentNullException("bType"); }
            try
            {
                // dynamically translate generic types into provider-known types
                Type[] genericArgs;
                if (endRole == RelationEndRole.A)
                {
                    genericArgs = new Type[] { aType.Type, bType.Type, aType.Type, bType.Type };
                }
                else
                {
                    genericArgs = new Type[] { aType.Type, bType.Type, bType.Type, aType.Type };
                }

                Type resultType = collectionHandlerType.MakeGenericType(genericArgs);
                return (IServerCollectionHandler)Activator.CreateInstance(resultType);
            }
            catch (Exception ex)
            {
                var msg = String.Format(
                    "Failed to create IServerCollectionHandler for A=[{0}], B=[{1}], role=[{2}]",
                    aType,
                    bType,
                    endRole);
                Log.Error(msg, ex);
                throw;
            }
        }
Exemplo n.º 7
0
        public static void RegisterServices(ImplementationType type, HttpConfiguration config = null)
        {
            var container = new Container();

            if (type == ImplementationType.API)
            {
                if (config == null)
                {
                    throw new ArgumentException("O parametro HttpConfiguration não pode ser null para Web Api");
                }
                container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();
                InitializeContainer(container);
                container.RegisterWebApiControllers(config);
                container.Verify();
                config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
            }
            else
            {
                container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
                InitializeContainer(container);
                //container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
                container.Verify();
                //DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
            }
        }
Exemplo n.º 8
0
        public void GenerateResolver(GeneratedAssembly generatedAssembly)
        {
            if (_resolverType != null)
            {
                return;                        // got some kind of loop in here we need to short circuit
            }
            if (ErrorMessages.Any() || Dependencies.SelectMany(x => x.ErrorMessages).Any())
            {
                return;
            }

            var typeName = (ServiceType.FullNameInCode() + "_" + Name).Sanitize();


            var buildType = ServiceType.MustBeBuiltWithFunc() || ImplementationType.MustBeBuiltWithFunc()
                ? typeof(object)
                : ServiceType;

            _resolverType = generatedAssembly.AddType(typeName, ResolverBaseType.MakeGenericType(buildType));

            var method = _resolverType.MethodFor("Build");

            var frame = CreateBuildFrame();

            method.Frames.Add(frame);
        }
Exemplo n.º 9
0
		public static double[] Run (ImplementationType implType, string mode, int keySize, int blockSize, int dataSize, int threads)
		{
			double[] result;
			int totalBlocks = dataSize / (blockSize >> 3);
			byte[] key = new byte [keySize >> 3];
			byte[] iv  = new byte [blockSize >> 3];
			object algo = Helper.CreateInstance (implType);
			do {
				SymmetricAlgorithmPlus sap = algo as SymmetricAlgorithmPlus;
				if (sap != null) {
					sap.NumberOfThreads = threads;
					sap.ModePlus = (CipherModePlus)Enum.Parse (typeof (CipherModePlus), mode);
					result = Run (sap, key, iv, totalBlocks);
					break;
				}
				SymmetricAlgorithm sa = algo as SymmetricAlgorithm;
				if (sa != null) {
					sa.Mode = (CipherMode)Enum.Parse (typeof (CipherMode), mode);
					result = Run (sa, key, iv, totalBlocks);
					break;
				}
				result = Run (algo as IBlockCipher, mode, key, iv, totalBlocks);
			} while (false);

			for (int i = 0; i < result.Length; i ++)
				result[i] = dataSize * 8.0 / result[i] / (1024.0 * 1024.0);
			return result;
		}
Exemplo n.º 10
0
        private void ValidateOpenGeneric()
        {
            string name = ServiceType.FullName;

            // Open generics must be registered by type.
            if (ImplementationType == null)
            {
                throw new IoCException
                          ($"Open generic type {name} must be implemented by type, " +
                          $"not by instance or expression.");
            }

            var impl = ImplementationType.FullName;

            // Open generic implementations must also be open generics.
            if (!ImplementationType.IsGenericTypeDefinition
                )
            {
                throw new IoCException
                          ($"{impl} is not a valid implementation for {name} as it " +
                          $"is not an open generic.");
            }

            // Open generic implementations must either implement the service interface...
            if (ImplementationType.InheritsOrImplements(ServiceType))
            {
                return;
            }

            throw new IoCException
                      ($"Implementation type {ImplementationType.FullName} does not " +
                      $"implement or derive from service type {ServiceType.FullName}.");
        }
 /// <summary>
 /// Creates new service descriptor object
 /// </summary>
 internal TwinoServiceDescriptor(ImplementationType implementation, Type serviceType, Type implementationType, object instance = null)
 {
     Implementation     = implementation;
     ServiceType        = serviceType;
     ImplementationType = implementationType;
     Instance           = instance;
 }
Exemplo n.º 12
0
        public static double[] Run(ImplementationType implType, string mode, int keySize, int blockSize, int dataSize, int threads)
        {
            double[] result;
            int      totalBlocks = dataSize / (blockSize >> 3);

            byte[] key  = new byte [keySize >> 3];
            byte[] iv   = new byte [blockSize >> 3];
            object algo = Helper.CreateInstance(implType);

            do
            {
                SymmetricAlgorithmPlus sap = algo as SymmetricAlgorithmPlus;
                if (sap != null)
                {
                    sap.NumberOfThreads = threads;
                    sap.ModePlus        = (CipherModePlus)Enum.Parse(typeof(CipherModePlus), mode);
                    result = Run(sap, key, iv, totalBlocks);
                    break;
                }
                SymmetricAlgorithm sa = algo as SymmetricAlgorithm;
                if (sa != null)
                {
                    sa.Mode = (CipherMode)Enum.Parse(typeof(CipherMode), mode);
                    result  = Run(sa, key, iv, totalBlocks);
                    break;
                }
                result = Run(algo as IBlockCipher, mode, key, iv, totalBlocks);
            } while (false);

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = dataSize * 8.0 / result[i] / (1024.0 * 1024.0);
            }
            return(result);
        }
            public override IMessage Invoke(IMessage msg)
            {
                IMethodCallMessage msgCall = msg as IMethodCallMessage;

                if (msgCall != null)
                {
                    if (msgCall.MethodBase == GetTypeMethod)
                    {
                        Type bound = GetBoundType();
                        if (!BoundType.IsAssignableFrom(bound))
                        {
                            throw new InvalidOperationException("Bound type must inherit TBound.");
                        }
                        return(new ReturnMessage(bound, null, 0, msgCall.LogicalCallContext, msgCall));
                    }

                    var method = ImplementationType.GetMethod(msgCall.MethodName, msgCall.MethodSignature as Type[]);
                    if (method == null)
                    {
                        method = msgCall.MethodBase as MethodInfo;
                    }

                    var    args = msgCall.Args;
                    object ret  = method.Invoke(Implementation, args);
                    return(new ReturnMessage(ret, args, args.Length, msgCall.LogicalCallContext, msgCall));
                }
                return(null);
            }
Exemplo n.º 14
0
        protected ValueCollectionWrapper(IZetboxContext ctx, TParent parent, Action parentNotifier, TEntryCollection collection)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            // may be null: if (parentNotifier == null) { throw new ArgumentNullException("parentNotifier"); }
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            this.ctx                  = ctx;
            this.parent               = parent;
            this.parentNotifier       = parentNotifier;
            this.collection           = collection;
            this.tEntryImplementation = ctx.GetImplementationType(typeof(TEntry));
            this.tEntryInterface      = tEntryImplementation.ToInterfaceType();

            // may be necessary on (lazy) initialisation
            foreach (var item in this.collection)
            {
                if (item.Context != this.ctx)
                {
                    ctx.Attach(item);
                }
            }
        }
        /// <summary>
        /// Creates an instance of <typeparamref name="TDefinition"/> within the given <paramref name="container"/> scope and <paramref name="callSync"/> call chain
        /// </summary>
        /// <param name="container"><see cref="Container"/> used to resolve dependencies of the implementation of <typeparamref name="TDefinition"/></param>
        /// <param name="callSync">Virtual call stack used to prevent circular references</param>
        /// <returns>An instance of <typeparamref name="TDefinition"/></returns>
        internal object CreateInstance(Container container, HashSet <Type> callSync)
        {
            if (callSync.Contains(typeof(TDefinition)))
            {
                throw new Exception("Circular reference detected");
            }

            callSync.Add(typeof(TDefinition));

            if (Instance != null)
            {
                return(Instance);
            }

            var constructors = ImplementationType.GetConstructors();

            foreach (var constructor in constructors)
            {
                var result = CreateFromConstructor(constructor, container, callSync);
                if (result == null)
                {
                    continue;
                }

                return(result);
            }

            throw new Exception($"No matching constructor could be found for {ImplementationType.Name} bound as {DefinitionType.Name}");
        }
Exemplo n.º 16
0
		public static string ToName (ImplementationType type)
		{
			string ret;
			if (_implTable.TryGetValue (type, out ret))
				return ret;
			return null;
		}
Exemplo n.º 17
0
        private void btnRunSpeedTest_Click(object sender, EventArgs e)
        {
            ImplementationType type = Helper.ToImplementationType((string)cbImpl.SelectedItem);
            string             mode = (string)cbBlockMode.SelectedItem;
            int keySize             = (int)cbKeySize.SelectedItem;
            int blockSize           = (int)cbBlockSize.SelectedItem;

            string[] items = new string [6];
            items[0] = Helper.ToName(type);
            items[1] = mode;
            items[2] = keySize.ToString() + "bits";
            items[3] = blockSize.ToString() + "bits";
            try {
                double[] result = SpeedTest.Run(type, mode, keySize, blockSize, ToSize((string)cbDataSize.SelectedItem), (int)numThreads.Value);
                items[4] = result[0].ToString("f2") + "Mbps";
                items[5] = result[1].ToString("f2") + "Mbps";
            } catch {
                items[4] = "N/A";
                items[5] = "N/A";
            }
            listResult.Items.Add(new ListViewItem(items));
            while (listResult.Items.Count > 100)
            {
                listResult.Items.RemoveAt(0);
            }
            listResult.EnsureVisible(listResult.Items.Count - 1);
            Application.DoEvents();
        }
Exemplo n.º 18
0
        private void btnKeySchedulingSpeed_Click(object sender, EventArgs e)
        {
            ImplementationType type = Helper.ToImplementationType((string)cbImpl.SelectedItem);
            int keySize             = (int)cbKeySize.SelectedItem;
            int blockSize           = (int)cbBlockSize.SelectedItem;

            string[] items = new string[6];
            items[0] = Helper.ToName(type);
            items[1] = "-";
            items[2] = keySize.ToString() + "bits";
            items[3] = blockSize.ToString() + "bits";
            try {
                uint[] result = KeySchedulingTest.Run(type, keySize, blockSize);
                items[4] = result[0].ToString() + "/s";
                items[5] = result[1].ToString() + "/s";
            } catch {
                items[4] = "N/A";
                items[5] = "N/A";
            }
            listResult.Items.Add(new ListViewItem(items));
            while (listResult.Items.Count > 100)
            {
                listResult.Items.RemoveAt(0);
            }
            listResult.EnsureVisible(listResult.Items.Count - 1);
            Application.DoEvents();
        }
Exemplo n.º 19
0
 public void SetImplementation(Source src, ImplementationType type, string str, bool isDefault)
 {
     ImplementationSource    = src;
     ImplementationType      = type;
     ImplementationString    = str;
     IsDefaultImplementation = isDefault;
 }
Exemplo n.º 20
0
 public UxlImplementation(Source src, ImplementationType type, SourceValue body, SourceValue?cond, bool isDefault)
 {
     Source    = src;
     Type      = type;
     Body      = body;
     Condition = cond;
     IsDefault = isDefault;
 }
        public override int GetHashCode()
        {
            int hash = 17;

            hash = hash * 23 + ImplementationType.GetHashCode();
            hash = hash * 23 + ImplementationLifetime.GetHashCode();
            return(hash);
        }
Exemplo n.º 22
0
 public Type[] GetInjectionInterfaces()
 {
     //    这处理的不好
     return(ImplementationType.GetInterfaces()
            .Where(type =>
                   typeof(IScopedDependency) != type && typeof(ISingletonDependency) != type &&
                   typeof(ITransientDependency) != type).ToArray());
 }
Exemplo n.º 23
0
 public override string ToString()
 => $"{GetType().GetFriendlyName()}"
 + "["
 + $"{ServiceType.GetFriendlyFullName()} - {ImplementationType.GetFriendlyFullName()}"
 + $"{(IsSingleton ? $", {nameof(ServiceRegistration.IsSingleton)}" : string.Empty)}"
 + $"{(IsImplementationContainerCreated ? $", {nameof(ServiceRegistration.IsImplementationContainerCreated)}" : string.Empty)}"
 + $"{(IsSingleton && IsSingletonSet ? $", {nameof(ServiceRegistration.IsSingletonSet)}={IsSingletonSet}" : string.Empty)}"
 + "]";
Exemplo n.º 24
0
        public static string ToName(ImplementationType type)
        {
            string ret;

            if (_implTable.TryGetValue(type, out ret))
            {
                return(ret);
            }
            return(null);
        }
Exemplo n.º 25
0
        private IProxyObject NhFindById(ImplementationType implType, int ID)
        {
            if (ID <= Zetbox.API.Helper.INVALIDID)
            {
                throw new ArgumentOutOfRangeException("ID", ID, "Cannot ask NHibernate for INVALIDID");
            }

            return((IProxyObject)_nhSession
                   .CreateCriteria(ToProxyType(implType))
                   .Add(global::NHibernate.Criterion.Restrictions.Eq("ID", ID))
                   .UniqueResult());
        }
Exemplo n.º 26
0
        private Expression BuildMemberInitExpression(NewExpression newExpression)
        {
            var parameters = newExpression.Constructor.GetParameters();

            var bindings = from s in ImplementationType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                           where s.CanWrite && _container.GetRegistrations(s.PropertyType).Any() &&
                           !s.IsDefined <IgnoreInjectPropertyAttribute>() &&
                           !parameters.Any(t => t.ParameterType == s.PropertyType)       //如果构造器里已经有这个类型,则不使用属性注入
                           select(MemberBinding) Expression.Bind(s, BuildParameterExpression(s.PropertyType));

            return(Expression.MemberInit(newExpression, bindings));
        }
Exemplo n.º 27
0
        /// <summary>
        /// Gets a value that indicates whether or not the current registration matches the specified registration key or not.
        /// </summary>
        /// <returns>
        /// <c>true</c>, if the current instance matches the specified key, <c>false</c> otherwise.</returns>
        /// <param name="key">The registration key against which to test.</param>
        public override bool MatchesKey(ServiceRegistrationKey key)
        {
            if (base.MatchesKey(key))
            {
                return(true);
            }

            if (key == null)
            {
                return(false);
            }

            return(key.ServiceType.GetTypeInfo().IsAssignableFrom(ImplementationType.GetTypeInfo()) && Name == key.Name);
        }
Exemplo n.º 28
0
        private static ServiceLifetime ToLifeTime(this ImplementationType type)
        {
            if (type == ImplementationType.Singleton)
            {
                return(ServiceLifetime.Singleton);
            }

            if (type == ImplementationType.Scoped)
            {
                return(ServiceLifetime.Scoped);
            }

            return(ServiceLifetime.Transient);
        }
Exemplo n.º 29
0
 public Scenario(string scenarioName, ImplementationType implementationType, int runs, int numberOfCores)
 {
     if (implementationType == ImplementationType.All)
     {
         foreach (var implementationName in Enumerable.Where(Enum.GetNames(typeof(ImplementationType)), s => s != "All"))
         {
             _implementations.Add(new Implementation(scenarioName, implementationName, runs, numberOfCores));
         }
     }
     else
     {
         string implementationName = implementationType.ToString();
         _implementations.Add(new Implementation(scenarioName, implementationName, runs, numberOfCores));
     }
 }
Exemplo n.º 30
0
		public static uint[] Run (ImplementationType implType, int keySize, int blockSize)
		{
			byte[] key = new byte [keySize >> 3];
			byte[] iv  = new byte [blockSize >> 3];
			object algo = Helper.CreateInstance (implType);
			SymmetricAlgorithmPlus sap = algo as SymmetricAlgorithmPlus;
			if (sap != null) {
				return Run (sap, key, iv);
			}
			SymmetricAlgorithm sa = algo as SymmetricAlgorithm;
			if (sa != null) {
				return Run (sa, key, iv);
			}
			return Run (algo as IBlockCipher, key, iv);
		}
 public Scenario(string scenarioName, ImplementationType implementationType, int runs, int numberOfCores)
 {
     if (implementationType == ImplementationType.All)
     {
         foreach (var implementationName in Enumerable.Where(Enum.GetNames(typeof(ImplementationType)), s => s != "All"))
         {
             _implementations.Add(new Implementation(scenarioName, implementationName, runs, numberOfCores));
         }
     }
     else
     {
         string implementationName = implementationType.ToString();
         _implementations.Add(new Implementation(scenarioName, implementationName, runs, numberOfCores));
     }
 }
Exemplo n.º 32
0
        private bool AssignableToGenericInterface(Type type)
        {
            var interfaces = ImplementationType.GetInterfaces();

            foreach (var @interface in interfaces)
            {
                var interfaceTypeInfo = @interface.GetTypeInfo();
                if (interfaceTypeInfo.IsGenericType && @interface.GetGenericTypeDefinition() == type)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 33
0
        /// <summary>
        /// Adds a service pool to the container
        /// </summary>
        /// <param name="type">Implementation type</param>
        /// <param name="options">Options function</param>
        /// <param name="instance">After each instance is created, to do custom initialization, this method will be called.</param>
        private void AddPool <TService, TImplementation>(ImplementationType type, Action <ServicePoolOptions> options, Action <TService> instance)
            where TService : class
            where TImplementation : class, TService
        {
            ServicePool <TService, TImplementation> pool = new ServicePool <TService, TImplementation>(type, this, options, instance);
            ServiceDescriptor descriptor = new ServiceDescriptor
            {
                IsPool             = true,
                ServiceType        = typeof(TService),
                ImplementationType = typeof(ServicePool <TService, TImplementation>),
                Instance           = pool,
                Implementation     = ImplementationType.Singleton
            };

            Items.Add(typeof(TService), descriptor);
        }
Exemplo n.º 34
0
		public static object CreateInstance (ImplementationType type)
		{
			switch (type) {
			case ImplementationType.RijndaelRuntime:
				return new RijndaelManaged ();
			case ImplementationType.RijndaelBouncyCastle:
				return new Org.BouncyCastle.Crypto.Engines.AesFastEngine ();
			case ImplementationType.RijndaelOpenCrypto:
				return new openCrypto.RijndaelManaged ();
			case ImplementationType.CamelliaOpenCrypto:
				return new openCrypto.CamelliaManaged ();
			case ImplementationType.CamelliaBouncyCastle:
				return new Org.BouncyCastle.Crypto.Engines.CamelliaEngine ();
			default:
				return null;
			}
		}
Exemplo n.º 35
0
        /// <summary>
        /// Adds a service pool to the container
        /// </summary>
        /// <param name="type">Implementation type</param>
        /// <param name="options">Options function</param>
        /// <param name="instance">After each instance is created, to do custom initialization, this method will be called.</param>
        private void AddPool <TService, TImplementation>(ImplementationType type, Action <ServicePoolOptions> options, Action <TService> instance)
            where TService : class
            where TImplementation : class, TService
        {
            ServicePool <TService, TImplementation> pool = new ServicePool <TService, TImplementation>(type, this, options, instance);
            TwinoServiceDescriptor descriptor            = new TwinoServiceDescriptor(ImplementationType.Singleton,
                                                                                      typeof(TService),
                                                                                      typeof(TImplementation),
                                                                                      //typeof(ServicePool<TService, TImplementation>),
                                                                                      pool)
            {
                IsPool = true
            };

            _items.Add(descriptor);
            _provider = null;
        }
Exemplo n.º 36
0
        /// <summary>
        /// Crates new service pool belong the container with options and after instance creation functions
        /// </summary>
        /// <param name="type">Implementation type</param>
        /// <param name="container">Parent container</param>
        /// <param name="ofunc">Options function</param>
        /// <param name="func">After each instance is created, to do custom initialization, this method will be called.</param>
        public ServicePool(ImplementationType type, IServiceContainer container, Action <ServicePoolOptions> ofunc, Action <TService> func)
        {
            Type      = type;
            Container = container;
            _func     = func;

            Options                            = new ServicePoolOptions();
            Options.PoolMaxSize                = 128;
            Options.MaximumLockDuration        = TimeSpan.FromSeconds(60);
            Options.ExceedLimitWhenWaitTimeout = false;
            Options.WaitAvailableDuration      = TimeSpan.Zero;

            if (ofunc != null)
            {
                ofunc(Options);
            }
        }
        public PerformanceTestSession(ScenarioType scenarioType, ImplementationType implementationType, int runs)
        {
            _scenarioType = scenarioType;
            _implementationType = implementationType;
            _runs = runs;
            _computerSpecifications = ComputerSpecifications.GetSpecificationsForPlatform();
            Console.WriteLine("Scenario={0}, Implementation={1}, Runs={2}", scenarioType, implementationType, runs);

            if (scenarioType == ScenarioType.All)
            {
                foreach (var scenarioName in Enum.GetNames(typeof(ScenarioType)).Where(s => s != "All"))
                {
                    _scenarios.Add(new Scenario(scenarioName, implementationType, runs, _computerSpecifications.NumberOfCores));
                }
            }
            else
            {
                string scenarioName = scenarioType.ToString();
                _scenarios.Add(new Scenario(scenarioName, implementationType, runs, _computerSpecifications.NumberOfCores));
            }
        }
Exemplo n.º 38
0
 private void ApplySelectors(HashSet<ImplementationType> implementations, ContainerService.Builder builder)
 {
     if (builder.Configuration != ServiceConfiguration.empty)
         return;
     if (implementationSelectors.Count == 0)
         return;
     var selectorDecisions = new List<ImplementationSelectorDecision>();
     var typesArray = implementations.Select(x => x.type).ToArray();
     foreach (var s in implementationSelectors)
         s(builder.Type, typesArray, selectorDecisions);
     foreach (var decision in selectorDecisions)
     {
         var item = new ImplementationType
         {
             type = decision.target,
             comment = decision.comment,
             accepted = decision.action == ImplementationSelectorDecision.Action.Include
         };
         implementations.Replace(item);
     }
 }
Exemplo n.º 39
0
		public void LoadData(CLIFile pFile)
		{
			int token = 0;
			if (pFile.FileTable.Length > ImplementationTypeMax16BitRows ||
				pFile.AssemblyRefTable.Length > ImplementationTypeMax16BitRows ||
				pFile.ExportedTypeTable.Length > ImplementationTypeMax16BitRows) token = pFile.ReadInt32();
			else token = pFile.ReadUInt16();
			Type = (ImplementationType)(token & ImplementationTypeMask);
			token = (token >> ImplementationTypeBits) - 1;
			if (token >= 0)
			{
				switch (Type)
				{
					case ImplementationType.File: File = pFile.FileTable[token]; break;
					case ImplementationType.AssemblyRef: AssemblyRef = pFile.AssemblyRefTable[token]; break;
					case ImplementationType.ExportedType: ExportedType = pFile.ExportedTypeTable[token]; break;
					default: throw new BadImageFormatException("Implementation Type");
				}
			}
		}