Exemplo n.º 1
0
            /// <summary>
            /// 构造函数
            /// </summary>
            /// <param name="service">The service object that is used to invoke methods on</param>
            /// <param name="serviceAttribute">MDSService attribute of service object's class</param>
            public ServiceObject(ApService service, ApServiceAttribute serviceAttribute)
            {
                Service = service;
                ServiceAttribute = serviceAttribute;

                _serviceClassName = service.GetType().Name;

                //Find all methods
                _methods = new SortedList<string, bool>();
                foreach (var methodInfo in Service.GetType().GetMethods())
                {
                    var attributes = methodInfo.GetCustomAttributes(typeof(ApServiceMethodAttribute), true);
                    _methods.Add(methodInfo.Name, attributes.Length > 0);
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// 添加服务类
        /// </summary>
        /// <param name="service">Service to add</param>
        public void AddService(ApService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            var type = service.GetType();
            var attributes = type.GetCustomAttributes(typeof (ApServiceAttribute), true);
            if(attributes.Length <= 0)
            {
                throw new Exception("Service class must has ApService attribute to be added.");
            }

            if (_serviceObjects.ContainsKey(type.Name))
            {
                throw new Exception("Service '" + type.Name + "' is already added.");
            }
            service.ServiceApplication = this;
            _serviceObjects.Add(type.Name, new ServiceObject(service, (ApServiceAttribute)attributes[0]));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 移除服务类
        /// </summary>
        /// <param name="service">Service to add</param>
        public void RemoveService(ApService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            var type = service.GetType();
            if (!_serviceObjects.ContainsKey(type.Name))
            {
                return;
            }

            _serviceObjects.Remove(type.Name);
        }