Пример #1
0
        /// <summary>
        /// 根据类型描述得到类型对象
        /// </summary>
        /// <param name="typeDescription">完整类型描述,应该是Namespace.ClassName, AssemblyName</param>
        /// <returns>类型对象</returns>
        public static Type GetTypeInfo(string typeDescription)
        {
            ExceptionHelper.CheckStringIsNullOrEmpty(typeDescription, "typeDescription");

            Type result = Type.GetType(typeDescription);

            if (result == null)
            {
                TypeInfo ti = GenerateTypeInfo(typeDescription);

                AssemblyName aName = new AssemblyName(ti.AssemblyName);

                AssemblyMappingConfigurationElement element = AssemblyMappingSettings.GetConfig().Mapping[aName.Name];

                ExceptionHelper.TrueThrow <TypeLoadException>(element == null, "不能找到类型{0}", typeDescription);

                ti.AssemblyName = element.MapTo;

                result = Type.GetType(ti.ToString());

                ExceptionHelper.FalseThrow <TypeLoadException>(result != null, "不能得到类型信息{0}", ti.ToString());
            }

            return(result);
        }
Пример #2
0
        private void InitPerformanceCounter(PerformanceCounterInitData data)
        {
            PerformanceCounter pc;

            ExceptionHelper.FalseThrow <ArgumentNullException>(data != null, "data");
            ExceptionHelper.CheckStringIsNullOrEmpty(data.CategoryName, "CategoryName");
            ExceptionHelper.CheckStringIsNullOrEmpty(data.CounterName, "CounterName");

            try
            {
                if (string.IsNullOrEmpty(data.MachineName))
                {
                    pc = new PerformanceCounter(data.CategoryName, data.CounterName, data.InstanceName, data.Readonly);
                }
                else
                {
                    pc = new PerformanceCounter(data.CategoryName, data.CounterName, data.InstanceName, data.MachineName);
                }

                this.counter = pc;
            }
            catch (System.Exception)
            {
            }
        }
        /// <summary>
        /// 得到指定名称的监控数据
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static MonitorData GetMonitor(string name)
        {
            ExceptionHelper.CheckStringIsNullOrEmpty(name, "name");

            MonitorData md = null;

            ExceptionHelper.FalseThrow(StopWatchContextCache.Instance.TryGetValue(name, out md),
                                       "不能找到名称为{0}的MonitorData");

            return(md);
        }
Пример #4
0
        /// <summary>
        /// 从资源中得到流
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static Stream GetResourceStream(this Assembly assembly, string path)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(assembly != null, "assembly");
            ExceptionHelper.CheckStringIsNullOrEmpty(path, "path");

            Stream stm = assembly.GetManifestResourceStream(path);

            ExceptionHelper.FalseThrow(stm != null, "不能在Assembly:{0}中找到资源{1}", assembly.FullName, path);

            return(stm);
        }
Пример #5
0
        /// <summary>
        /// 把已序列化为字符串类型的对象反序列化为指定的类型
        /// </summary>
        /// <param name="serializedGraph">已序列化为字符串类型的对象</param>
        /// <param name="formatterType">消息格式编码类型(Soap或Binary型)</param>
        /// <param name="binder"></param>
        /// <returns>串行化转化结果</returns>
        /// <remarks>调用BinaryFormatter或SoapFormatter的Deserialize方法实现主要转换过程。</remarks>
        public static object DeserializeStringToObject(this string serializedGraph, SerializationFormatterType formatterType, SerializationBinder binder)
        {
            ExceptionHelper.CheckStringIsNullOrEmpty(serializedGraph, "serializedGraph");

            Byte[] arrGraph = Convert.FromBase64String(serializedGraph);
            using (MemoryStream memoryStream = new MemoryStream(arrGraph))
            {
                IRemotingFormatter formatter = GetFormatter(formatterType);
                formatter.Binder = binder;

                return(formatter.Deserialize(memoryStream));
            }
        }
        /// <summary>
        /// 开始执行计数
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static MonitorData StartMonitor(string name)
        {
            ExceptionHelper.CheckStringIsNullOrEmpty(name, "name");

            ExceptionHelper.TrueThrow(StopWatchContextCache.Instance.ContainsKey(name),
                                      "已经启动了名称为{0}的MonitorData", name);

            MonitorData md = new MonitorData();

            StopWatchContextCache.Instance.Add(name, md);

            md.Stopwatch.Start();

            return(md);
        }
 /// <summary>
 /// 构造方法,通过类型描述构造
 /// </summary>
 /// <param name="typeDesp">类型描述</param>
 public XmlObjectSubClassTypeAttribute(string typeDesp)
 {
     ExceptionHelper.CheckStringIsNullOrEmpty(typeDesp, "typeDesp");
     this.typeDescription = typeDesp;
 }