/// <summary>
 /// 注册所有公共方法
 /// </summary>
 /// <param name="server"></param>
 /// <param name="obj"></param>
 public static void RegisterService <T>(this HproseService server, object obj) where  T : class
 {
     if (!(obj is T))
     {
         return;
     }
     foreach (MethodInfo declaredMethod in obj.GetType().GetTypeInfo().DeclaredMethods)
     {
         if (declaredMethod.IsPublic)
         {
             server.Add(declaredMethod, obj, declaredMethod.Name, HproseResultMode.Normal, false);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// 服务是否已启动
        /// </summary>
        /// <param name="service"></param>
        /// <returns></returns>
        public static bool IsStarted(this HproseService service)
        {
            if (null == service)
            {
                return(false);
            }

            var value = service.GetValue("IsStarted");

            if (null == value)
            {
                return(false);
            }

            return(value.ToBool());
        }
Exemple #3
0
        /// <summary>
        /// 启动服务
        /// </summary>
        /// <param name="protocol">网络协议</param>
        /// <param name="port">监听端口</param>
        /// <param name="notifierName">通知器名称</param>
        /// <returns>错误信息</returns>
        public string Start(string protocol, int port, string notifierName, WriteLogDelegate writeLog = null)
        {
            try
            {
                if (m_Service != null)
                {
                    if (m_Service.IsStarted())
                    {
                        return(string.Empty);
                    }
                }
                else
                {
                    //var notifierName = ConfigHelper.GetValue("Notifier");
                    var notifier = GetNotifier(notifierName);
                    if (null == notifier)
                    {
                        throw new Exception("创建通知器实例失败");
                    }

                    if (writeLog != null)
                    {
                        notifier.SetLogger(writeLog);
                    }

                    //var port = ConfigHelper.GetInt32("ListenPort");
                    //var protocol = ConfigHelper.GetValue("NetProtocol").LowerCase();

                    m_Service = GetServer(protocol, port);
                    m_Service.Add("SendMessage", notifier);
                }

                m_Service.Start();

                return(m_Service.IsStarted() ? string.Empty : "服务启动失败");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemple #4
0
        /// <summary>
        /// 注册所有公共方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="server"></param>
        /// <param name="implement"></param>
        public static void RegisterService <T>(this HproseService server, object implement) where T : class
        {
            var methods = typeof(T).GetMethods().Where(t => t.IsPublic).Select(t => t.Name).ToArray();

            server.Add(methods, implement);
        }
Exemple #5
0
 /// <summary>
 /// 停止服务
 /// </summary>
 /// <param name="service"></param>
 public static void Stop(this HproseService service)
 => service?.Invoke("Stop");