private static void StartShreds(ShredStartupInfoList shredStartupInfoList) { if (null != shredStartupInfoList) { // create the data structure that will hold the shreds and their thread, etc. related objects foreach (ShredStartupInfo shredStartupInfo in shredStartupInfoList) { if (null != shredStartupInfo) { // clone the shredStartupInfo structure into the current AppDomain, otherwise, once the StagingDomain // has been unloaded, the shredStartupInfo structure will be destroyed ShredStartupInfo newShredStartupInfo = new ShredStartupInfo(shredStartupInfo.AssemblyPath, shredStartupInfo.ShredName, shredStartupInfo.ShredTypeName); // create the controller that will allow us to start and stop the shred ShredController shredController = new ShredController(newShredStartupInfo); _shredInfoList.Add(shredController); } } } foreach (ShredController shredController in _shredInfoList) { shredController.Start(); } }
/// <summary> /// Uses the ExtensionPoint type to scan the plugins folder for extensions. /// </summary> /// <returns> /// An enumerable collection that contains information on each extension that will help the loader /// load them into the AppDomain. If no extensions are found, null is returned.</returns> public ShredStartupInfoList ScanExtensions() { Platform.Log(LogLevel.Debug, this.GetType().ToString() + ":" + this.GetType().Name + " in AppDomain [" + AppDomain.CurrentDomain.FriendlyName + "]"); ShredStartupInfoList shredInfoList = new ShredStartupInfoList(); ShredExtensionPoint xp = new ShredExtensionPoint(); object[] shredObjects = xp.CreateExtensions(); foreach (object shredObject in shredObjects) { if (shredObject is IShred) { Uri assemblyPath = new Uri(shredObject.GetType().Assembly.CodeBase); shredInfoList.Add(new ShredStartupInfo(assemblyPath, (shredObject as IShred).GetDisplayName(), shredObject.GetType().FullName)); } } return(shredInfoList); }
/// <summary> /// Starts the ShredHost routine. /// </summary> /// <returns>true - if the ShredHost is currently running, false - if ShredHost is stopped.</returns> public static bool Start() { // install the unhandled exception event handler AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += MyUnhandledExceptionEventHandler; lock (_lockObject) { if (RunningState.Running == _runningState || RunningState.Transition == _runningState) { return(RunningState.Running == _runningState); } _runningState = RunningState.Transition; } Platform.Log(LogLevel.Info, "Starting up in AppDomain [" + AppDomain.CurrentDomain.FriendlyName + "]"); // the ShredList and shreds objects are proxy objects that actually exist // in the secondary AppDomain //AppDomain stagingDomain = AppDomain.CreateDomain("StagingDomain"); ExtensionScanner scanner = (ExtensionScanner)AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, "Macro.Server.ShredHost.ExtensionScanner"); ShredStartupInfoList shredStartupInfoList = null; try { shredStartupInfoList = scanner.ScanExtensions(); } catch (PluginException pluginException) { // There was a problem loading the plugins, including if there were no plugins found // This is an innocuous problem, and just means that there are no shreds to run Platform.Log(LogLevel.Warn, pluginException); } StartShreds(shredStartupInfoList); // all the shreds have been created, so we can dismantle the secondary domain that was used // for scanning for all Extensions that are shreds //AppDomain.Unload(stagingDomain); //try //{ // _sed = WcfHelper.StartHttpHost<ShredHostServiceType, IShredHost>( // "ShredHost", "Host program of multiple independent service-like sub-programs", ShredHostServiceSettings.Instance.ShredHostHttpPort); // _shredHostWCFInitialized = true; // string message = String.Format("The ShredHost WCF service has started on port {0}.", ShredHostServiceSettings.Instance.ShredHostHttpPort); // Platform.Log(LogLevel.Info, message); // Console.WriteLine(message); //} //catch(Exception e) //{ // Platform.Log(LogLevel.Error, e); // Console.WriteLine("The ShredHost WCF service has failed to start. Please check the log for more details."); //} lock (_lockObject) { _runningState = RunningState.Running; } return(RunningState.Running == _runningState); }