BaseApp.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System.IO;
  2. using System.Linq;
  3. using System.Reflection;
  4. using Aitex.Common.Util;
  5. using Caliburn.Micro;
  6. using MECF.Framework.Common.Account.Extends;
  7. namespace MECF.Framework.UI.Client.ClientBase
  8. {
  9. public class BaseApp
  10. {
  11. public UserContext UserContext { get; private set; }
  12. public MenuManager MenuManager { get; private set; }
  13. public MenuLoader MenuLoader { get; private set; }
  14. public UserMode UserMode { get; set; }
  15. public bool Initialized { get; private set; }
  16. public ModuleDataMonitor _dataMonitor;
  17. private static BaseApp _instance = null;
  18. public string MenuFilePathName { get; set; }
  19. public static BaseApp Instance
  20. {
  21. get
  22. {
  23. return _instance;
  24. }
  25. set
  26. {
  27. _instance = value;
  28. }
  29. }
  30. public BaseApp()
  31. {
  32. this.UserMode = UserMode.None;
  33. this.Initialized = false;
  34. this.Configure();
  35. }
  36. public void Initialize(bool force = false)
  37. {
  38. if (this.Initialized && !force)
  39. return;
  40. if (string.IsNullOrEmpty(MenuFilePathName))
  41. MenuFilePathName = Path.Combine(PathManager.GetCfgDir(), "Menu.xml");
  42. this.MenuLoader = new MenuLoader(MenuFilePathName);
  43. this.MenuLoader.Load();
  44. this.MenuManager = new MenuManager();
  45. this.UserContext = new UserContext();
  46. var file = string.Format("{0}MECF.Framework.UI.Client.dll", System.AppDomain.CurrentDomain.BaseDirectory);
  47. if (File.Exists(file))
  48. {
  49. Assembly assembly = Assembly.LoadFile(file);
  50. AssemblySource.Instance.Add(assembly);
  51. }
  52. this.OnInitialize();
  53. //must be called after specific project initialized
  54. _dataMonitor = new ModuleDataMonitor();
  55. this.Initialized = true;
  56. }
  57. public virtual void Dispose()
  58. {
  59. }
  60. protected void Configure()
  61. {
  62. //config skin/language...
  63. this.OnConfiguration();
  64. }
  65. protected virtual void OnInitialize() { }
  66. protected virtual void OnConfiguration() { }
  67. public virtual void SwitchPage(string mainMenu, string subMenu, object parameter) { }
  68. public int GetPermission(string menuid)
  69. {
  70. int per = 1;
  71. if (this.UserContext != null)
  72. {
  73. string[] list = this.UserContext.Role.MenuPermission.Split(';');
  74. var result = from r in list
  75. where r.Split(',')[0] == menuid
  76. select r;
  77. if (result.Count() > 0)
  78. per = int.Parse(result.ToArray()[0].Split(',')[1]);
  79. }
  80. return per;
  81. }
  82. }
  83. }