Ejemplo n.º 1
0
        /// <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 + "]");

            var shredInfoList = new ShredStartupInfoList();
			var xp = new ShredExtensionPoint();
            var shredObjects = xp.CreateExtensions();
            foreach (var shredObject in shredObjects)
            {
				var shredType = shredObject.GetType();
            	var asShred = shredObject as IShred;
				if (asShred == null)
				{
					Platform.Log(LogLevel.Debug, "Shred extension '{0}' does not implement IShred.", shredType.FullName);
					continue;
				}

            	var shredIsolation = shredType.GetCustomAttributes(typeof (ShredIsolationAttribute), true).OfType<ShredIsolationAttribute>().FirstOrDefault();
            	var shredIsolationLevel = shredIsolation == null ? ShredIsolationLevel.OwnAppDomain : shredIsolation.Level;

				var assemblyPath = new Uri(shredType.Assembly.CodeBase);
				var startupInfo = new ShredStartupInfo(assemblyPath, ((IShred)shredObject).GetDisplayName(), shredType.FullName, shredIsolationLevel);
                shredInfoList.Add(startupInfo);
            }

            return shredInfoList;
        }
Ejemplo n.º 2
0
        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
                        var newShredStartupInfo = new ShredStartupInfo(shredStartupInfo.AssemblyPath, shredStartupInfo.ShredName,
                                                                       shredStartupInfo.ShredTypeName, shredStartupInfo.IsolationLevel);

                        // create the controller that will allow us to start and stop the shred
                        var shredController = new ShredController(newShredStartupInfo);
                        _shredInfoList.Add(shredController);
                    }
                }
            }

            foreach (ShredController shredController in _shredInfoList)
            {
                shredController.Start();
            }
        }
Ejemplo n.º 3
0
        /// <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 + "]");

            var shredInfoList = new ShredStartupInfoList();
            var xp            = new ShredExtensionPoint();
            var shredObjects  = xp.CreateExtensions();

            foreach (var shredObject in shredObjects)
            {
                var shredType = shredObject.GetType();
                var asShred   = shredObject as IShred;
                if (asShred == null)
                {
                    Platform.Log(LogLevel.Debug, "Shred extension '{0}' does not implement IShred.", shredType.FullName);
                    continue;
                }

                var shredIsolation      = shredType.GetCustomAttributes(typeof(ShredIsolationAttribute), true).OfType <ShredIsolationAttribute>().FirstOrDefault();
                var shredIsolationLevel = shredIsolation == null ? ShredIsolationLevel.OwnAppDomain : shredIsolation.Level;

                if (shredIsolationLevel != ShredIsolationLevel.None)
                {
                    Platform.Log(LogLevel.Info, "Shred {0} is running in a seperate app domain", shredType.Name);
                }

                var assemblyPath = new Uri(shredType.Assembly.CodeBase);
                var startupInfo  = new ShredStartupInfo(assemblyPath, ((IShred)shredObject).GetDisplayName(), shredType.FullName, shredIsolationLevel);
                shredInfoList.Add(startupInfo);
            }

            return(shredInfoList);
        }
Ejemplo n.º 4
0
        public ShredController(ShredStartupInfo startupInfo)
        {
            Platform.CheckForNullReference(startupInfo, "startupInfo");

            _startupInfo = startupInfo;
            _id = ShredController.NextId;
            _runningState = RunningState.Stopped;
        }
Ejemplo n.º 5
0
        public ShredController(ShredStartupInfo startupInfo)
        {
            Platform.CheckForNullReference(startupInfo, "startupInfo");

            _startupInfo  = startupInfo;
            _id           = ShredController.NextId;
            _runningState = RunningState.Stopped;
        }
Ejemplo n.º 6
0
        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();
            }
        }