using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Reflection; namespace Mesnac.Equips { public interface DataChanged { void DoSave(object sender, Mesnac.Equips.ReadEventArgs e); } public abstract class DataChanging { public DataChanging(DataChanged _changed) { this.DataChanged = _changed; } public abstract void DoRead(object sender, Mesnac.Equips.ReadEventArgs e); protected DataChanged DataChanged { get; set; } protected string DataChangingKey { get; set; } } public class DataChange { public DataChange() { Dictionary dicDataChanging = ReadDataChangingXml(); equipOnRead(dicDataChanging); } #region 数据验证层 //绑定变化 private void equipOnRead(DataChanging changing) { foreach (BaseEquip equip in Mesnac.Equips.Factory.Instance.AllEquips.Values) { equip.EquipReadData += changing.DoRead; } } private void equipOnRead(Dictionary dicDataChanging) { foreach (DataChanging changing in dicDataChanging.Values) { equipOnRead(changing); } } //解析配置文件 private Dictionary ReadDataChangingXml() { Dictionary dicDataChanging = new Dictionary(); return dicDataChanging; } private DataChanging getDataChanging(string fileName, string className, string key) { DataChanged changed = getDataChanged(key); if (changed == null) { return null; } if (!File.Exists(fileName)) { return null; } Assembly ass = Assembly.LoadFile(fileName); if (ass == null) { return null; } Type type = ass.GetType(className); if (type == null) { return null; } DataChanging changing = (DataChanging)Activator.CreateInstance(type, changed); return changing; } #endregion #region 数据保存层 private DataChanged getDataChanging(string fileName, string className) { if (!File.Exists(fileName)) { return null; } Assembly ass = Assembly.LoadFile(fileName); if (ass == null) { return null; } Type type = ass.GetType(className); if (type == null) { return null; } DataChanged changed = (DataChanged)Activator.CreateInstance(type); return changed; } private DataChanged getDataChanged(string key) { string fileName = string.Empty; string className = string.Empty; return getDataChanging(fileName, className); } #endregion } }