internal static IEnhancedOrgService GetConnection(string connectionString, bool noCache = false)
        {
            Status.Update("Creating connection to CRM ... ", false);

            poolCache.TryGetValue(connectionString, out var pool);
            factoryCache.TryGetValue(connectionString, out var factory);

            if (pool == null || factory == null)
            {
                var template = EnhancedServiceBuilder.NewBuilder
                               .Initialise(connectionString)
                               .AddCaching()
                               .Finalise()
                               .GetBuild();
                factoryCache[connectionString] = factory = new EnhancedServiceFactory <EnhancedOrgService>(template);
                poolCache[connectionString]    = pool = new EnhancedServicePool <EnhancedOrgService>(factory);
            }

            if (noCache)
            {
                factory.ClearCache();
            }

            var service = pool.GetService();

            Status.Update("done!");

            return(service);
        }
Exemple #2
0
        public static IEnhancedServicePool <IEnhancedOrgService> GetPool(ConnectionParams connectionParams, PoolParams poolParams)
        {
            var parameters = BuildBaseParams(string.Empty, 2, poolParams, connectionParams);
            var factory    = new EnhancedServiceFactory <IEnhancedOrgService, Services.Enhanced.EnhancedOrgService>(parameters);

            return(new EnhancedServicePool <IEnhancedOrgService, Services.Enhanced.EnhancedOrgService>(factory, poolParams));
        }
Exemple #3
0
        public static IEnhancedServicePool <IEnhancedOrgService> GetPool(string connectionString, int poolSize = 2)
        {
            var parameters = BuildBaseParams(connectionString, poolSize);
            var factory    = new EnhancedServiceFactory <IEnhancedOrgService, Services.Enhanced.EnhancedOrgService>(parameters);

            return(new EnhancedServicePool <IEnhancedOrgService, Services.Enhanced.EnhancedOrgService>(factory, poolSize));
        }
        public static EnhancedServicePool <AsyncOrgService> GetAsyncPool(string connectionString, int poolSize = 10,
                                                                         EnhancedServiceParams serviceParams   = null, bool isHoldAppForAsync = true)
        {
            var builder = EnhancedServiceBuilder.NewBuilder.Initialise(connectionString);

            if (serviceParams?.IsCachingEnabled == true)
            {
                builder.AddCaching(serviceParams.CachingParams);
            }

            if (serviceParams?.IsConcurrencyEnabled != false)
            {
                builder.AddConcurrency(serviceParams?.ConcurrencyParams);

                if (isHoldAppForAsync)
                {
                    builder.HoldAppForAsync();
                }
            }

            if (serviceParams?.IsTransactionsEnabled == true)
            {
                builder.AddTransactions(serviceParams.TransactionParams);
            }

            var build   = builder.Finalise().GetBuild();
            var factory = new EnhancedServiceFactory <AsyncOrgService>(build);

            return(new EnhancedServicePool <AsyncOrgService>(factory, poolSize));
        }
Exemple #5
0
        public static IOrganizationService GetConnection(Settings settings, ref int connectionsCreated, int total = 1)
        {
            Status.Update($"Creating connection {connectionsCreated + 1} / {total} to CRM ... ");

            var connectionString = settings.GetOrganizationCrmConnectionString();

            poolCache.TryGetValue(connectionString, out var pool);
            factoryCache.TryGetValue(connectionString, out var factory);

            if (pool == null || factory == null)
            {
                var template = EnhancedServiceBuilder.NewBuilder
                               .Initialise(connectionString)
                               .Finalise()
                               .GetBuild();
                factoryCache[connectionString] = factory = new EnhancedServiceFactory <EnhancedOrgService>(template);
                poolCache[connectionString]    = pool = new EnhancedServicePool <EnhancedOrgService>(factory);
            }

            var service = pool.GetService();

            Status.Update($"Created connection {++connectionsCreated} / {total}.");

            return(service);
        }
 public EnhancedServicePool(EnhancedServiceFactory <TServiceInterface, TEnhancedOrgService> factory, int poolSize)
 {
     this.factory = factory;
     poolParams   = new PoolParams {
         PoolSize = poolSize
     };
 }
        public static EnhancedServicePool <Services.EnhancedOrgService> GetPool(string connectionString,
                                                                                EnhancedServiceParams serviceParams = null)
        {
            var builder = EnhancedServiceBuilder.NewBuilder.Initialise(connectionString);

            if (serviceParams?.IsCachingEnabled == true)
            {
                serviceParams.CachingParams = serviceParams.CachingParams
                                              ?? new CachingParams
                {
                    CacheMode = CacheMode.PrivatePerInstance
                };
                builder.AddCaching(serviceParams.CachingParams);
            }

            if (serviceParams?.IsConcurrencyEnabled == true)
            {
                builder.AddConcurrency(serviceParams.ConcurrencyParams);
            }

            if (serviceParams?.IsTransactionsEnabled == true)
            {
                builder.AddTransactions(serviceParams.TransactionParams);
            }

            var build   = builder.Finalise().GetBuild();
            var factory = new EnhancedServiceFactory <Services.EnhancedOrgService>(build);

            return(new EnhancedServicePool <Services.EnhancedOrgService>(factory));
        }
Exemple #8
0
        public static IEnhancedServicePool <ICachingOrgService> GetPoolCaching(ConnectionParams connectionParams, PoolParams poolParams,
                                                                               CachingParams cachingParams = null)
        {
            var parameters = BuildBaseParams(string.Empty, 2, null, connectionParams,
                                             cachingParams ?? new CachingParams());
            var factory = new EnhancedServiceFactory <ICachingOrgService, CachingOrgService>(parameters);

            return(new EnhancedServicePool <ICachingOrgService, CachingOrgService>(factory, poolParams));
        }
Exemple #9
0
        public static IEnhancedServicePool <ICachingOrgService> GetPoolCaching(string connectionString, int poolSize = 2,
                                                                               CachingParams cachingParams           = null)
        {
            var parameters = BuildBaseParams(connectionString, poolSize, null,
                                             cachingParams: cachingParams ?? new CachingParams());
            var factory = new EnhancedServiceFactory <ICachingOrgService, CachingOrgService>(parameters);

            return(new EnhancedServicePool <ICachingOrgService, CachingOrgService>(factory, poolSize));
        }
        public EnhancedServicePool(EnhancedServiceFactory <TServiceInterface, TEnhancedOrgService> factory, PoolParams poolParams = null)
        {
            this.factory = factory;

            if (poolParams != null)
            {
                poolParams.IsLocked = true;
            }

            this.poolParams = poolParams ?? factory.Parameters?.PoolParams ?? new PoolParams();
        }
Exemple #11
0
        public static IEnhancedServicePool <ICachingOrgService> GetCachingPool(ServiceParams serviceParams)
        {
            serviceParams.Require(nameof(serviceParams));

            if (AutoSetMaxPerformanceParams)
            {
                serviceParams.AutoSetMaxPerformanceParams();
            }

            var factory = new EnhancedServiceFactory <ICachingOrgService, CachingOrgService>(serviceParams);

            return(new EnhancedServicePool <ICachingOrgService, CachingOrgService>(factory, serviceParams.PoolParams));
        }
Exemple #12
0
        public static ICachingOrgService GetCachingPoolingService(ServiceParams serviceParams)
        {
            serviceParams.Require(nameof(serviceParams));

            if (AutoSetMaxPerformanceParams)
            {
                serviceParams.AutoSetMaxPerformanceParams();
            }

            var pool    = new DefaultServicePool(serviceParams);
            var factory = new EnhancedServiceFactory <ICachingOrgService, CachingOrgService>(serviceParams);

            return(factory.CreateService(pool));
        }
Exemple #13
0
        public static IEnhancedServicePool <ICachingOrgService> GetPoolCaching(EnhancedServiceParams serviceParams)
        {
            var factory = new EnhancedServiceFactory <ICachingOrgService, CachingOrgService>(serviceParams);

            return(new EnhancedServicePool <ICachingOrgService, CachingOrgService>(factory));
        }
Exemple #14
0
        public static IEnhancedServicePool <IEnhancedOrgService> GetPool(EnhancedServiceParams serviceParams)
        {
            var factory = new EnhancedServiceFactory <IEnhancedOrgService, Services.Enhanced.EnhancedOrgService>(serviceParams);

            return(new EnhancedServicePool <IEnhancedOrgService, Services.Enhanced.EnhancedOrgService>(factory));
        }
Exemple #15
0
 public EnhancedServicePool(EnhancedServiceFactory <TService> factory, int poolSize = 10)
 {
     this.factory  = factory;
     this.poolSize = poolSize;
 }
 public EnhancedServicePool(EnhancedServiceFactory <TService> factory)
 {
     this.factory = factory;
 }