/// <summary> /// 创建 /// </summary> /// <param name="_planConfig"></param> /// <param name="savePath"></param> public void Create(PlanConfig _planConfig, string savePath) { FileStream fs = null; try { fs = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); var serializer = new XmlSerializer(_planConfig.GetType()); serializer.Serialize(fs, _planConfig); } catch { throw new Exception("文件XML序列化失败,创建PlanConfig失败"); } finally { if (fs != null) { fs.Close(); } } }
public void Initialize(string configPath) { FileStream fs = null; try { fs = new FileStream(configPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var serializer = new XmlSerializer(typeof(PlanConfig)); PlanConfig _planConfig = (PlanConfig)serializer.Deserialize(fs); this._taskThreads.Clear(); foreach (var _planGroup in _planConfig.planGroupList) { var taskThread = new TaskThread(_planGroup.interval); this._taskThreads.Add(taskThread); foreach (var _plan in _planGroup.planList) { var taskType = Type.GetType(_plan.PlanType); if (taskType != null) { var task = new Task(taskType, _plan); taskThread.AddTask(task); } } } //var taskType = Type.GetType(attribute.Value); } catch { throw new Exception("文件XML反序列化失败"); } finally { if (fs != null) { fs.Close(); } } }