static void Main(string[] args) { DotNetEnv.Env.Load(); NodeBlockExporter.ExportNodesSchema(Environment.GetEnvironmentVariable("node_schema_path")); try { // init graphs cost database updater //GraphsContainer.InitConsumingGraphCosts(); // init graphs that was live on last run if (Environment.GetEnvironmentVariable("relaunch_last_graph") == "true") { GraphsContainer.InitActiveGraphs(); } new InternalApi(new string[] { }, "0.0.0.0", 1337).InitApi(); } catch (Exception error) { Console.WriteLine("Unable to init GraphLinq Engine API: {0}", error.Message); } Console.ReadLine(); }
public static void LoadPlugins() { if (_pluginLoaded) { return; } if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins"))) { Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins")); } foreach (var pluginDll in Directory.GetFiles(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins"))) { try { var assembly = Assembly.LoadFile(pluginDll); var basePluginType = assembly.GetTypes().ToList().FirstOrDefault(x => x.IsSubclassOf(typeof(BasePlugin))); if (basePluginType == null) { continue; } var plugin = Activator.CreateInstance(basePluginType) as BasePlugin; plugin.Load(); var nodeCount = 0; foreach (var type in assembly.GetTypes()) { foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)) { if (method.GetCustomAttributes(typeof(Attributes.ExportableObject), true).Length == 0) { continue; } var eo = method.GetCustomAttributes(typeof(Attributes.ExportableObject), true).FirstOrDefault() as ExportableObject; _exportableObjects.Add(eo.Name, method); } if (type.GetCustomAttributes(typeof(Attributes.NodeDefinition), true).Length == 0) { continue; } var instance = Activator.CreateInstance(type, string.Empty, null) as Node; NodeBlockExporter.AddNodeType(instance); nodeCount++; } _plugins.Add(plugin); logger.Info("Plugin " + plugin.GetType().FullName + " loaded with " + nodeCount + " nodes and " + _exportableObjects.Count + " exportables objects"); } catch (Exception ex) { logger.Error(ex, "Can't load the plugin : " + pluginDll); } } _pluginLoaded = true; }
public static void LoadPlugins() { if (_pluginLoaded) { return; } if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins"))) { Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins")); } foreach (var pluginDll in Directory.GetFiles(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins"))) { try { var assembly = Assembly.LoadFile(pluginDll); var basePluginType = assembly.GetTypes().ToList().FirstOrDefault(x => x.IsSubclassOf(typeof(BasePlugin))); if (basePluginType == null) { continue; } var plugin = Activator.CreateInstance(basePluginType) as BasePlugin; plugin.Load(); foreach (var type in assembly.GetTypes()) { if (type.GetCustomAttributes(typeof(Attributes.NodeDefinition), true).Length == 0) { continue; } var instance = Activator.CreateInstance(type, string.Empty, null) as Node; NodeBlockExporter.AddNodeType(instance); } _plugins.Add(plugin); } catch (Exception ex) { logger.Error(ex, "Can't load the plugin : " + pluginDll); } } _pluginLoaded = true; }
public static BlockGraph LoadGraph(string graphJson, string uniqueHash, string compressedRaw) { var graphSchema = JsonConvert.DeserializeObject <BlockGraphSchema>(graphJson); var graph = new BlockGraph(graphSchema.Name, null, false); graph.RawGraphData = graphJson; graph.UniqueHash = uniqueHash; graph.CompressedRaw = compressedRaw; if (string.IsNullOrEmpty(graph.UniqueHash) || string.IsNullOrEmpty(graph.CompressedRaw)) { throw new Exception("UniqueHash or CompressedRaw from BlockGraph cannot be null."); } // Load nodes foreach (var nodeSchema in graphSchema.Nodes) { Node node = null; var typeFromSchema = NodeBlockExporter.GetNodes().FirstOrDefault(x => x.NodeType == nodeSchema.Type); if (typeFromSchema != null) { node = Activator.CreateInstance(typeFromSchema.GetType(), nodeSchema.Id, graph) as Node; } if (node != null) { graph.Nodes.Add(node.Id, node); } } // Load assignments and exec direction foreach (var nodeSchema in graphSchema.Nodes) { if (!graph.Nodes.ContainsKey(nodeSchema.Id)) { continue; } var node = graph.Nodes[nodeSchema.Id]; if (nodeSchema.OutNode != null) { node.OutNode = graph.Nodes[nodeSchema.OutNode]; } foreach (var parameter in nodeSchema.InParameters) { var nodeParam = node.InParameters[parameter.Name]; nodeParam.Id = parameter.Id; nodeParam.Value = parameter.Value; } foreach (var parameter in nodeSchema.OutParameters) { var nodeParam = node.OutParameters[parameter.Name]; nodeParam.Id = parameter.Id; if (parameter.ValueIsReference && parameter.Value != null && parameter.Value.ToString() != "") { nodeParam.Value = graph.Nodes[(string)parameter.Value]; } else { nodeParam.Value = parameter.Value; } } } foreach (var nodeSchema in graphSchema.Nodes) { if (!graph.Nodes.ContainsKey(nodeSchema.Id)) { continue; } var node = graph.Nodes[nodeSchema.Id]; foreach (var parameter in nodeSchema.InParameters) { var nodeParam = node.InParameters[parameter.Name]; if (parameter.Assignment != string.Empty) { nodeParam.Assignments = graph.FindParameterById(parameter.Assignment); } } foreach (var parameter in nodeSchema.OutParameters) { var nodeParam = node.OutParameters[parameter.Name]; if (parameter.Assignment != string.Empty) { nodeParam.Assignments = graph.FindParameterById(parameter.Assignment); } } } return(graph); }