BaseApp.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.IO;
  2. using System.Linq;
  3. using Aitex.Common.Util;
  4. using OpenSEMI.ClientBase.UI;
  5. using OpenSEMI.ClientBase.Handlers;
  6. using log4net;
  7. using MECF.Framework.Common.Account.Extends;
  8. namespace OpenSEMI.ClientBase
  9. {
  10. public class BaseApp
  11. {
  12. public BaseApp()
  13. {
  14. this.UserMode = UserMode.None;
  15. this.Initialized = false;
  16. //load configuration files...
  17. this.Configure();
  18. }
  19. public void Initialize(bool force = false)
  20. {
  21. if (this.Initialized && !force)
  22. return;
  23. this.MenuLoader = new MenuLoader(Path.Combine(PathManager.GetCfgDir(), "Menu.xml"));
  24. this.MenuLoader.Load();
  25. this.MenuManager = new MenuManager();
  26. this.UserContext = new UserContext();
  27. this.UIHandler = new ClientBase.UI.UIHandler();
  28. this.UIHandler.Looper.Run();
  29. this.OnInitialize();
  30. this.Initialized = true;
  31. }
  32. public virtual void Dispose()
  33. {
  34. this.UIHandler.Looper.Terminate();
  35. }
  36. protected void Configure()
  37. {
  38. //config skin/language...
  39. this.OnConfiguration();
  40. //config log4net
  41. log4net.Config.XmlConfigurator.Configure();
  42. this.Log = log4net.LogManager.GetLogger("loginfo");
  43. this.SysEvent = log4net.LogManager.GetLogger("sysEvent");
  44. }
  45. protected virtual void OnInitialize() { }
  46. protected virtual void OnConfiguration() { }
  47. public void SetCurrentPage(PageID page)
  48. {
  49. //set page to get real data every 500 ms ...
  50. }
  51. public int GetPermission(string menuid)
  52. {
  53. int per = 1;
  54. if (this.UserContext != null)
  55. {
  56. string[] list = this.UserContext.Role.MenuPermission.Split(';');
  57. var result = from r in list
  58. where r.Split(',')[0] == menuid
  59. select r;
  60. if (result.Count() > 0)
  61. per = int.Parse(result.ToArray()[0].Split(',')[1]);
  62. }
  63. return per;
  64. }
  65. public static BaseApp Instance
  66. {
  67. get
  68. {
  69. return _instance;
  70. }
  71. set
  72. {
  73. _instance = value;
  74. }
  75. }
  76. public UserContext UserContext { get; private set; }
  77. public MenuManager MenuManager { get; private set; }
  78. public MenuLoader MenuLoader { get; private set; }
  79. public UserMode UserMode { get; set; }
  80. public UIHandler UIHandler { get; set; }
  81. public bool Initialized { get; private set; }
  82. public ILog Log { get; private set; }
  83. public ILog SysEvent { get; private set; }
  84. public StatesHandler StatesManager { get; protected set; }
  85. public WaferStatusHandler WaferStatusManager { get; protected set; }
  86. private static BaseApp _instance = null;
  87. public virtual void SwitchPage(string mainMenu, string subMenu, object parameter) { }
  88. }
  89. }