private void tsbAdd_Click(object sender, EventArgs e) { // 判断项目是否存在 if (string.IsNullOrWhiteSpace(Project.GetInstance().Name)) { MessageBox.Show("请先新建项目"); return; } // 初始化流程名称 string name = "流程1"; for (int i = 1; ; i++) { if (!TabProcesses.TabPages.ContainsKey("流程" + i)) { name = "流程" + i; break; } } // 新建流程页 ProcessTabPage tp = new ProcessTabPage(name); if (Project.GetInstance().MainProcess == null) { // 设置主流程 Project.GetInstance().MainProcess = Project.GetInstance()[name]; } // 将流程页添加到TabControl TabProcesses.TabPages.Add(tp); TabProcesses.SelectedTab = tp; }
private void Open(string fileName) { // 加载当前应用程序目录下的指定程序集 DirectoryInfo info = new DirectoryInfo(Application.StartupPath); FileInfo[] files = info.GetFiles("*Module.dll"); Dictionary <Type, Assembly> typeCollection = new Dictionary <Type, Assembly>(); foreach (var file in files) { Assembly a = Assembly.LoadFile(file.FullName); Type[] types = a.GetExportedTypes(); foreach (var type in types) { ModuleAttribute attribute = (ModuleAttribute)type.GetCustomAttribute(typeof(ModuleAttribute)); if (attribute != null) { typeCollection.Add(type, a); } } } // 从XML加载流程 XmlDocument doc = new XmlDocument(); doc.Load(fileName); XmlElement root = doc.DocumentElement; // 清理所有流程 TabProcesses.TabPages.Clear(); Project.GetInstance().Clear(); Project.GetInstance().Name = root.GetAttribute("name"); // 流程节点循环加载 foreach (XmlElement page in root.ChildNodes) { // 增加流程 ProcessTabPage tp = new ProcessTabPage(page.GetAttribute("name") /*, VisualProject*/); TabProcesses.TabPages.Add(tp); // 模块节点循环加载 foreach (XmlElement unit in page.ChildNodes) { foreach (var type in typeCollection) { // 获取类型自定义特性 ModuleAttribute des = (ModuleAttribute)type.Key.GetCustomAttribute(typeof(ModuleAttribute)); if (unit.GetAttribute("name") == des.Name) { // 增加模块 ModuleBase module = (ModuleBase)type.Value.CreateInstance(type.Key.FullName); module.Owner = Project.GetInstance()[tp.Text]; module.Index = Convert.ToInt32(unit.GetAttribute("id")); module.Load(); ModuleControl mc = new ModuleControl(module); tp.AddModule(mc); } } } } // 设置主流程 Project.GetInstance().MainProcess = Project.GetInstance()[root.GetAttribute("main")]; TabProcesses.SelectTab(Project.GetInstance().MainProcess.Name); }