public bool Start(string appName, string appFilePath) { try { Preconditions.CheckNotBlankOrWhiteSpace(appName, "appName"); _appName = appName; AppStrapLog.Info(_appName, "Start"); var assembly = Assembly.LoadFile(appFilePath); var bootType = assembly.GetTypes().First(i => i.GetInterface(typeof(IAppStrapBoot).FullName) == typeof(IAppStrapBoot)); _bootInstance = (IAppStrapBoot)Activator.CreateInstance(bootType); if (_bootInstance != null) { _bootInstance.Start(); } AppStrapLog.Info(_appName, "Start succeed"); return(true); } catch (Exception ex) { AppStrapLog.Error(_appName, ex.GetBaseException().Message); AppStrapLog.Info(_appName, "Start failed"); return(false); } }
public AppDomain GetAppDomain(Evidence securityInfo = null, AppDomainSetup info = null) { if (_appDomain != null) { AppStrapLog.Info(AppName, $"AppDomain:{AppName} already exists"); return(_appDomain); } AppStrapLog.Info(AppName, "Create AppDomain"); if (info == null) { info = new AppDomainSetup(); } info.ApplicationBase = Path.GetDirectoryName(AppFilePath); if (!string.IsNullOrWhiteSpace(ConfigFile)) { info.ConfigurationFile = ConfigFile; AppStrapLog.Info(AppName, "Load Config File"); } _appDomain = AppDomain.CreateDomain(AppName, securityInfo, info); _appDomain.DoCallBack(() => { AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => { AppStrapLog.Error(AppName, "UnhandledException"); AppDomain.Unload(AppDomain.CurrentDomain); }; }); AppStrapLog.Info(AppName, "Create AppDomain succeed"); return(_appDomain); }
public bool Stop() { try { AppStrapLog.Info(_appName, "Stop"); if (_bootInstance != null) { _bootInstance.Stop(); } AppStrapLog.Info(_appName, "Stop succeed"); return(true); } catch (Exception ex) { AppStrapLog.Error(_appName, ex.GetBaseException().Message); AppStrapLog.Info(_appName, "Stop failed"); return(false); } }