Use this class store information for each metric. The metricInfo class must have get accessors so that the internal serializer will use the data.
        /// <summary>
        /// Return the metrics and their descriptions for each and the parameters they need
        /// </summary>
        /// <returns></returns>
        public List<MetricInfo> GetMetricsDescriptions()
        {
            //Dictionary<string,string> imetricTypes = new Dictionary<string,string>();
            List<MetricInfo> imetricTypes = new List<MetricInfo>();

            //use the assembly object to get to the types that inherits IMETRIC
            Assembly webAnalytics = Assembly.Load(typeof(IMetric).Assembly.FullName); //<== successful

            //find the types that are instanceof IMetric
            IMetric metric;
            MetricInfo info;
            foreach (TypeInfo typeInfo in webAnalytics.DefinedTypes)
            {
                if (typeof(IMetric).IsAssignableFrom(typeInfo) && !typeInfo.IsInterface)
                {
                    info = new MetricInfo();
                    //to get a description of the metric, we need to use activator to create an instance of that type and use the GetMetricDescription
                    try
                    {
                        metric = (IMetric)Activator.CreateInstance(typeInfo);
                        info.Name = metric.MetricName;
                        info.Description = metric.GetMetricDescription;
                        info.ClassName = typeInfo.FullName.Replace("WebAnalytics.Model.Metrics.", String.Empty);
                        Trace.WriteLine(info.ClassName);
                        info.Parameters = metric.GetParameters();
                        imetricTypes.Add(info);
                    }
                    catch (Exception)
                    {
                        Trace.WriteLine("error with: " + typeInfo.ToString());
                    }
                }
            }
            return imetricTypes;
        }
示例#2
0
        /// <summary>
        /// Return the metrics and their descriptions for each and the parameters they need
        /// </summary>
        /// <returns></returns>
        public List <MetricInfo> GetMetricsDescriptions()
        {
            //Dictionary<string,string> imetricTypes = new Dictionary<string,string>();
            List <MetricInfo> imetricTypes = new List <MetricInfo>();

            //use the assembly object to get to the types that inherits IMETRIC
            Assembly webAnalytics = Assembly.Load(typeof(IMetric).Assembly.FullName); //<== successful

            //find the types that are instanceof IMetric
            IMetric    metric;
            MetricInfo info;

            foreach (TypeInfo typeInfo in webAnalytics.DefinedTypes)
            {
                if (typeof(IMetric).IsAssignableFrom(typeInfo) && !typeInfo.IsInterface)
                {
                    info = new MetricInfo();
                    //to get a description of the metric, we need to use activator to create an instance of that type and use the GetMetricDescription
                    try
                    {
                        metric           = (IMetric)Activator.CreateInstance(typeInfo);
                        info.Name        = metric.MetricName;
                        info.Description = metric.GetMetricDescription;
                        info.ClassName   = typeInfo.FullName.Replace("WebAnalytics.Model.Metrics.", String.Empty);
                        Trace.WriteLine(info.ClassName);
                        info.Parameters = metric.GetParameters();
                        imetricTypes.Add(info);
                    }
                    catch (Exception)
                    {
                        Trace.WriteLine("error with: " + typeInfo.ToString());
                    }
                }
            }
            return(imetricTypes);
        }