public Generator(Context ctx) { Context.Logger.Info("Generator constructor called"); this.ctx = ctx; // Declare Output schema Dictionary<string, List<Type>> outputSchema = new Dictionary<string, List<Type>>(); outputSchema.Add("default", new List<Type>() { typeof(string) }); this.ctx.DeclareComponentSchema(new ComponentStreamSchema(null, outputSchema)); }
public SimpleDRPC(Context ctx) { Context.Logger.Info("SimpleDRPC constructor called"); this.ctx = ctx; // Declare Input and Output schemas Dictionary<string, List<Type>> inputSchema = new Dictionary<string, List<Type>>(); inputSchema.Add("default", new List<Type>() { typeof(string), typeof(object) }); Dictionary<string, List<Type>> outputSchema = new Dictionary<string, List<Type>>(); outputSchema.Add("default", new List<Type>() { typeof(string), typeof(object) }); this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, outputSchema)); }
public static Script Compile(Code code, Context context, string source, IDebugger debugger) { if (debugger != null) debugger.SetSourceCode(source); context.SetFunction("eval", (string c) => { var bkCode = source; var scope = context.Scope; context.Scope = new Scope {Obj = scope.Obj}; var result = Compile(code, context, c, debugger).Run(); CloneProperties(context, context.Scope.Obj, scope.Obj); context.Scope = scope; if (debugger != null) debugger.SetSourceCode(bkCode); return result; }); context.SetFunction("isNaN", (object value) => value == JsObject.NaN); JsObject instance = null; if (!_cache.ContainsKey(source)) { var csCode = GetCsCode(code, Parse(source, debugger != null, context)); Assembly asm = CSScript.LoadCode(csCode); var type = asm.GetType("C0"); var args = new List<object>(); context.Actions.ToList().ForEach(a => args.Add(a.Value)); args.Add(debugger); instance = (JsObject) Activator.CreateInstance(type, args.ToArray()); _cache[source] = instance; } else { instance = _cache[source]; } CloneProperties(context, context.Scope.Obj, instance); context.Scope.Obj = instance; return new Script(context); }
public Splitter(Context ctx) { Context.Logger.Info("Splitter constructor called"); this.ctx = ctx; // Declare Input and Output schemas Dictionary<string, List<Type>> inputSchema = new Dictionary<string, List<Type>>(); inputSchema.Add("default", new List<Type>() { typeof(string) }); Dictionary<string, List<Type>> outputSchema = new Dictionary<string, List<Type>>(); outputSchema.Add("default", new List<Type>() { typeof(string), typeof(char) }); this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, outputSchema)); // Demo how to get stormConf info if (Context.Config.StormConf.ContainsKey("topology.message.timeout.secs")) { msgTimeoutSecs = Convert.ToInt32(Context.Config.StormConf["topology.message.timeout.secs"]); } Context.Logger.Info("msgTimeoutSecs: {0}", msgTimeoutSecs); }
/// <summary> /// Implements of delegate "newPlugin", which is used to create a instance of this spout/bolt /// </summary> /// <param name="ctx">Context instance</param> /// <returns></returns> public static Splitter Get(Context ctx) { return new Splitter(ctx); }
public static Script Compile(Code code, Context context, string source) { return Compile(code, context, source, null); }
private Script(Context context) { _context = context; }
private static dynamic Parse(string source, bool debugMode, Context context) { dynamic tree = null; try { /*if(context.Scope.Obj != null) { source = string.Format("(function(){{{0}}})();", source); }*/ tree = new Esprima.NET.Esprima().Parse(new CsCodeGeneration(debugMode, context), source); } catch (Esprima.NET.Esprima.Error ex) { if (ex.Message.Contains("Invalid left-hand side in assignment")) throw new ReferenceError(ex.Message); throw new SyntaxError(ex.Message); } return tree; }
private static void CloneProperties(Context context, JsObject original, JsObject target) { if (original != null) { context.DeclaredVarNames.ForEach(v => { var originalProperty = original.GetType().GetProperty(v, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic); var targetProperty = target.GetType().GetProperty(v, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic); if (targetProperty != null) { if (originalProperty != null) targetProperty.SetValue(target, originalProperty.GetValue(original)); } else { if (originalProperty != null) target.DynamicProperties[v] = originalProperty.GetValue(original); } }); } }
/// <summary> /// Implements of delegate "newPlugin", which is used to create a instance of this spout/bolt /// </summary> /// <param name="ctx">Context instance</param> /// <returns></returns> public static Generator Get(Context ctx) { return new Generator(ctx); }
/// <summary> /// Implements of delegate "newPlugin", which is used to create a instance of this spout/bolt /// </summary> /// <param name="ctx">Context instance</param> /// <returns></returns> public static Counter Get(Context ctx) { return new Counter(ctx); }
public CsCodeGeneration(bool debugMode, Context context) { _debugMode = debugMode; _context = context; }
/// <summary> /// Implements of delegate "newPlugin", which is used to create a instance of this spout/bolt /// </summary> /// <param name="ctx">Context instance</param> /// <returns></returns> public static SimpleDRPC Get(Context ctx) { return new SimpleDRPC(ctx); }