• JohnSon:ModuleManager动态加载模块


    [Export(typeof(VMShell))]
        [PartCreationPolicy(CreationPolicy.Shared)]
        public class VMShell : NotificationObject
        {
            IEventAggregator eventAggregator;
            Lazy<IModuleManager> lazyModuleManager;
            IModuleManager moduleManager = null;

            [ImportingConstructor]
            public VMShell(IEventAggregator agg, Lazy<IModuleManager> module)
            {
                eventAggregator = agg;
                lazyModuleManager = module;

                ShowLoginView();
            }

            private void ShowLoginView()
            {
                //初始化ModuleManager,加载事件等
                InitLoginManager();
                //根据模块名取得模块信息
                ModuleCatalog moduleCatalog = ServiceLocator.Current.GetInstance<ModuleCatalog>();
                if (moduleCatalog == null) return;
                ModuleInfo moduleInfo = moduleCatalog.Modules.FirstOrDefault(p => p.ModuleName == "ModuleLogin");
                if (moduleInfo == null) return;
                if (moduleInfo.State == ModuleState.Initialized)
                {
                    //显示当前主视图
                    ShowLogin();
                }
                else if (moduleManager != null)
                {
                    moduleManager.LoadModule("ModuleLogin");
                }
                string status = moduleInfo.State.ToString();
            }

            private void InitLoginManager()
            {
                if (!lazyModuleManager.IsValueCreated)
                {
                    moduleManager = lazyModuleManager.Value;
                    moduleManager.ModuleDownloadProgressChanged += new EventHandler<ModuleDownloadProgressChangedEventArgs>(LoginModuleProgressChanged);
                    moduleManager.LoadModuleCompleted += new EventHandler<LoadModuleCompletedEventArgs>(LoadModuleCompleted);
                }
            }

            void LoginModuleProgressChanged(object sender, ModuleDownloadProgressChangedEventArgs e)
            {
                //ModuleLoadedPercent = e.ProgressPercentage;
                //if (ModuleLoadedPercent > 0 && ModuleLoadedPercent < 100)
                //    IsBusy = true;
                //else
                //    IsBusy = false;
            }

            void LoadModuleCompleted(object sender, LoadModuleCompletedEventArgs e)
            {
                if (e.Error == null)
                {
                    ShowLogin();
                }
            }

            private void ShowLogin()
            {
                UserControl loginView = ServiceLocator.Current.GetInstance<UserControl>("ViewLogin");
                if (loginView != null)
                {
                    eventAggregator.GetEvent<ModuleEvent>().Publish(loginView);
                }
            }
        }

  • 相关阅读:
    中层人才轮岗,张勇宣布阿里新一轮组织架构调整
    公司倒闭 1 年了,而我当年的项目上了 GitHub 热榜
    为什么别人的行业都那么让人羡慕
    ClickHouse 高级(五)数据一致性(重点)
    ClickHouse 高级(四)优化(4)查询优化
    ClickHouse 高级(二)优化(2)建表优化
    ClickHouse 高级(一)优化(1)Explain 查看执行计划
    ClickHouse基础(八)使用基础(5)ClickHouse 的安装(win10)
    【简单的原创】div简单轮换显示
    BZOJ 5494: [2019省队联测]春节十二响 (左偏树 可并堆)
  • 原文地址:https://www.cnblogs.com/iwangjun/p/2385812.html
Copyright © 2020-2023  润新知