/// <summary>
		/// Parses the category specified in the configuration specified for the type specified, and returns an array of Versions that are listed in the category.
		/// </summary>
		/// <param name="configuration">The configuration to parse</param>
		/// <param name="type">The type to search for</param>
		/// <param name="categoryName">The category to search in</param>
		/// <returns></returns>
		public static Version[] GetListedVersionsOfType(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)
						{
							// enumerate the type category, each subcategory is the full name of a type that is listed
							foreach(XmlConfigurationCategory typeCategory in searchCategory.Categories)
							{
								// compare the category's element name to the full name of the type specified
								if (string.Compare(typeCategory.ElementName, type.FullName, false) == 0)
								{
									// enumerate the version category, each subcategory is the version number of the type
									ArrayList array = new ArrayList();
									foreach(XmlConfigurationCategory versionCategory in typeCategory.Categories)
									{
										Version v = new Version(versionCategory.ElementName);
										array.Add(v);
									}
									return array.ToArray(typeof(Version)) as Version[];
								}
							}
						}
					}
				}
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}			
			return new Version[] {};
		}
예제 #2
0
 /// <summary>
 /// Parses the category specified in the configuration specified for the type specified, and returns an array of Versions that are listed in the category.
 /// </summary>
 /// <param name="configuration">The configuration to parse</param>
 /// <param name="type">The type to search for</param>
 /// <param name="categoryName">The category to search in</param>
 /// <returns></returns>
 public static Version[] GetListedVersionsOfType(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)
                 {
                     // enumerate the type category, each subcategory is the full name of a type that is listed
                     foreach (XmlConfigurationCategory typeCategory in searchCategory.Categories)
                     {
                         // compare the category's element name to the full name of the type specified
                         if (string.Compare(typeCategory.ElementName, type.FullName, false) == 0)
                         {
                             // enumerate the version category, each subcategory is the version number of the type
                             ArrayList array = new ArrayList();
                             foreach (XmlConfigurationCategory versionCategory in typeCategory.Categories)
                             {
                                 Version v = new Version(versionCategory.ElementName);
                                 array.Add(v);
                             }
                             return(array.ToArray(typeof(Version)) as Version[]);
                         }
                     }
                 }
             }
         }
     }
     catch (System.Exception systemException)
     {
         System.Diagnostics.Trace.WriteLine(systemException);
     }
     return(new Version[] {});
 }
		/// <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;
		}
예제 #4
0
        /// <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);
        }