using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Reflection; namespace ButcherFactory.BO.Utils { public static class FormUtil { public static Form CreateFrom() { //RedirectRole(); var dll = Path.Combine(Directory.GetCurrentDirectory(), "ButcherFactory.Form.dll"); if (!File.Exists(dll)) throw new Exception("缺少必要的程序集文件 ButcherFactory.Form.dll"); var formType = typeof(IWithRoleForm); Form form = null; foreach (var type in Assembly.LoadFile(dll).GetTypes()) { if (formType.IsAssignableFrom(type)) { var instance = (IWithRoleForm)Activator.CreateInstance(type); foreach (var item in instance.RoleName) { if (AppContext.Worker.RoleList.Contains(item)) return instance.Generate(); } } } return form; } private static void RedirectRole() { var list = XmlUtil.DeserializeFromFile>("Config\\RoleRedirectConfig.xml"); var arr = AppContext.Worker.RoleList.ToList(); foreach (var item in list) { var idx = arr.IndexOf(item.Role); if (idx >= 0) arr[idx] = item.RedirectRole; } AppContext.Worker.Role = string.Join(",", arr); } } public class RoleRedirectConfig { public short Role { get; set; } public short RedirectRole { get; set; } } public interface IWithRoleForm { List RoleName { get; } Form Generate(); } }