public void ShutdownServices()
        {
            if (Services == null)
            {
                return;
            }

            try
            {
                foreach (ExportServiceHost host in _manager.Services)
                {
                    host.Close();

                    try
                    {
                        Services.Remove(Services.Single(s => s.Name == host.Meta.Name));
                    }
                    catch (InvalidOperationException ex)
                    {
                    }
                }
            }
            catch (Exception e)
            {
                LastMessage = ExceptionMessage.GetExceptionMessage(e);
                RaisePropertyChanged("LastMessage");
            }
        }
        private void StartupServices()
        {
            try
            {
                LastMessage = "搜索可提供的服务...";
                RaisePropertyChanged("LastMessage");

                _bootstrapper = new ServiceHostBootstrapper();
                _bootstrapper.Run();

                //DatabaseInitializer.Initialize();

                IServiceLocator serviceLocator = _bootstrapper._container.GetExportedValue <IServiceLocator>();
                _manager            = serviceLocator.GetInstance <IServiceHostManager>() as ServiceHostManager;
                _manager._container = _bootstrapper._container;
                _manager.LookupServices();

                LastMessage = "找到服务" + _manager.Services.Count <ExportServiceHost>().ToString() + "个";
                RaisePropertyChanged("LastMessage");

                _lighterServerContext = _bootstrapper._container.GetExportedValue <ILighterServerContext>();
                Users = _lighterServerContext.LoginedAccounts;

                foreach (ExportServiceHost host in _manager.Services)
                {
                    if (!host.UpdateAddressPort(ServerPort))
                    {
                        LastMessage = "Hosting Service: " + host.Meta.Name + " UpdateAddressPort " + ServerPort.ToString() + " failure.";
                        RaisePropertyChanged("LastMessage");
                    }

                    Debug.Assert(host.Description.Endpoints.Count == 1);
                    var address = host.Description.Endpoints[0];

                    host.Open();
                    host.Opened += delegate
                    {
                        LastMessage = "服务已启动: " + host.Meta.Name + " at " + address.Address.Uri;
                        RaisePropertyChanged("LastMessage");
                    };

                    //foreach (var address in host.Description.Endpoints)
                    {
                        LastMessage = "正在初始化服务 " + host.Meta.Name + " ... ";
                        RaisePropertyChanged("LastMessage");

                        //OperationContext operationContext = OperationContext.Current;
                        //InstanceContext instanceContext = operationContext.InstanceContext;
                        //ILighterService service = instanceContext.GetServiceInstance() as ILighterService;
                        //service.Initialize();

                        ServiceInfo info = new ServiceInfo(host.Meta.Description, address.Address.Uri);
                        Services.Add(info);
                        RaisePropertyChanged("Services");
                    }
                }

                LastMessage = "服务已提供";
                RaisePropertyChanged("LastMessage");

                IEventAggregator _eventAggregator = _manager._container.GetExportedValue <IEventAggregator>();
                _eventAggregator.GetEvent <AccountLoginEvent>().Subscribe(AccountLogined);
                _eventAggregator.GetEvent <AccountLogoutEvent>().Subscribe(AccountLogouted);
            }
            catch (Exception e)
            {
                LastMessage = ExceptionMessage.GetExceptionMessage(e);
                RaisePropertyChanged("LastMessage");
            }
        }