Esempio n. 1
0
        private static T CreateCounters <T>(string instance)
        {
            T result = Activator.CreateInstance <T>();

            try {
                IICPerformanceCountersAttribute categoryAttr = AttributeHelper.
                                                               GetAttribute <IICPerformanceCountersAttribute>(typeof(T));

                List <IICPerformanceCounter> counters = new List <IICPerformanceCounter>();

                FieldInfo[] fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

                foreach (FieldInfo fieldInfo in fields)
                {
                    IICPerformanceCounterAttribute counterAttr = AttributeHelper.
                                                                 GetAttribute <IICPerformanceCounterAttribute>(fieldInfo);

                    IICPerformanceCounter perfCounter = new IICPerformanceCounter();

                    perfCounter._rawAttr = counterAttr;
                    counters.Add(perfCounter);

                    fieldInfo.SetValue(result, perfCounter);
                }

                IICPerformanceCounterMananger.CreateCounters(instance, categoryAttr, counters);
            } catch (Exception ex) {
                SystemLog.Warn(LogEventID.PerformanceCounterFailed, ex, "PerformanceCounter<{0}>({1}) Create Failed.", typeof(T).Name, instance);
            }
            return(result);
        }
Esempio n. 2
0
        public virtual void SetDefaultValue()
        {
            Type sectionType = this.GetType();

            IICConfigSectionAttribute sectionAttr = AttributeHelper.GetAttribute <IICConfigSectionAttribute>(sectionType);

            foreach (FieldInfo field in sectionType.GetFields())
            {
                IICConfigFieldAttribute fieldAttr = AttributeHelper.TryGetAttribute <IICConfigFieldAttribute>(field);
                if (fieldAttr != null && fieldAttr.DefaultValue != null)
                {
                    ObjectHelper.SetValue(field, this, fieldAttr.DefaultValue);
                    continue;
                }

                IICConfigItemAttribute itemAttr = AttributeHelper.TryGetAttribute <IICConfigItemAttribute>(field);
                if (itemAttr != null)
                {
                    IICConfigItem item = (IICConfigItem)Activator.CreateInstance(field.FieldType);
                    item.SetDefaultValue();
                    field.SetValue(this, item);
                    continue;
                }

                IICConfigItemCollectionAttribute colletionAttr = AttributeHelper.TryGetAttribute <IICConfigItemCollectionAttribute>(field);
                if (colletionAttr != null)
                {
                    object collection = Activator.CreateInstance(field.FieldType);
                    field.SetValue(this, collection);
                    continue;
                }
            }
        }
Esempio n. 3
0
        public RpcServiceDecorator(T serviceObj) : base(string.Empty)
        {
            Type intf = typeof(T);

            if (!intf.IsInterface)
            {
                throw new NotSupportedException();
            }

            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf);

            p_serviceName = serviceAttr.ServiceName;
            _serviceObj   = serviceObj;

            IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("rpc:" + p_serviceName, PerformanceCounterCategoryType.MultiInstance);

            foreach (MethodInfo method in intf.GetMethods())
            {
                RpcServiceMethodAttribute methodAttr = AttributeHelper.GetAttribute <RpcServiceMethodAttribute>(method);
                string methodName = method.Name;

                RpcServiceMethod m = new RpcServiceDecorator <T> .RpcServiceMethod();

                m.RatePerSecond = category.CreateCounter(methodName + " /sec.", PerformanceCounterType.RateOfCountsPerSecond32);
                m.TotalCount    = category.CreateCounter(methodName + " Total.", PerformanceCounterType.NumberOfItems32);
                m.TotalFailed   = category.CreateCounter(methodName + " Failed.", PerformanceCounterType.NumberOfItems32);
                m.Concurrent    = category.CreateCounter(methodName + " Concurrent.", PerformanceCounterType.NumberOfItems32);
                m.Method        = method;

                _methods.Add(methodName, m);
            }
            IICPerformanceCounterFactory.GetCounters(category);
        }
Esempio n. 4
0
        public RpcServiceDecorator(T serviceObj, string serviceName) : base(string.Empty)
        {
            Type intf = typeof(T);

            if (!intf.IsInterface)
            {
                throw new NotSupportedException();
            }

            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf);

            if (!string.IsNullOrEmpty(serviceName))
            {
                p_serviceName = serviceName;
            }
            else
            {
                p_serviceName = serviceAttr.ServiceName;
            }

            _serviceObj = serviceObj;
            _methods    = new HybridDictionary <string, RpcServiceMethod>();

            bool enableCounter = serviceAttr.EnableCounters == RpcPerformanceCounterMode.Both || serviceAttr.EnableCounters == RpcPerformanceCounterMode.Server;

            IICPerformanceCounterCategory category = new IICPerformanceCounterCategory("rpc:" + p_serviceName, PerformanceCounterCategoryType.MultiInstance);

            foreach (MethodInfo method in intf.GetMethods())
            {
                string           methodName = method.Name;
                RpcServiceMethod m;

                RpcServiceBatchMethodAttribute battr = AttributeHelper.TryGetAttribute <RpcServiceBatchMethodAttribute>(method);
                if (battr != null)
                {
                    if (!string.IsNullOrEmpty(battr.MethodName))
                    {
                        methodName = battr.MethodName;
                    }

                    m = new RpcServiceBatchMethod(serviceObj, category, methodName, method, enableCounter);
                }
                else
                {
                    RpcServiceMethodAttribute attr = AttributeHelper.GetAttribute <RpcServiceMethodAttribute>(method);
                    if (!string.IsNullOrEmpty(attr.MethodName))
                    {
                        methodName = attr.MethodName;
                    }

                    m = new RpcServiceMethod(serviceObj, category, methodName, method, enableCounter);
                }

                _methods.Add(methodName, m);
            }
            IICPerformanceCounterFactory.GetCounters(category);
        }
Esempio n. 5
0
        private static RpcClientProxy GetProxyInner <T>(ServerUri solvedUri, ResolvableUri toUri)
        {
            var attr = AttributeHelper.GetAttribute <RpcServiceAttribute>(typeof(T));

            if (attr == null)
            {
                throw new NotSupportedException("RpcInterface MUST markup with [RpcService] Attribute");
            }

            return(GetProxyInner(solvedUri, toUri, attr.ServiceName));
        }
Esempio n. 6
0
        public static IICConfigSection CreateDefault(Type sectionType)
        {
            IICConfigSectionAttribute attr = AttributeHelper.GetAttribute <IICConfigSectionAttribute>(sectionType);

            if (attr.IsRequired)
            {
                return(null);
            }
            else
            {
                IICConfigSection ret = (IICConfigSection)Activator.CreateInstance(sectionType);
                ret.SetDefaultValue();
                return(ret);
            }
        }
Esempio n. 7
0
        public static IICConfigItem CreateDefault(Type type)
        {
            IICConfigItemAttribute itemAttr = AttributeHelper.GetAttribute <IICConfigItemAttribute>(type);

            if (itemAttr.IsRequired)
            {
                throw new ConfigurationNotFoundException(IICConfigType.Item, type.Name);
            }
            else
            {
                IICConfigItem ret = (IICConfigItem)Activator.CreateInstance(type);
                ret.SetDefaultValue();
                return(ret);
            }
        }
        internal RpcTransparentService(T serviceObj, string serviceUrl)
            : base(string.Empty)
        {
            Type intf = typeof(T);

            if (!intf.IsInterface)
            {
                throw new NotSupportedException();
            }

            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(intf);

            p_serviceName = serviceAttr.ServiceName;
            _serviceObj   = serviceObj;
            _serviceUrl   = serviceUrl;

            IICPerformanceCounterCategory category =
                new IICPerformanceCounterCategory("rpc:" + p_serviceName,
                                                  PerformanceCounterCategoryType.MultiInstance);

            foreach (MethodInfo method in intf.GetMethods())
            {
                string methodName = method.Name;


                DynamicMethod dm = new DynamicMethod("fun", typeof(object[]),
                                                     new[] { typeof(RpcServerContext) });

                RpcServiceMethod m = new RpcServiceMethod();
                m.RatePerSecond = category.CreateCounter(methodName + " /sec.",
                                                         PerformanceCounterType.RateOfCountsPerSecond32);
                m.TotalCount = category.CreateCounter(methodName + " Total.",
                                                      PerformanceCounterType.NumberOfItems32);
                m.TotalFailed = category.CreateCounter(methodName + " Failed.",
                                                       PerformanceCounterType.NumberOfItems32);
                m.Concurrent = category.CreateCounter(methodName + " Concurrent.",
                                                      PerformanceCounterType.NumberOfItems32);
                m.Method = method;

                RpcGetArgsHelper.RegisterMethod(p_serviceName, m);

                _methods.Add(methodName, m);
            }
            IICPerformanceCounterFactory.GetCounters(category);
        }
Esempio n. 9
0
        public static void RegisterService <T>(T service)
        {
            RpcServiceAttribute serviceAttr = AttributeHelper.GetAttribute <RpcServiceAttribute>(typeof(T));

            RegisterService <T>(serviceAttr.ServiceName, service);
        }