Ejemplo n.º 1
0
		private void ExtractAttributesFromMetaData(Type type)
		{
			try
			{
				SnapInAttributeReader reader = new SnapInAttributeReader(type);
				if (reader != null)
				{
					// company name
					SnapInCompanyAttribute companyAttribute = reader.GetSnapInCompanyAttribute();
					if (companyAttribute != null)
						_company = companyAttribute.CompanyName;

					// description
					SnapInDescriptionAttribute descriptionAttribute = reader.GetSnapInDescriptionAttribute();
					if (descriptionAttribute != null)
						_description = descriptionAttribute.Description;

					// developers
					SnapInDevelopersAttribute developersAttribute = reader.GetSnapInDeveloperAttributes();
					if (developersAttribute != null)
						_developers = developersAttribute.DevelopersNames;

					// image
					SnapInImageAttribute imageAttribute = reader.GetSnapInImageAttribute();
					if (imageAttribute != null)
						_image = (Bitmap)imageAttribute.GetImage(type);

					// product families
					SnapInProductFamilyMemberAttribute[] productFamilyAttributes = reader.GetSnapInProductFamilyMemberAttribute();
					if (productFamilyAttributes != null)
					{
						_productFamilies = new string[productFamilyAttributes.Length];
						for(int i = 0; i < productFamilyAttributes.Length; i++)
							_productFamilies[i] = productFamilyAttributes[i].ProductFamily;
					}
					
					// title
					SnapInTitleAttribute titleAttribute = reader.GetSnapInTitleAttribute();
					if (titleAttribute != null)
						_title = titleAttribute.Title;						
					
					// version
					SnapInVersionAttribute versionAttribute = reader.GetSnapInVersionAttribute();
					if (versionAttribute != null)
						_version = versionAttribute.Version;
				}	

				if (_developers == null)
					_developers = new string[] {};

				if (_productFamilies == null)
					_productFamilies = new string[] {};

				// ensure default image
				if (_image == null)
					_image = _defaultImage;
							
				// ensure title 
				if (_title == null || _title == string.Empty)
					_title = type.FullName;

				if (_version == null)
					_version = new Version("1.0.0.0");
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
		}
		/// <summary>
		/// Handles the BuildingFeatureList event from the FeatureEngine
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		internal static void OnFeatureEngineBuildingFeatureList(object sender, FeatureCollectionEventArgs e)
		{
			SnapInHostingEngine hostingEngine = SnapInHostingEngine.GetExecutingInstance();

			// add features for resetting the configuration files
			e.Features.Add(new ConfigurationFeature(SnapInHostingEngine.DefaultCommonConfigurationName, "The common configuration stores options common to all users.", FeatureActions.ResetToDefault));
			e.Features.Add(new ConfigurationFeature(SnapInHostingEngine.DefaultLocalUserConfigurationName, "The local user configuration stores options specific to the current user.", FeatureActions.ResetToDefault));

			// since this event may fire before we have loaded any snapins (as a result of the _troubleshoot flag from the command line or app config )
			// we need to make sure we descriptors before we try this
			if ( hostingEngine.SnapInDescriptors != null )
			{
				// add features for reinstalling the snapins
				foreach(SnapInDescriptor descriptor in hostingEngine.SnapInDescriptors)
				{
					try
					{
						SnapInAttributeReader r = new SnapInAttributeReader(descriptor.Type);
						SnapInTitleAttribute ta = r.GetSnapInTitleAttribute();
						SnapInDescriptionAttribute da = r.GetSnapInDescriptionAttribute();

						string name = descriptor.Type.FullName;
						string description = null;

						if (ta != null)
							name = ta.Title;

						if (da != null)
							description = da.Description;

						e.Features.Add(new SnapInFeature(name, description, descriptor.Type, FeatureActions.Reinstall));
					}
					catch(System.Exception systemException)
					{
						System.Diagnostics.Trace.WriteLine(systemException);
					}
				}
			}
		}