public void Load(IServiceContext ctx, ModuleUpdateAction action) { if (ctx == null) { throw new ArgumentNullException("svcCtx"); } LoggerProvider.EnvironmentLogger.Info(() => string.Format("Loading module: [{0}]", this.Name)); if (this.Name == "core") { #if DEBUG //调试模式不捕获异常,以便于调试 this.LoadCoreModule(ctx, action); #else try { this.LoadCoreModule(ctx, action); } catch (Exception ex) { var msg = "Failed to load core module"; LoggerProvider.EnvironmentLogger.FatalException(msg, ex); throw new Exceptions.InitializationException(msg, ex); } #endif } else { this.LoadAdditionalModule(ctx, action); } }
private void LoadCoreModule(IServiceContext tc, ModuleUpdateAction action) { Debug.Assert(tc != null); var a = typeof(SlipStream.Core.ModuleModel).Assembly; var resources = this.GetResourcesInAssembly(a); this.InitializeResources(tc, resources, action); //加载核心模块数据 if (action == ModuleUpdateAction.ToInstall) { LoggerProvider.EnvironmentLogger.Info(() => "Importing data for the Core Module..."); var importer = new Model.XmlDataImporter(tc, this.Name); foreach (var resPath in s_coreInitDataFiles) { using (var resStream = a.GetManifestResourceStream(resPath)) { LoggerProvider.EnvironmentLogger.Info(() => "Importing data file: [" + resPath + "]"); importer.Import(resStream); resStream.Close(); } } } }
private void LoadAdditionalModule(IServiceContext ctx, ModuleUpdateAction action) { Debug.Assert(ctx != null); LoggerProvider.EnvironmentLogger.Info(() => "Loading precompiled assemblies..."); var resources = new List <IResource>(); if (this.Dlls != null) { resources.AddRange(this.LoadStaticAssemblies()); } /* FIXME dynamic load * if (!string.IsNullOrEmpty(this.Path)) * { * resources.AddRange(this.LoadDynamicAssembly()); * } */ this.InitializeResources(ctx, resources, action); this.LoadModuleData(ctx, action); LoggerProvider.EnvironmentLogger.Info(() => string.Format("Module [{0}] has been loaded.", this.Name)); }
private void LoadModuleData(IServiceContext scope, ModuleUpdateAction action) { Debug.Assert(scope != null); LoggerProvider.EnvironmentLogger.Info(() => "Importing data..."); if (action == ModuleUpdateAction.ToInstall && this.InitFiles != null && this.InitFiles.Length > 0) { LoggerProvider.EnvironmentLogger.Info(() => "Importing data for installation..."); var files = this.InitFiles; this.ImportDataFiles(scope, files); } if (action == ModuleUpdateAction.ToUpgrade && this.UpgradeFiles != null && this.UpgradeFiles.Length > 0) { LoggerProvider.EnvironmentLogger.Info(() => "Importing data for upgrade..."); var files = this.UpgradeFiles; this.ImportDataFiles(scope, files); } }
private void InitializeResources(IServiceContext tc, IEnumerable <IResource> resources, ModuleUpdateAction action) { //注册并初始化所有资源 var standaloneResources = new List <IResource>(); foreach (var r in resources) { var merged = tc.Resources.RegisterResource(r); if (!merged) { standaloneResources.Add(r); } } ResourceDependencySort(standaloneResources); foreach (var r in standaloneResources) { r.Initialize(action != ModuleUpdateAction.NoAction); } }