public PySnippet(string script) { _script = new ScriptContainer("python", Guid.Empty, script, false); _script.ReferencedNames.Add(typeof(Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair).Assembly.GetName()); _script.ReferencedNames.Add(typeof(ExpressionResolver).Assembly.GetName()); }
/// <summary> /// A factory object for a dynamic scripted node /// </summary> /// <param name="label">The node label</param> /// <param name="guid">The node guid</param> /// <param name="container">A container for the script code</param> /// <param name="classname">The name of the class to create</param> /// <param name="state">Node state</param> public DynamicNodeFactory(string label, Guid guid, ScriptContainer container, string classname, object state) : base(label, guid) { Container = container; ClassName = classname; State = state; }
public static IEnumerable<DataFrame> ParseFrames(IEnumerable<DataFrame> frames, string selectionPath, ScriptContainer container, string classname) { BasePipelineNode input; ParseWithPipelineNode output; IEnumerable<DataFrame> ret = new DataFrame[0]; NetGraph graph = BuildGraph(container, classname, selectionPath, out input, out output); try { foreach (DataFrame frame in frames) { input.Input(frame); } input.Shutdown(null); output.EventFlag.WaitOne(500); ret = output.Frames; } finally { ((IDisposable)graph).Dispose(); } return ret; }
/// <summary> /// Constructor /// </summary> public ScriptDocument(string engine) { _script = new ScriptContainer(engine, Uuid, "", false); _config = new Dictionary<string, DynamicNodeConfigProperty>(); // Add some more assemblies that we can see _script.ReferencedNames.Add(typeof(ScriptDocument).Assembly.GetName()); _script.ReferencedNames.Add(typeof(ProxyNetworkService).Assembly.GetName()); _script.ReferencedNames.Add(typeof(CertificateUtils).Assembly.GetName()); _script.ReferencedNames.Add(typeof(Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair).Assembly.GetName()); _script.ReferencedNames.Add(typeof(ExpressionResolver).Assembly.GetName()); _script.ReferencedNames.Add(typeof(HttpParser).Assembly.GetName()); }
public static DataNode ParseNode(DataNode dataNode, ScriptContainer container, string classname) { DataNode ret = null; if (dataNode != null) { string selectionPath = String.Format("/{0}", dataNode.PathName); DataFrame frame = new DataFrame(new DataKey("Root")); frame.Root.AddSubNode(dataNode.CloneNode()); DataFrame[] frames = ParseFrames(new DataFrame[1] { frame }, selectionPath, container, classname).ToArray(); if(frames.Length > 0) { // We only replace the node with the first DataNode for now ret = frames[0].SelectSingleNode(selectionPath); } } return ret; }
private static NetGraph BuildGraph(ScriptContainer container, string classname, string selectionPath, out BasePipelineNode input, out ParseWithPipelineNode output) { DynamicNodeFactory factory = new DynamicNodeFactory("", Guid.NewGuid(), container, classname, null); ParseWithPipelineNodeFactory parseWithFactory = new ParseWithPipelineNodeFactory(); factory.SelectionPath = selectionPath; NetGraphBuilder builder = new NetGraphBuilder(); builder.AddNode(factory); builder.AddNode(parseWithFactory); builder.AddLine(factory, parseWithFactory, null); NetGraph graph = builder.Factory.Create(Logger.GetSystemLogger(), null, new MetaDictionary(), new MetaDictionary(), new PropertyBag("Connection")); input = graph.Nodes[factory.Id]; output = (ParseWithPipelineNode)graph.Nodes[parseWithFactory.Id]; return graph; }
public DummyScriptDocument(ScriptContainer script) { _script = script; }
/// <summary> /// Clone constructor, copy everything /// </summary> /// <param name="container">The existing container</param> public ScriptContainer(ScriptContainer container) : this(container, container.Script) { }
/// <summary> /// Clone constructor, copy everything but the script /// </summary> /// <param name="container">The existing container</param> /// <param name="newScript">New script to use</param> public ScriptContainer(ScriptContainer container, string newScript) : this(container.Engine, container.Uuid, newScript, container.EnableDebug, container.ReferencedNames) { }
private void RunScript(LogPacket[] packets, ScriptContainer container, string classname) { if (packets.Length > 0) { try { DataFrame[] frames = ParseWithUtils.ParseFrames(packets.Select(p => p.Frame), "/", container, classname).ToArray(); if (frames.Length > 0) { int index = 0; lock (_packets) { index = _packets.IndexOf(packets[0]); int currIndex = index; foreach(LogPacket packet in packets) { _packets.Remove(packet); } LogPacket template = packets[0]; foreach (DataFrame frame in frames) { LogPacket newPacket = new LogPacket(template.Tag, template.NetId, Guid.NewGuid(), template.Network, frame, template.Color, template.Timestamp); _packets.Insert(currIndex, newPacket); currIndex++; } } listLogPackets.SelectedIndices.Clear(); RefreshLog(); listLogPackets.SelectedIndices.Add(index); } else { MessageBox.Show(this, CANAPE.Properties.Resources.TreeDataKeyEditorControl_NoParseResults, CANAPE.Properties.Resources.TreeDataKeyEditorControl_NoParseResultsCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, CANAPE.Properties.Resources.TreeDataKeyEditorControl_ParseError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Constructor, internal use only /// </summary> /// <param name="container">The script container</param> /// <param name="classname">The classname</param> private DynamicScriptContainer(ScriptContainer container, string classname) { // Clone the container _container = new ScriptContainer(container); _classname = classname; }
/// <summary> /// /// </summary> /// <returns></returns> protected IDataParser CreateConverter() { if (_convert == null) { ScriptContainer container = new ScriptContainer(_engine, Guid.Empty, _script, _enableDebug, _referencedAssemblies.Select(a => a.GetName())); _convert = (IDataParser)ScriptUtils.GetInstance(container, _classname); if (_state != null) { IPersistDynamicNode persist = _convert as IPersistDynamicNode; if (persist != null) { persist.SetState(_state, GetLogger()); } } } return _convert; }
/// <summary> /// Load an assembly /// </summary> /// <param name="container">The script container, the script value indicates the assembly name</param> /// <returns></returns> public virtual ScriptError[] Parse(ScriptContainer container) { List<ScriptError> errors = new List<ScriptError>(); try { _assembly = Assembly.Load(container.Script); } catch (Exception ex) { errors.Add(new ScriptError(ex.Message, "Error", 0, 0)); } return errors.ToArray(); }
private void RunScriptFromLibraryNode(LogPacket[] packets, NodeLibraryManager.NodeLibraryType node) { ScriptContainer container = new ScriptContainer("assembly", Guid.NewGuid(), node.Type.Assembly.FullName, false); RunScript(packets, container, node.Type.FullName); }
private bool InternalParseScript() { bool ret = false; listViewErrors.Items.Clear(); ScriptContainer newContainer = new ScriptContainer(_document.Container, _currText); ScriptError[] errs = ScriptUtils.Parse(newContainer); if (errs.Length == 0) { ret = true; } else { foreach (var err in errs) { ListViewItem item = listViewErrors.Items.Add(err.Severity); item.SubItems.Add(err.Description); item.SubItems.Add(err.Line.ToString()); item.SubItems.Add(err.Column.ToString()); item.Tag = err; } } return ret; }
/// <summary> /// Create a container /// </summary> /// <param name="container">The script container</param> /// <param name="classname">The classname</param> /// <returns>The new container, will reuse an existing one if appropriate</returns> public static DynamicScriptContainer Create(ScriptContainer container, string classname) { return(GetCachedContainer(new DynamicScriptContainer(container, classname))); }
/// <summary> /// Create a container /// </summary> /// <param name="container">The script container</param> /// <param name="classname">The classname</param> /// <returns>The new container, will reuse an existing one if appropriate</returns> public static DynamicScriptContainer Create(ScriptContainer container, string classname) { return GetCachedContainer(new DynamicScriptContainer(container, classname)); }
public ScriptParserType(string name, string engine, string script) : base(name) { _script = new DummyScriptContainer(this, engine, script); }