static void Main(string[] args) { string[] runType = args; if (args == null || args.Length < 1) { string paraStr = Console.ReadLine(); runType = paraStr.Split(' '); } if (runType[0].Contains("1")) { WorkItemManager.SetAllStop(1); Console.Write("爬取服务器暂停成功"); return; } else if (runType[0].Contains("0")) { WorkItemManager.SetAllStop(0); Console.Write("爬取服务器启动成功"); return; } work: if (!WorkItemManager.CheckPassSpider())//****检查数据库是否有维护程序在执行******// { System.Threading.Thread.Sleep(60000); goto work; } if (!runType[0].Contains("IP代理")) { #region (设置日志名称) Dictionary <string, List <string> > dic = new Dictionary <string, List <string> >(); //将参数添加到字典,用于生成日志文件名 foreach (string str in runType) { string strIndex1 = str.Split('.')[0]; string strIndex2 = str.Split('.')[1]; List <string> strList = new List <string>(); if (!dic.ContainsKey(strIndex1)) { dic.Add(strIndex1, new List <string>()); } strList = dic[strIndex1]; strList.Add(strIndex2); dic[strIndex1] = strList; } StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, List <string> > kvp in dic) { string key = kvp.Key; List <string> list = kvp.Value; sb.Append(key).Append("_"); for (int i = 0; i < list.Count; i++) { string str = list[i]; if (i < list.Count - 1) { sb.Append(str).Append("."); } else { sb.Append(str).Append(";"); } } } InitLogger("(" + sb.ToString() + ")"); #endregion foreach (string str in runType) { //运行操作 INewDataRum rum = null; string directory = GetConfigDire(); string dllFill = directory + "\\FxtSpider.RunSource.dll"; Type type = Assembly.LoadFile(dllFill).GetType("FxtSpider.RunSource." + str); if (type != null) { rum = Activator.CreateInstance(type) as INewDataRum; } else { type = Assembly.LoadFile(dllFill).GetType("FxtSpider.RunSource." + str.Split('.')[0] + ".其他城市"); rum = Activator.CreateInstance(type) as INewDataRum; rum.CityName = str.Split('.')[1]; } rum.start(); } } else { #region (设置日志名称) Dictionary <string, List <string> > dic = new Dictionary <string, List <string> >(); StringBuilder sb = new StringBuilder(); //将参数添加到字典,用于生成日志文件名 foreach (string str in runType) { sb.Append(str).Append(";"); } InitLogger("(" + sb.ToString() + ")"); #endregion foreach (string str in runType) { string directory = GetConfigDire(); string dllFill = directory + "\\FxtSpider.RunSource.dll"; string className = str.Split('.')[0] + "." + str.Split('.')[1]; object objClass = Assembly.LoadFile(dllFill).CreateInstance("FxtSpider.RunSource." + className); if (objClass != null) { MethodInfo method = objClass.GetType().GetMethod(str.Split('.')[2]); ArrayList al = new ArrayList(); al.Add(method); al.Add(objClass); Thread m_thread = new Thread(new ParameterizedThreadStart(ExecIpSpider)); m_thread.Start(al); } } } }