Changeset 2763 for trunk/sources/HeuristicLab.PluginInfrastructure/Manager
- Timestamp:
- 02/08/10 16:25:23 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.PluginInfrastructure/Manager
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginDescription.cs
r2690 r2763 60 60 internal set { version = value; } 61 61 } 62 [Obsolete] 62 63 private DateTime buildDate; 63 64 /// <summary> 64 65 /// Gets the build date of the plugin. 65 66 /// </summary> 67 [Obsolete] 66 68 public DateTime BuildDate { 67 69 get { return buildDate; } … … 132 134 internal void Load() { 133 135 if (!(pluginState == PluginState.Enabled || pluginState == PluginState.Loaded)) 134 throw new InvalidOperationException("Can't load eda plugin in state " + pluginState);136 throw new InvalidOperationException("Can't load a plugin in state " + pluginState); 135 137 pluginState = PluginState.Loaded; 136 138 nTimesLoaded++; -
trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginValidator.cs
r2750 r2763 260 260 /// <param name="t"></param> 261 261 private PluginDescription GetPluginDescription(Type pluginType) { 262 // get all attributes of that type 263 IList<CustomAttributeData> attributes = CustomAttributeData.GetCustomAttributes(pluginType); 264 List<PluginDependency> pluginDependencies = new List<PluginDependency>(); 265 List<PluginFile> pluginFiles = new List<PluginFile>(); 266 string pluginName = null; 267 string pluginDescription = null; 268 string pluginVersion = "0.0.0.0"; 269 // iterate through all custom attributes and search for attributed that we are interested in 270 foreach (CustomAttributeData attributeData in attributes) { 271 if (IsAttributeDataForType(attributeData, typeof(PluginAttribute))) { 272 pluginName = (string)attributeData.ConstructorArguments[0].Value; 273 if (attributeData.ConstructorArguments.Count() > 1) { 274 pluginVersion = (string)attributeData.ConstructorArguments[1].Value; 275 } 276 if (attributeData.ConstructorArguments.Count() > 2) { 277 pluginDescription = (string)attributeData.ConstructorArguments[2].Value; 278 } else { 279 // no description given => use name as description 280 pluginDescription = pluginName; 281 } 282 } else if (IsAttributeDataForType(attributeData, typeof(PluginDependencyAttribute))) { 283 string name = (string)attributeData.ConstructorArguments[0].Value; 284 Version version = new Version(); 285 // check if version is given for now 286 // later when the constructore of PluginDependencyAttribute with only one argument has been removed 287 // this conditional can be removed as well 288 if (attributeData.ConstructorArguments.Count > 1) { 289 try { 290 version = new Version((string)attributeData.ConstructorArguments[1].Value); // throws FormatException 291 } 292 catch (FormatException ex) { 293 throw new InvalidPluginException("Invalid version format of dependency " + name + " in plugin " + pluginType.ToString(), ex); 294 } 295 } 296 pluginDependencies.Add(new PluginDependency(name, version)); 297 } else if (IsAttributeDataForType(attributeData, typeof(PluginFileAttribute))) { 298 string pluginFileName = (string)attributeData.ConstructorArguments[0].Value; 299 PluginFileType fileType = (PluginFileType)attributeData.ConstructorArguments[1].Value; 300 pluginFiles.Add(new PluginFile(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName)), fileType)); 301 } 302 } 262 263 string pluginName, pluginDescription, pluginVersion; 264 GetPluginMetaData(pluginType, out pluginName, out pluginDescription, out pluginVersion); 265 var pluginFiles = GetPluginFilesMetaData(pluginType); 266 var pluginDependencies = GetPluginDependencyMetaData(pluginType); 303 267 304 268 // minimal sanity check of the attribute values 305 269 if (!string.IsNullOrEmpty(pluginName) && 306 pluginFiles.Count > 0 &&// at least on file270 pluginFiles.Count() > 0 && // at least on file 307 271 pluginFiles.Any(f => f.Type == PluginFileType.Assembly)) { // at least on assembly 308 272 // create a temporary PluginDescription that contains the attribute values … … 317 281 } else { 318 282 throw new InvalidPluginException("Invalid metadata in plugin " + pluginType.ToString()); 283 } 284 } 285 286 private static IEnumerable<PluginDependency> GetPluginDependencyMetaData(Type pluginType) { 287 // get all attributes of type PluginDependency 288 var dependencyAttributes = from attr in CustomAttributeData.GetCustomAttributes(pluginType) 289 where IsAttributeDataForType(attr, typeof(PluginDependencyAttribute)) 290 select attr; 291 292 foreach (var dependencyAttr in dependencyAttributes) { 293 string name = (string)dependencyAttr.ConstructorArguments[0].Value; 294 Version version = new Version("0.0.0.0"); // default version 295 // check if version is given for now 296 // later when the constructor of PluginDependencyAttribute with only one argument has been removed 297 // this conditional can be removed as well 298 if (dependencyAttr.ConstructorArguments.Count > 1) { 299 try { 300 version = new Version((string)dependencyAttr.ConstructorArguments[1].Value); // might throw FormatException 301 } 302 catch (FormatException ex) { 303 throw new InvalidPluginException("Invalid version format of dependency " + name + " in plugin " + pluginType.ToString(), ex); 304 } 305 } 306 yield return new PluginDependency(name, version); 307 } 308 } 309 310 // not static because we need the PluginDir property 311 private IEnumerable<PluginFile> GetPluginFilesMetaData(Type pluginType) { 312 // get all attributes of type PluginFileAttribute 313 var pluginFileAttributes = from attr in CustomAttributeData.GetCustomAttributes(pluginType) 314 where IsAttributeDataForType(attr, typeof(PluginFileAttribute)) 315 select attr; 316 foreach (var pluginFileAttribute in pluginFileAttributes) { 317 string pluginFileName = (string)pluginFileAttribute.ConstructorArguments[0].Value; 318 PluginFileType fileType = (PluginFileType)pluginFileAttribute.ConstructorArguments[1].Value; 319 yield return new PluginFile(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName)), fileType); 320 } 321 } 322 323 private static void GetPluginMetaData(Type pluginType, out string pluginName, out string pluginDescription, out string pluginVersion) { 324 // there must be a single attribute of type PluginAttribute 325 var pluginMetaDataAttr = (from attr in CustomAttributeData.GetCustomAttributes(pluginType) 326 where IsAttributeDataForType(attr, typeof(PluginAttribute)) 327 select attr).Single(); 328 329 pluginName = (string)pluginMetaDataAttr.ConstructorArguments[0].Value; 330 331 // default description and version 332 pluginVersion = "0.0.0.0"; 333 pluginDescription = pluginName; 334 if (pluginMetaDataAttr.ConstructorArguments.Count() == 2) { 335 // if two arguments are given the second argument is the version 336 pluginVersion = (string)pluginMetaDataAttr.ConstructorArguments[1].Value; 337 } else if (pluginMetaDataAttr.ConstructorArguments.Count() == 3) { 338 // if three arguments are given the second argument is the description and the third is the version 339 pluginDescription = (string)pluginMetaDataAttr.ConstructorArguments[1].Value; 340 pluginVersion = (string)pluginMetaDataAttr.ConstructorArguments[2].Value; 319 341 } 320 342 } … … 459 481 } 460 482 461 internalvoid OnPluginLoaded(PluginInfrastructureEventArgs e) {483 private void OnPluginLoaded(PluginInfrastructureEventArgs e) { 462 484 if (PluginLoaded != null) 463 485 PluginLoaded(this, e);
Note: See TracChangeset
for help on using the changeset viewer.