/// <summary> /// Determines if the specified Type's Version (queried via attributes and reflection) is included in the array of Versions specified /// </summary> /// <param name="versions">The array of versions to search</param> /// <param name="type">The type to search for</param> /// <returns></returns> public static bool IsVersionOfTypeIncluded(Version[] versions, Type type) { try { if (type != null) { SnapInAttributeReader reader = new SnapInAttributeReader(type); if (reader != null) { SnapInVersionAttribute versionAttribute = reader.GetSnapInVersionAttribute(); if (versionAttribute != null) { foreach (Version version in versions) { if (Version.Equals(version, versionAttribute.Version)) { return(true); } } } } } } catch (System.Exception systemException) { System.Diagnostics.Trace.WriteLine(systemException); } return(false); }
/// <summary> /// Determines if the specified Type's Version is an upgrade from the specified versions /// </summary> /// <param name="versions">The array of versions to compare</param> /// <param name="type">The type whos version to compare against</param> /// <returns></returns> public static bool IsVersionOfTypeAnUpgrade(Version[] versions, Type type) { try { if (type != null) { SnapInAttributeReader reader = new SnapInAttributeReader(type); if (reader != null) { SnapInVersionAttribute versionAttribute = reader.GetSnapInVersionAttribute(); if (versionAttribute != null) { bool newer = true; foreach (Version version in versions) { if (version > versionAttribute.Version) { newer = false; } } return(newer); } } } } catch (System.Exception systemException) { System.Diagnostics.Trace.WriteLine(systemException); } return(false); }
/// <summary> /// Creates a category for the type including it's version (defaulted to "1.0.0.0" for versionless types) in the specified configuration, using the specified type, and specified category name. /// </summary> /// <param name="configuration">The configuration in which the category will be created</param> /// <param name="type">The type for which the category will be created</param> /// <param name="categoryName">The category name in which creation will occur</param> /// <returns></returns> public static XmlConfigurationCategory CreateCategoryForTypeVersion(XmlConfiguration configuration, Type type, CategoryNames categoryName) { try { if (configuration != null) { if (type != null) { // start in the specified category XmlConfigurationCategory searchCategory = configuration.Categories[@"SnapIns\" + categoryName.ToString()]; if (searchCategory != null) { SnapInAttributeReader reader = new SnapInAttributeReader(type); if (reader != null) { Version version = null; SnapInVersionAttribute versionAttribute = reader.GetSnapInVersionAttribute(); if (versionAttribute != null) { version = versionAttribute.Version; } else { version = new Version(1, 0, 0, 0); } string path = string.Format("{0}\\{1}\\{2}", @"SnapIns\" + categoryName.ToString(), type.FullName, version.ToString()); return(configuration.Categories[path, true]); } } } } } catch (System.Exception systemException) { System.Diagnostics.Trace.WriteLine(systemException); } return(null); }
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); } }