Example #1
0
        public static void Start()
        {
            new Thread(
                delegate()
                {
                    _state = AlbianState.Starting;
                    _service = new AlbianChunk("AlbianService");
                    IConfigParser parser = new ServiceConfigParser();
                    parser.Init("config/service.config");
                    IDictionary<string, IAlbianServiceAttrbuite> serviceInfos = FreeServiceConfigParser.ServiceConfigInfo;
                    bool isSuccess = true;
                    IDictionary<string, IAlbianServiceAttrbuite> failServicesInfos = new Dictionary<string, IAlbianServiceAttrbuite>();
                    int failCountBeforeTimes = 0;
                    while (true)
                    {
                        isSuccess = true;
                        if (0 != failServicesInfos.Count)
                        {
                            if (failCountBeforeTimes == failServicesInfos.Count)
                            {
                                if (null != Logger)
                                {
                                    Logger.ErrorFormat("Refer to each other when service loading!");
                                    foreach (KeyValuePair<string, IAlbianServiceAttrbuite> kv in failServicesInfos)
                                    {
                                        Logger.ErrorFormat("Refer to each other!id:{0},Type:{1}", kv.Value.Id, kv.Value.Type);
                                    }
                                    Logger.Error("Please examine the service id above the line!");
                                }
                                _state = AlbianState.UnLoading;
                                throw new ServiceException("Refer to each other!");
                            }

                            failCountBeforeTimes = failServicesInfos.Count;
                            serviceInfos.Clear();
                            foreach (KeyValuePair<string, IAlbianServiceAttrbuite> kv in failServicesInfos)
                            {
                                serviceInfos.Add(kv.Key, kv.Value);
                            }
                            failServicesInfos.Clear();
                        }

                        foreach (KeyValuePair<string, IAlbianServiceAttrbuite> kv in serviceInfos)
                        {
                            try
                            {
                                Type impl = Type.GetType(kv.Value.Type);
                                IAlbianService service = (IAlbianService)Activator.CreateInstance(impl);
                                service.State = ServiceState.Loading;
                                service.Loading();
                                service.State = ServiceState.Running;
                                _service.Set(kv.Key, service);
                            }
                            catch
                            {
                                isSuccess = false;
                                failServicesInfos.Add(kv.Key, kv.Value);
                            }
                        }
                        if (isSuccess)
                        {
                            _state = AlbianState.Running;
                            break;
                        }
                    }
                }
                ).Start();
        }
Example #2
0
        public static void Start()
        {
            new Thread(
                delegate()
            {
                _state               = AlbianState.Starting;
                _service             = new AlbianChunk("AlbianService");
                IConfigParser parser = new ServiceConfigParser();
                parser.Init("config/service.config");
                IDictionary <string, IAlbianServiceAttrbuite> serviceInfos = FreeServiceConfigParser.ServiceConfigInfo;
                bool isSuccess = true;
                IDictionary <string, IAlbianServiceAttrbuite> failServicesInfos = new Dictionary <string, IAlbianServiceAttrbuite>();
                int failCountBeforeTimes = 0;
                while (true)
                {
                    isSuccess = true;
                    if (0 != failServicesInfos.Count)
                    {
                        if (failCountBeforeTimes == failServicesInfos.Count)
                        {
                            if (null != Logger)
                            {
                                Logger.ErrorFormat("Refer to each other when service loading!");
                                foreach (KeyValuePair <string, IAlbianServiceAttrbuite> kv in failServicesInfos)
                                {
                                    Logger.ErrorFormat("Refer to each other!id:{0},Type:{1}", kv.Value.Id, kv.Value.Type);
                                }
                                Logger.Error("Please examine the service id above the line!");
                            }
                            _state = AlbianState.UnLoading;
                            throw new ServiceException("Refer to each other!");
                        }

                        failCountBeforeTimes = failServicesInfos.Count;
                        serviceInfos.Clear();
                        foreach (KeyValuePair <string, IAlbianServiceAttrbuite> kv in failServicesInfos)
                        {
                            serviceInfos.Add(kv.Key, kv.Value);
                        }
                        failServicesInfos.Clear();
                    }

                    foreach (KeyValuePair <string, IAlbianServiceAttrbuite> kv in serviceInfos)
                    {
                        try
                        {
                            Type impl = Type.GetType(kv.Value.Type);
                            IAlbianService service = (IAlbianService)Activator.CreateInstance(impl);
                            service.State          = ServiceState.Loading;
                            service.Loading();
                            service.State = ServiceState.Running;
                            _service.Set(kv.Key, service);
                        }
                        catch
                        {
                            isSuccess = false;
                            failServicesInfos.Add(kv.Key, kv.Value);
                        }
                    }
                    if (isSuccess)
                    {
                        _state = AlbianState.Running;
                        break;
                    }
                }
            }
                ).Start();
        }