internal static List <ICustomPackageData> GetAllData() { var packageData = new List <ICustomPackageData>(); var plugins = PluginManager.GetPlugins <ICustomPackageData>(); foreach (var plugin in plugins) { try { if (failedToLoadPlugins.Contains(plugin)) { continue; } ICustomPackageData customData = (ICustomPackageData)Activator.CreateInstance(plugin); packageData.Add(customData); } catch (Exception ex) { failedToLoadPlugins.Add(plugin); log.Warning($"Failed to instantiate {plugin}. Skipping plugin."); log.Debug(ex); } } return(packageData); }
public override bool Deserialize(XElement node, ITypeData t, Action <object> setter) { if (node.Name.LocalName == "File" && t.IsA(typeof(PackageFile))) { PackageFile packageFile = new PackageFile(); foreach (XAttribute attr in node.Attributes()) { switch (attr.Name.LocalName) { case "Path": packageFile.RelativeDestinationPath = attr.Value; break; case "SourcePath": packageFile.SourcePath = attr.Value; break; case "LicenseRequired": packageFile.LicenseRequired = attr.Value; break; } } foreach (XElement elm in node.Elements()) { if (elm.Name.LocalName == "Plugins") { Serializer.Deserialize(elm, o => packageFile.Plugins = o as List <PluginFile>, typeof(List <PluginFile>)); continue; } if (elm.Name.LocalName == "IgnoreDependency") { packageFile.IgnoredDependencies.Add(elm.Value); continue; } var handlingPlugins = plugins.Where(s => s.GetType().GetDisplayAttribute().Name == elm.Name.LocalName).ToArray(); if (handlingPlugins.Length > 0) { if (handlingPlugins.Length > 1) { Log.Warning($"Detected multiple plugins able to handle XMl tag {elm.Name.LocalName}. Unexpected behavior may occur."); } ICustomPackageData p = handlingPlugins[0]; if (elm.HasAttributes || !elm.IsEmpty) { Serializer.Deserialize(elm, o => p = (ICustomPackageData)o, p.GetType()); } packageFile.CustomData.Add(p); continue; } packageFile.CustomData.Add(new MissingPackageData(elm)); } setter.Invoke(packageFile); return(true); } return(false); }