public void TestConfigParser()
        {
            var testconnection = "Endpoint=http://abc;Port=888;AccessKey=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGH==A;Version=1.0;";
            var configs        = new ServiceConfigParser(testconnection);

            Assert.AreEqual("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGH==A", configs.AccessKey);
            Assert.AreEqual("http://abc/", configs.Endpoint.ToString());
            Assert.AreEqual(888, configs.Port);
        }
Esempio n. 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();
        }