コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: AppStrapDomain.cs プロジェクト: jango2015/AppStrap
        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);
        }
コード例 #3
0
 public bool LoadAppStrap(string appName, string appFilePath)
 {
     try
     {
         Preconditions.CheckNotBlankOrWhiteSpace(appName, "AppName");
         Preconditions.CheckNotBlankOrWhiteSpace(appFilePath, "AppFilePath");
         var app = new AppStrap(appName, appFilePath);
         app.Start();
         return(true);
     }
     catch (Exception ex)
     {
         AppStrapLog.Error("AppStrap", ex.Message);
         return(false);
     }
 }
コード例 #4
0
 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);
     }
 }