Пример #1
0
        public static ABCBaseScreen GetABCScreen(STViewsInfo info, ViewMode mode)
        {
            if (info.STViewID == null || info.STViewID == Guid.Empty)
            {
                return(null);
            }

            info = (STViewsInfo) new STViewsController().GetObjectByID(info.STViewID);
            if (info == null)
            {
                return(null);
            }


            if (ABCScreenManager.Instance.CheckViewPermission(info.STViewID, ViewPermission.AllowView) == false)
            {
                ABCHelper.ABCMessageBox.Show("Bạn không đủ quyền hạn sử dụng tính năng này!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
            ABCBaseScreen screen = null;

            #region Get Type
            Type type = GetABCScreenType(info.STViewID);
            if (type == null)
            {
                if (info.STViewUseCode && String.IsNullOrWhiteSpace(info.STViewCode) == false)
                {
                    Assembly ass = ABCScreenFactory.CompileScreenSouceCode(info);
                    if (ass != null)
                    {
                        if (!String.IsNullOrWhiteSpace(info.ScreenName))
                        {
                            type = ass.GetType("ABCApp.Screens." + info.ScreenName + "Screen");
                        }

                        if (type == null && !String.IsNullOrWhiteSpace(info.STViewNo))
                        {
                            type = ass.GetType("ABCApp.Screens." + info.STViewNo + "Screen");
                        }

                        if (type != null)
                        {
                            screen = (ABCBaseScreen)ass.CreateInstance(type.FullName);
                        }
                        //   screen=(ABCBaseScreen)AppDomain.CurrentDomain.CreateInstanceAndUnwrap( type.Assembly.FullName ,type.FullName );
                        if (screen != null)
                        {
                            screen.LoadScreen(info, mode);
                            return(screen);
                        }
                    }
                }
            }

            if (type == null)
            {
                type = typeof(ABCBaseScreen);
            }
            #endregion

            if (type != null)
            {
                screen = (ABCBaseScreen)ABCDynamicInvoker.CreateInstanceObject(type);
            }

            if (screen != null)
            {
                screen.LoadScreen(info, mode);
            }

            return(screen);
        }
Пример #2
0
        public static void DebugScreen(String strLayoutXMLPath, String strSourceCode, String strViewNo, ViewMode mode)
        {
            ABCHelper.ABCWaitingDialog.Show("", ". . .");

            try
            {
                ABCBaseScreen screen = null;
                Type          type   = null;
                Assembly      ass    = null;

                #region Build
                if (String.IsNullOrWhiteSpace(strSourceCode) == false)
                {
                    ass = ABCScreenFactory.CompileScreenSouceCode(strSourceCode, strViewNo);
                    if (ass != null)
                    {
                        type = ass.GetType("ABCApp.Screens." + strViewNo + "Screen");
                    }
                }
                if (type == null)
                {
                    type = typeof(ABCBaseScreen);
                }
                #endregion

                Assembly         asBase     = null;
                ABCScreenManager globalBase = null;

                AppDomain domain = AppDomain.CreateDomain("DebugABCScreen", AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);
                try
                {
                    asBase     = domain.Load(typeof(ABCScreenManager).Assembly.FullName);
                    globalBase = (ABCScreenManager)domain.CreateInstanceAndUnwrap("ABCBaseScreen", "ABCScreen.ABCScreenManager");
                    globalBase.CallInitialize();

                    if (ass != null)
                    {
                        domain.Load(ass.GetName());
                    }

                    screen = (ABCBaseScreen)domain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
                    if (screen != null)
                    {
                        screen.LoadScreen(strLayoutXMLPath, mode);
                        ABCHelper.ABCWaitingDialog.Close();
                        screen.ShowDialog();
                    }
                }
                catch (Exception ex)
                {
                }

                screen     = null;
                globalBase = null;
                asBase     = null;

                AppDomain.Unload(domain);
                domain = null;
            }
            catch (Exception exx)
            { }

            GC.Collect();                  // collects all unused memory
            GC.WaitForPendingFinalizers(); // wait until GC has finished its work
            GC.Collect();
            ABCHelper.ABCWaitingDialog.Close();
        }