Пример #1
0
        public static BaseMonitoredObj CreateMonitoredObj(MonitoredObjConfig config)
        {
            switch (config.Type)
            {
            case "MonitoredWebSite":
                return(CreateMonitoredIISApp(config));

            case "MonitoredService":
                return(CreateMonitoredService(config));

            case "MonitoredSchTaskBat":
                return(CreateMonitoredSchTask(config));

            default:
                break;
            }
            //扩展的自定义类
            if (config.Type.StartsWith("CustomMonitoredObj"))
            {
                return(CreateCustomMonitoredObj(config));
            }
            else
            {
                throw new Exception(string.Format("未知的监视类型: {0}", config.Type));
            }
        }
Пример #2
0
        private static BaseMonitoredObj CreateMonitoredSchTask(MonitoredObjConfig config)
        {
            var monitoredObj = new MonitoredSchTaskBat
            {
                Name        = config.Name,
                Desc        = config.Desc,
                Remote      = config.Remote,
                HasLog      = false,
                ProcessFile = config.Property1
            };

            return(monitoredObj);
        }
Пример #3
0
        private static BaseMonitoredObj CreateMonitoredService(MonitoredObjConfig config)
        {
            var monitoredObj = new MonitoredService
            {
                Name        = config.Name,
                Desc        = config.Desc,
                Remote      = config.Remote,
                Watched     = config.Watched,
                HasLog      = false,
                MachineName = config.Property1
            };

            return(monitoredObj);
        }
Пример #4
0
        private static BaseMonitoredObj CreateMonitoredIISApp(MonitoredObjConfig config)
        {
            var monitoredObj = new MonitoredIISApp(new MonitoredIISPool(new MonitoredIIS())
            {
                Name = config.Property1
            })
            {
                Name    = config.Name,
                Desc    = config.Desc,
                Remote  = config.Remote,
                Watched = config.Watched,
                HasLog  = false,
                Url     = config.Property2
            };

            return(monitoredObj);
        }
Пример #5
0
        private static BaseMonitoredObj CreateCustomMonitoredObj(MonitoredObjConfig config)
        {
            var typeName     = string.Format("{0}.{1}", "HYMonitors", config.Type);
            var type         = Assembly.GetExecutingAssembly().GetType(typeName);
            var monitoredObj = Activator.CreateInstance(type);

            #region set Name
            var nameProp = type.GetProperty("Name");
            nameProp.SetValue(monitoredObj, config.Name, null);
            #endregion

            #region set Desc
            var descProp = type.GetProperty("Desc");
            descProp.SetValue(monitoredObj, config.Desc, null);
            #endregion

            return(monitoredObj as BaseMonitoredObj);
        }