Exemple #1
0
        /// <summary>
        /// 停止服务
        /// </summary>
        /// <param name="message">出错的情况下为出错的具体描述</param>
        /// <returns>成功与否</returns>
        public bool StopService(out string message)
        {
            lock (this)
            {
                if (!ServiceStarted || serviceHostPharmacyService == null || serviceHostPharmacyService.State != CommunicationState.Opened)
                {
                    ServiceStarted             = false;
                    serviceHostPharmacyService = null;
                    message = "服务已经启动";
                    return(true);
                }
                OnPreStopService(EventArgs.Empty);
                Log.Information("开始停止服务.....");
                ServiceStarted = false;
                message        = string.Empty;
                try
                {
                    NotificationClientContextManager.Clear();
                    //通知服务
                    Log.Information("开始停止[通知服务].....");
                    if (serviceHostNotification != null)
                    {
                        serviceHostNotification.Abort();
                        serviceHostNotification.Close();
                    }
                    Log.Information("成功停止[通知服务].....");

                    //数据服务
                    Log.Information("开始停止[数据服务].....");
                    if (serviceHostPharmacyService != null)
                    {
                        serviceHostPharmacyService.Abort();
                        serviceHostPharmacyService.Close();
                    }
                    Log.Information("成功停止[数据服务]");

                    OnEndStopService(EventArgs.Empty);
                    ServiceStarted = false;
                    Log.Information("停止服务成功!");
                    return(!ServiceStarted);
                }
                catch (Exception ex)
                {
                    ex      = new Exception("停止服务失败!", ex);
                    message = ex.Message;
                    Log.Error(ex);
                    return(false);
                }
                finally
                {
                    Log.Information("结束停止服务.....");
                }
            }
        }
 public void RegisterClientNotification(User user)
 {
     try
     {
         NotificationClientContextManager.RegisterNotificationClientContext(user, OperationContext.Current);
     }
     catch (Exception ex)
     {
         ex = new Exception("为用户注册通知服务失败", ex);
         LoggerHelper.Instance.Error(ex);
     }
 }
 public void CloseClientNotification(User user)
 {
     try
     {
         NotificationClientContextManager.RemoveNotification(user);
         NotificationClientContextManager.RemoveNotification(OperationContext.Current);
     }
     catch (Exception ex)
     {
         ex = new Exception("为用户注销通知服务失败", ex);
         LoggerHelper.Instance.Error(ex);
     }
 }