Exemplo n.º 1
0
            public static Client GetInstance <T>() where T : Client
            {
                Client instance;

                try
                {
                    instance = DoGetInstance(typeof(T));
                }
                catch (Exception e)
                {
                    Logger.GetInstance(typeof(Client)).Fatal("Instance initialization error: " + e);
                    Logger.GetInstance(typeof(Client)).Info("Initializing " + typeof(NamedPipeIpcChannel.Client).FullName + "...");
                    instance = new NamedPipeIpcChannel.Client();
                }
                return(instance);
            }
Exemplo n.º 2
0
            private static Client DoGetInstance(Type type)
            {
                if (type == null)
                {
                    throw new ArgumentException("Invalid arguments to get " + typeof(Client).Name + " instance");
                }

                var    key      = type.FullName + "_";
                Client instance = null;

                if (Instances.ContainsKey(key))
                {
                    instance = Instances[key];
                }
                if (instance == null)
                {
                    Logger.GetInstance(typeof(Client)).Info("Initializing " + key + "...");
                    var constructor = type.GetConstructor(new Type[] { });
                    if (constructor != null)
                    {
                        instance = (Client)constructor.Invoke(new object[] { });
                    }
                }
                if (instance == null)
                {
                    Logger.GetInstance(typeof(Client)).Info("Initializing " + typeof(NamedPipeIpcChannel.Client).FullName + "...");
                    instance = new NamedPipeIpcChannel.Client();
                }
                lock (InstancesLock)
                {
                    if (!Instances.ContainsKey(key))
                    {
                        Instances.Add(key, instance);
                    }
                }
                return(instance);
            }