Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 /// <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);
 }
Ejemplo n.º 6
0
 public static Script Compile(Code code, Context context, string source)
 {
     return Compile(code, context, source, null);
 }
Ejemplo n.º 7
0
 private Script(Context context)
 {
     _context = context;
 }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
 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);
             }
         });
     }
 }
Ejemplo n.º 10
0
 /// <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);
 }
Ejemplo n.º 11
0
 /// <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);
 }
Ejemplo n.º 12
0
 public CsCodeGeneration(bool debugMode, Context context)
 {
     _debugMode = debugMode;
     _context = context;
 }
Ejemplo n.º 13
0
 /// <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);
 }