using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using RunRules;
using System.Reflection;
using System.IO;
namespace RunRules
{
public class MonitorFactory
{
private static MonitorFactory _instance = new MonitorFactory();
public static MonitorFactory Instance
{
get { return _instance; }
}
public IQSDB MakeRules(string Name)
{
IQSDB MyRule= null;
try
{
Assembly tempAssembly;
tempAssembly = Assembly.Load("DailyRun");
Type type = tempAssembly.GetType(Name, true);
MyRule = (IQSDB)Activator.CreateInstance(type);
}
catch (TypeLoadException e)
{
Console.WriteLine("Wrong Rule type,exception caught - {0}", e.Message);
}
return MyRule;
}
}
class Program
{
List<Rules> list = new List<Rules>();
static void Main(string[] args)
{
Type[] typePublic = null; Type typeIQSDB = null;
string exeDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //得到运行目录
string[] dellPaths = Directory.GetFiles(exeDirPath, "*.dll");//得到所有的DLL
for (int i = 0; i < dellPaths.Length; i++)
{
Assembly asm = Assembly.LoadFile(dellPaths[i]);
typePublic = asm.GetExportedTypes();//得到所有的public方法
typeIQSDB = typeof(IQSDB);//接口的类型
for (int j = 0; j < typePublic.Length; j++)
{
if (typeIQSDB.IsAssignableFrom(typePublic[j]) && !typePublic[j].IsAbstract)
{
IQSDB obj = (IQSDB)Activator.CreateInstance(typePublic[j]);
obj.RunCheck();
}
// IQSDB obj = MonitorFactory.Instance.MakeRules("DailyRun.RunDailyMonitor");
// obj.RunCheck();
}
Console.ReadKey();
}
}
void Initil()
{
Rules rule1 = new Rules(); rule1.RuleName = "QSDB_APAC"; rule1.deadLine = "21:00"; rule1.dateAdd = 0; list.Add(rule1);
Rules rule2 = new Rules(); rule2.RuleName = "QSDB_EMEA"; rule2.deadLine = "23:00"; rule2.dateAdd = 0; list.Add(rule2);
Rules rule3 = new Rules(); rule3.RuleName = "QSDB_NAM"; rule3.deadLine = "01:00"; rule3.dateAdd = -1; list.Add(rule3);
Rules rule4 = new Rules(); rule4.RuleName = "DCCHECK"; rule4.deadLine = "02:00"; rule4.dateAdd = -1; list.Add(rule4);
Rules rule5 = new Rules(); rule5.RuleName = "QSDB_OCEAN"; rule5.deadLine = "04:00"; rule5.dateAdd = -1; list.Add(rule5);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using RunRules;
using System.Reflection;
using System.IO;
namespace RunRules
{
public class MonitorFactory
{
private static MonitorFactory _instance = new MonitorFactory();
public static MonitorFactory Instance
{
get { return _instance; }
}
public IQSDB MakeRules(string Name)
{
IQSDB MyRule= null;
try
{
Assembly tempAssembly;
tempAssembly = Assembly.Load("DailyRun");
Type type = tempAssembly.GetType(Name, true);
MyRule = (IQSDB)Activator.CreateInstance(type);
}
catch (TypeLoadException e)
{
Console.WriteLine("Wrong Rule type,exception caught - {0}", e.Message);
}
return MyRule;
}
}
class Program
{
List<Rules> list = new List<Rules>();
static void Main(string[] args)
{
Type[] typePublic = null; Type typeIQSDB = null;
string exeDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //得到运行目录
string[] dellPaths = Directory.GetFiles(exeDirPath, "*.dll");//得到所有的DLL
for (int i = 0; i < dellPaths.Length; i++)
{
Assembly asm = Assembly.LoadFile(dellPaths[i]);
typePublic = asm.GetExportedTypes();//得到所有的public方法
typeIQSDB = typeof(IQSDB);//接口的类型
for (int j = 0; j < typePublic.Length; j++)
{
if (typeIQSDB.IsAssignableFrom(typePublic[j]) && !typePublic[j].IsAbstract)
{
IQSDB obj = (IQSDB)Activator.CreateInstance(typePublic[j]);
obj.RunCheck();
}
// IQSDB obj = MonitorFactory.Instance.MakeRules("DailyRun.RunDailyMonitor");
// obj.RunCheck();
}
Console.ReadKey();
}
}
void Initil()
{
Rules rule1 = new Rules(); rule1.RuleName = "QSDB_APAC"; rule1.deadLine = "21:00"; rule1.dateAdd = 0; list.Add(rule1);
Rules rule2 = new Rules(); rule2.RuleName = "QSDB_EMEA"; rule2.deadLine = "23:00"; rule2.dateAdd = 0; list.Add(rule2);
Rules rule3 = new Rules(); rule3.RuleName = "QSDB_NAM"; rule3.deadLine = "01:00"; rule3.dateAdd = -1; list.Add(rule3);
Rules rule4 = new Rules(); rule4.RuleName = "DCCHECK"; rule4.deadLine = "02:00"; rule4.dateAdd = -1; list.Add(rule4);
Rules rule5 = new Rules(); rule5.RuleName = "QSDB_OCEAN"; rule5.deadLine = "04:00"; rule5.dateAdd = -1; list.Add(rule5);
}
}
}