Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPublicClassDiscovered(object sender, RuntimeClassProviderEventArgs e)
        {
            try
            {
                // does type support the interface we are searching for? ISnapIn?
                if (e.Type.GetInterface(_type.FullName) == null)
                {
                    return;
                }

                try
                {
                    // confirm the type is visible, some types may be marked with the SnapInVisibilityAttribute
                    if (this.IsTypeVisibleForHosting(e))
                    {
                        _array.Add(e);
                    }
                }
                catch (System.Exception systemException)
                {
                    System.Diagnostics.Trace.WriteLine(systemException);
                }
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }
        }
        //		public Type[] GetPublicClasses(FileInfo fileInfo)
        //		{
        //			try
        //			{
        //				// try and load the file as a .net assembly
        //				Assembly assembly = Assembly.LoadFrom(fileInfo.FullName);
        //
        //				// get the exported types from the assembly
        //				Type[] types = assembly.GetExportedTypes();
        //
        //				if (types == null)
        //					return;
        //
        //				foreach(Type t in types)
        //					// A public class that is not abstract
        //					if (t.IsClass && t.IsPublic && (!t.IsAbstract))
        //						OnPublicClassDiscovered(this, new RuntimeClassProviderEventArgs(assembly, t));
        //
        //				types = null;
        //				assembly = null;
        //			}
        //			catch(BadImageFormatException)
        //			{
        //				// fileInfo.FullName is not a valid .NET assembly
        //			}
        //			catch(System.Exception systemException)
        //			{
        //				System.Diagnostics.Trace.WriteLine(systemException);
        //			}
        //		}

        /// <summary>
        /// Raises the PublicClassDiscovered event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnPublicClassDiscovered(object sender, RuntimeClassProviderEventArgs e)
        {
            try
            {
                if (this.PublicClassDiscovered != null)
                {
                    this.PublicClassDiscovered(sender, e);
                }
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }
        }
Exemplo n.º 3
0
        private bool IsTypeVisibleForHosting(RuntimeClassProviderEventArgs e)
        {
            try
            {
                // ok, yes, now make sure that no one has hidden it from the SnapInHostingEngine
                SnapInAttributeReader     r = new SnapInAttributeReader(e.Type);
                SnapInVisibilityAttribute a = r.GetSnapInHostVisibilityAttribute();

                if (a != null)
                {
                    return(a.Visible);
                }
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }
            return(true);
        }
		private bool IsTypeVisibleForHosting(RuntimeClassProviderEventArgs e)
		{
			try
			{
				// ok, yes, now make sure that no one has hidden it from the SnapInHostingEngine
				SnapInAttributeReader r = new SnapInAttributeReader(e.Type);
				SnapInVisibilityAttribute a = r.GetSnapInHostVisibilityAttribute();

				if (a != null)
					return a.Visible;					
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
			return true;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnPublicClassDiscovered(object sender, RuntimeClassProviderEventArgs e)
		{
			try
			{
				// does type support the interface we are searching for? ISnapIn?
				if (e.Type.GetInterface(_type.FullName) == null)
					return;

				try
				{
					// confirm the type is visible, some types may be marked with the SnapInVisibilityAttribute
					if (this.IsTypeVisibleForHosting(e))
						_array.Add(e);
				}
				catch(System.Exception systemException)
				{
					System.Diagnostics.Trace.WriteLine(systemException);
				}
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
		}
		//		public Type[] GetPublicClasses(FileInfo fileInfo)
		//		{
		//			try
		//			{
		//				// try and load the file as a .net assembly
		//				Assembly assembly = Assembly.LoadFrom(fileInfo.FullName);
		//
		//				// get the exported types from the assembly
		//				Type[] types = assembly.GetExportedTypes();
		//				
		//				if (types == null)
		//					return;
		//				
		//				foreach(Type t in types)
		//					// A public class that is not abstract
		//					if (t.IsClass && t.IsPublic && (!t.IsAbstract))
		//						OnPublicClassDiscovered(this, new RuntimeClassProviderEventArgs(assembly, t));
		//				
		//				types = null;
		//				assembly = null;
		//			}
		//			catch(BadImageFormatException)
		//			{
		//				// fileInfo.FullName is not a valid .NET assembly
		//			}
		//			catch(System.Exception systemException) 
		//			{
		//				System.Diagnostics.Trace.WriteLine(systemException); 
		//			}
		//		}

		/// <summary>
		/// Raises the PublicClassDiscovered event
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected virtual void OnPublicClassDiscovered(object sender, RuntimeClassProviderEventArgs e)
		{
			try
			{
				if (this.PublicClassDiscovered != null)
					this.PublicClassDiscovered(sender, e);
			}
			catch(System.Exception systemException) 
			{
				System.Diagnostics.Trace.WriteLine(systemException); 
			}	
		}