Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CastleFactory"/> class.
        /// </summary>
        /// <param name="config">The container.</param>
        protected CastleFactory(CastleFactoryConfiguration config)
        {
            this.config    = config;
            this.container = new SimpleServiceContainer(config.Type);

            container.OnLog += (log, type) =>
            {
                if (this.OnLog != null)
                {
                    this.OnLog(log, type);
                }
            };
            container.OnError += error =>
            {
                if (this.OnError != null)
                {
                    this.OnError(error);
                }
            };

            this.proxies = new Dictionary <string, IService>();

            if (config.Nodes.Count > 0)
            {
                foreach (var p in config.Nodes)
                {
                    if (p.Value.MaxPool < 10)
                    {
                        throw new WarningException("Minimum pool size 10!");
                    }
                    if (p.Value.MaxPool > 500)
                    {
                        throw new WarningException("Maximum pool size 500!");
                    }

                    IService proxy = null;
                    if (p.Value.Format == TransferType.Json)
                    {
                        proxy = new InvokeProxy(p.Value, container);
                    }
                    else
                    {
                        proxy = new RemoteProxy(p.Value, container);
                    }

                    this.proxies[p.Key.ToLower()] = proxy;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates this instance.
        /// </summary>
        /// <returns></returns>
        public static CastleFactory Create()
        {
            lock (hashtable.SyncRoot)
            {
                if (singleton == null)
                {
                    var config = CastleFactoryConfiguration.GetConfig();

                    if (config == null)
                    {
                        throw new WarningException("Not find configuration section castleFactory!");
                    }

                    singleton = new CastleFactory(config);
                }
            }

            return(singleton);
        }
        /// <summary>
        ///  Initializes a new instance of the <see cref="ServiceInvocationHandler"/> class.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="container"></param>
        /// <param name="service"></param>
        /// <param name="serviceType"></param>
        /// <param name="cache"></param>
        public ServiceInvocationHandler(CastleFactoryConfiguration config, IServiceContainer container, IService service, Type serviceType, ICacheStrategy cache, IServiceLog logger)
        {
            this.config      = config;
            this.container   = container;
            this.serviceType = serviceType;
            this.service     = service;
            this.cache       = cache;
            this.logger      = logger;

            this.hostName  = DnsHelper.GetHostName();
            this.ipAddress = DnsHelper.GetIPAddress();

            this.cacheTimes = new Dictionary <string, int>();
            var methods = CoreHelper.GetMethodsFromType(serviceType);

            foreach (var method in methods)
            {
                var contract = CoreHelper.GetMemberAttribute <OperationContractAttribute>(method);
                if (contract != null && contract.CacheTime > 0)
                {
                    cacheTimes[method.ToString()] = contract.CacheTime;
                }
            }
        }
 /// <summary>
 ///  Initializes a new instance of the <see cref="ServiceInvocationHandler"/> class.
 /// </summary>
 /// <param name="config"></param>
 /// <param name="container"></param>
 /// <param name="service"></param>
 /// <param name="serviceType"></param>
 /// <param name="cache"></param>
 public LocalInvocationHandler(CastleFactoryConfiguration config, IServiceContainer container, IService service, Type serviceType, ICacheStrategy cache, IServiceLog logger)
     : base(config, container, service, serviceType, cache, logger)
 {
     this.container = container;
     //TO DO
 }