zoukankan      html  css  js  c++  java
  • 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);
                }
            }
        }

  • 相关阅读:
    系统tabbar出现两个tabbar的问题解决方案。
    iOS 开发苹果由http改为https 之后,如果服务器不做相应的修改,那么客户端需要做点更改
    UIAlertController的一些简单实用方法
    ios开发同一个lab显示不同的颜色
    ios开发同一个版本多次提交不想改变版本号的解决方法
    iOS开发textfield的一些方法汇总
    C#笔记
    Shader之性能优化
    Shader之ShaderUI使用方法
    Shader Example
  • 原文地址:https://www.cnblogs.com/iwangjun/p/2385812.html
Copyright © 2011-2022 走看看