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);
                }
            }
        }

  • 相关阅读:
    maven打包时出现 Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project……
    maven+springmvc出现:java.sql.SQLException: Unknown system variable 'query_cache_size'
    IDEA复制某个类的包名路径
    IDEA中更改Tomcat服务器的URL
    IDEA去除自动检测bean是否存在
    ASM ClassReader failed to parse class file
    The content of element type "web-app" must match "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet- mapping*,session-config?,mime-map
    Could not open ServletContext resource [/WEB-INF/xxx-servlet.xml]
    Eclipse+maven 构建第一个简单的springmvc项目
    Eclispe中编辑xml配置文件时不会提示也不能自动调整格式
  • 原文地址:https://www.cnblogs.com/iwangjun/p/2385812.html
Copyright © 2011-2022 走看看