/// <summary> /// Scans for plugins in a custom location /// </summary> /// <param name="dir">Directory to scan</param> /// <remarks> /// <para> /// Scanning looks for files with a <em>.dll</em> extension, loads them and then searches for types implementing the <see cref="IConnectionDefinition">IConnectionDefinition</see> interface /// </para> /// </remarks> public static void ScanPlugins(String dir) { //Then find types in Plugin assemblies if (Directory.Exists(dir)) { foreach (String file in Directory.GetFiles(dir)) { switch (Path.GetExtension(file)) { case ".dll": try { Assembly assm = Assembly.LoadFrom(file); ConnectionDefinitionManager.DiscoverTypes(assm); } catch { //Ignore errors in loading assemblies } break; default: continue; } } } }
private static void Init() { if (!_init) { //First find all types in this assembly Assembly assm = Assembly.GetExecutingAssembly(); ConnectionDefinitionManager.DiscoverTypes(assm); //Then scan for plugins ScanPlugins(); _init = true; } }
/// <summary> /// Loads the connection definition for the connection from the given graph /// </summary> /// <param name="g">Graph</param> public void LoadConfiguration(IGraph g) { g.NamespaceMap.AddNamespace("store", UriFactory.Create(StoreManagerNamespace)); g.NamespaceMap.AddNamespace("dnr", UriFactory.Create(ConfigurationLoader.ConfigurationNamespace)); INode rootNode = g.CreateUriNode(this.RootUri); // First off need to find the definition type (if any) Triple t = g.GetTriplesWithSubjectPredicate(rootNode, g.CreateUriNode("store:definitionType")).FirstOrDefault(); if (t != null && t.Object.NodeType == NodeType.Literal) { String typeString = ((ILiteralNode)t.Object).Value; Type defType = TryGetType(typeString, new string[] { "StoreManager.Core", "dotNetRDF", "dotNetRDF.Data.Virtuoso" }); if (defType != null) { this.Definition = (IConnectionDefinition)Activator.CreateInstance(defType); } } if (ReferenceEquals(this.Definition, null)) { // Have to figure out the definition type another way t = g.GetTriplesWithSubjectPredicate(rootNode, g.CreateUriNode("dnr:type")).FirstOrDefault(); if (t != null && t.Object.NodeType == NodeType.Literal) { String typeString = ((ILiteralNode)t.Object).Value; Type providerType = TryGetType(typeString, new string[] { "StoreManager.Core", "dotNetRDF", "dotNetRDF.Data.Virtuoso" }); if (providerType != null) { IConnectionDefinition temp = ConnectionDefinitionManager.GetDefinitionByTargetType(providerType); if (temp != null) { this.Definition = (IConnectionDefinition)Activator.CreateInstance(temp.GetType()); } } } } if (ReferenceEquals(this.Definition, null)) { throw new ArgumentException("Unable to locate the necessary configuration information to load this connection from the given Graph"); } // Populate information this.Definition.PopulateFrom(g, rootNode); this.LoadInformation(g); }
private static void Init() { if (!_init) { //First find all types in this assembly Assembly assm = Assembly.GetExecutingAssembly(); ConnectionDefinitionManager.DiscoverTypes(assm); //Then find types in Plugin assemblies if (Directory.Exists("plugins")) { foreach (String file in Directory.GetFiles("plugins")) { switch (Path.GetExtension(file)) { case ".dll": try { assm = Assembly.LoadFrom(file); ConnectionDefinitionManager.DiscoverTypes(assm); } catch (Exception ex) { //Ignore errors in loading assemblies } break; default: continue; } } } _init = true; } }