public IComponentProvider LoadFromLibrary(string libName, string componentName, bool throwOnFailure) { // Console.Out.WriteLine("LoadFromLibrary: {0} -> {1}", libName, componentName); string fullName = libName + "." + componentName; if (partiallyLoadedLibraries.ContainsKey(libName)) { /* check if it's loaded */ if (this.FindByName(fullName) != null) { return(this.FindByName(fullName)[0]); } } else if (fullyLoadedLibraries.ContainsKey(libName)) { return(this.FindByName(fullName)[0]); } else { /* it's not even partially loaded, so do a partial load */ LibraryDesc lib = PartialLoadLibrary(libName, throwOnFailure); /* if above doesn't throw, returning null is assumed */ if (lib == null) { return(null); } foreach (IComponentProvider provider in lib.Components) { if (!provider.MatchAgainstNameAllowed) { continue; } if (provider.MatchedName == componentName) { /* register lib */ partiallyLoadedLibraries[libName] = lib; /* create name redirect */ IComponentProvider newProvider = new NameOverride(provider, fullName); Register(newProvider); return(newProvider); } } if (throwOnFailure) { throw new Exception( String.Format("Library {0} do not contain component {1}", libName, componentName)); } } return(null); }
public LibraryDesc LoadLibrary(string libName, bool throwOnFailure) { if (fullyLoadedLibraries.ContainsKey(libName)) { return(fullyLoadedLibraries[libName]); } if (partiallyLoadedLibraries.ContainsKey(libName)) { /* fully load partially loaded library */ foreach (IComponentProvider provider in partiallyLoadedLibraries[libName].Components) { if (!provider.MatchAgainstNameAllowed) { continue; } string fullName = libName + "." + provider.MatchedName; if (FindByName(fullName).Length == 0) { Register(new NameOverride(provider, fullName)); } } /* now fully loaded */ LibraryDesc lib = partiallyLoadedLibraries[libName]; partiallyLoadedLibraries.Remove(libName); fullyLoadedLibraries[libName] = lib; return(lib); } LibraryDesc libFull = PartialLoadLibrary(libName, throwOnFailure); foreach (IComponentProvider provider in libFull.Components) { if (!provider.MatchAgainstNameAllowed) { continue; } string fullName = libName + "." + provider.MatchedName; Register(new NameOverride(provider, fullName)); } fullyLoadedLibraries[libName] = libFull; return(libFull); }
private void CacheDeserialization() { Child.InstallEnvironment = environment; SerializableXmlDocument doc = Child.OpenForReading <SerializableXmlDocument>().Object; doc.Normalize(); XmlElement node = doc.FirstChild.NextSibling as XmlElement; // assert root node if (node.Name != "Library") { throw new AbortInstallationException("Source is not a library descriptor"); } // check version if (new Version(node.GetAttribute("xversion")) > new Version(1, 0, 0)) { throw new AbortInstallationException("Application descriptor is of an incorrect version"); } string name = node.GetAttribute("name"); // Guid id = new Guid(node.GetAttribute("id")); // string rootComponentName = node.GetAttribute("root"); // ApplicationType apptype = (ApplicationType)Enum.Parse(typeof(ApplicationType), node.GetAttribute("type")); // string friendlyName = node.GetAttribute("friendly"); List <ConfiguredComponent> defs = new List <ConfiguredComponent>(); foreach (XmlNode firstNode in node.ChildNodes) { if (firstNode.Name == "Components") { /* load all components */ foreach (XmlNode componentNode in firstNode.ChildNodes) { if (componentNode.Name.StartsWith("#")) { continue; } if (componentNode.Name != "Component") { throw new AbortInstallationException( String.Format( "Library description is not well-formed. Only Component nodes are allowed in the Components section. Found '{0}' instead", componentNode.Name)); } defs.Add(new ConfiguredComponent(componentNode)); } } } /** ok, construct **/ LibraryDesc lib = new LibraryDesc(); lib.Components = defs.ToArray(); applicationDescriptor = lib; }