public override ManagerStateEnum Stop() { if (this.ManagerState == ManagerStateEnum.Started) { if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, service stopping...", LOG_PREFIX)); } OnStop(ManagerEventStateEnum.Before); Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContextLock.Lock(); try { NetworkPeerDataContext context = Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContext; if (context != null) { context.PropertyItems.Remove(Id); Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContext = context; } } finally { Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContextLock.Unlock(); } if (ServiceBaseServices.IsContractRegistered(typeof(TIServiceProxyType))) { ServiceBaseServices.UnregisterContract(typeof(TIServiceProxyType)); } this.ManagerState = ManagerStateEnum.Stopped; if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, service successfully stopped.", LOG_PREFIX)); } OnStop(ManagerEventStateEnum.After); } return(this.ManagerState); }
public virtual ManagerStateEnum Start(long priority, IServiceDescriptor serviceDescriptor) { if (this.ManagerState != ManagerStateEnum.Started) { if (priority < 0) { ThrowHelper.ThrowArgumentOutOfRangeException("priority"); } if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, initializing service...", LOG_PREFIX)); } OnStart(ManagerEventStateEnum.Before); try { ChannelServices.Initialize(); this.ChannelId = ConfigurationAccessHelper.GetValueByPath(NetworkServiceConfiguration.Settings.CategoryPropertyItems, string.Format("Services/{0}", Id)); if (string.IsNullOrEmpty(this.ChannelId)) { this.ChannelId = Id; } Channel channel = LookUpChannel(); if (channel.ServerEndpoints.Count == 0) { throw new InvalidConfigurationException(string.Format("Channel '{0}' has not got listening server endpoint(s).", channel.ChannelId)); } ServiceBaseServices.Initialize(); if (!ServiceBaseServices.IsContractRegistered(typeof(TIServiceProxyType))) { ServiceBaseServices.RegisterContract(typeof(TIServiceProxyType), typeof(TServiceProxyImplementationType)); } this.mPriority = priority; this.mServiceDescriptor = serviceDescriptor; RegisterToPeerContext(channel, priority, serviceDescriptor); this.ManagerState = ManagerStateEnum.Started; if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, service successfully initialized.", LOG_PREFIX)); } } catch (Exception) { this.ManagerState = ManagerStateEnum.Fault; throw; } OnStart(ManagerEventStateEnum.After); } return(this.ManagerState); }