Esempio n. 1
0
        public EnhancedServiceFactory(EnhancedServiceParams parameters)
        {
            var enhancedOrgType = typeof(TEnhancedOrgService);

            if (enhancedOrgType.IsAbstract)
            {
                throw new NotSupportedException("Given Enhanced Org type must be concrete.");
            }

            parameters.Require(nameof(parameters));

            var isCachingService = typeof(ICachingOrgService).IsAssignableFrom(typeof(TEnhancedOrgService));

            if (parameters.IsCachingEnabled == true && !isCachingService)
            {
                throw new NotSupportedException("Cannot create a caching service factory unless the given service is caching.");
            }

            SetPerformanceParams(parameters);

            parameters.IsLocked = true;
            Parameters          = parameters;

            customCacheFactory = parameters.CachingParams.CustomCacheFactory;

            if (parameters.IsCachingEnabled == true)
            {
                switch (parameters.CachingParams.CacheScope)
                {
                case CacheScope.Global:
                    factoryCache = customCacheFactory == null ? MemoryCache.Default : customCacheFactory(this, Parameters, null);
                    break;

                case CacheScope.Factory:
                    factoryCache = customCacheFactory == null
                                                        ? (parameters.CachingParams.ObjectCache ?? new MemoryCache(parameters.ConnectionParams.ConnectionString))
                                                        : customCacheFactory(this, Parameters, null);
                    break;

                case CacheScope.Service:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(parameters.CachingParams.CacheScope));
                }
            }

            customServiceFactory = parameters.ConnectionParams.CustomIOrgSvcFactory ?? customServiceFactory;
        }
        public virtual INodeService AddNode(EnhancedServiceParams serviceParams, int weight = 1)
        {
            serviceParams.Require(nameof(serviceParams), "Service Parameters must be set first.");
            weight.RequireAtLeast(1, nameof(weight));

            var node = new NodeService(serviceParams, weight);

            if (NodeQueue.IsEmpty)
            {
                SetPrimaryNode(node);
            }

            NodeQueue.Enqueue(node);

            return(node);
        }