Exemplo n.º 1
0
        public override void Evaluate(IScriptContext context)
        {
            if (TypeExpr == null && GenericsPostfix == null)
            {
                context.Result = RuntimeHost.GetType(Identifier);
                return;
            }

            if (TypeExpr != null)
            {
                string name = string.Format("{0}.{1}", EvaluateName(TypeExpr), Identifier);
                Type   type = null;

                if (GenericsPostfix != null)
                {
                    Type genericType = RuntimeHost.GetType(GenericsPostfix.GetGenericTypeName(name));
                    GenericsPostfix.Evaluate(context);
                    type = genericType.MakeGenericType((Type[])context.Result);
                }
                else
                {
                    type = RuntimeHost.GetType(name);
                }

                context.Result = type;
            }
            else
            {
                Type genericType = RuntimeHost.GetType(Identifier);
                GenericsPostfix.Evaluate(context);
                context.Result = genericType.MakeGenericType((Type[])context.Result);
            }
        }
Exemplo n.º 2
0
        public object Invoke(IScriptContext context, object[] args)
        {
            string    code   = (String)args[0];
            ScriptAst result = null;

            LanguageCompiler compiler = (LanguageCompiler)context.GetItem("Compiler", true);

            RuntimeHost.Lock();

            try
            {
                result = Script.Parse(code + ";", false) as ScriptAst;
                //TODO: Create LocalOnlyScope that can't change Parent's variables
                //No, need for doing these. It is already done
                context.CreateScope();
            }
            finally
            {
                RuntimeHost.UnLock();
            }

            result.Evaluate(context);
            context.RemoveLocalScope();

            return(context.Result);
        }
Exemplo n.º 3
0
        public void MethodInvocationBug()
        {
            RuntimeHost.AddType("TestOverloading", typeof(TestOverloading));
            object rez = Script.RunCode("b = new TestOverloading(); return b.GetString(2);");

            Assert.Equal("Ok", rez);
        }
Exemplo n.º 4
0
 public void ShouldChangeInitializationState()
 {
     Assert.False(RuntimeHost.IsInitialized);
     RuntimeHost.Initialize();
     Assert.True(RuntimeHost.IsInitialized);
     RuntimeHost.CleanUp();
     Assert.False(RuntimeHost.IsInitialized);
 }
Exemplo n.º 5
0
        private RuntimeHost GetAndSetupRuntimeHost()
        {
            List <Type> controllers = GetControllersWithReflection();

            RuntimeHost runtimeHost = RuntimeHost.GetRuntimeHost(this.Server, controllers);

            return(runtimeHost);
        }
Exemplo n.º 6
0
 private static void Main(string[] pArgs)
 {
     RegisterFileAssociation(".fsb", "FiestaShark", "FiestaShark Binary File", Assembly.GetExecutingAssembly().Location, string.Empty, 0);
     RuntimeHost.Initialize();
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new MainForm(pArgs));
 }
Exemplo n.º 7
0
 public void ParamsKeywordIsNotSupported()
 {
     Assert.Throws <ScriptMethodNotFoundException>(() =>
     {
         RuntimeHost.AddType("ParamsLimitation", typeof(ParamsLimitation));
         Assert.False(
             (bool)Script.RunCode("ParamsLimitation.Test(1,2,3,4);"));
     });
 }
Exemplo n.º 8
0
        public void TestTypeExprGenerics()
        {
            RuntimeHost.AddType("Int", typeof(int));
            ScriptContext context = new ScriptContext();

            object rez = Script.RunCode("a = new List<|Int|>(); return a is List<|Int|>;", context);

            Assert.IsTrue((bool)rez);
        }
Exemplo n.º 9
0
        public void TestTypeExpr()
        {
            RuntimeHost.AddType("Int", typeof(int));
            ScriptContext context = new ScriptContext();

            object rez = Script.RunCode("a = 2; return a is Int;", context);

            Assert.IsTrue((bool)rez);
        }
Exemplo n.º 10
0
        public void ConsoleTest()
        {
            RuntimeHost.AddType("Console", typeof(ConsoleMock));

            string expected = "Value of x is 10 and y is 20";
            string actual   = Script.RunCode("return Console.WriteLine(\"Value of x is {0} and y is {1}\", 10, 20);").ToString();

            Assert.Equal(expected, actual);
        }
        internal void BuildObjectGraph(Action shutdown)
        {
            const int FIVE_SECONDS   = 5000;
            const int THIRTY_SECONDS = 30000;

            var args          = Environment.GetCommandLineArgs();
            var nativeMethods = new NativeMethods();

            logger     = new Logger();
            systemInfo = new SystemInfo();

            InitializeConfiguration();
            InitializeLogging();
            InitializeText();

            var messageBox     = new MessageBox(text);
            var desktopFactory = new DesktopFactory(ModuleLogger(nameof(DesktopFactory)));
            var explorerShell  = new ExplorerShell(ModuleLogger(nameof(ExplorerShell)), nativeMethods);
            var processFactory = new ProcessFactory(ModuleLogger(nameof(ProcessFactory)));
            var proxyFactory   = new ProxyFactory(new ProxyObjectFactory(), logger);
            var runtimeHost    = new RuntimeHost(appConfig.RuntimeAddress, new HostObjectFactory(), ModuleLogger(nameof(RuntimeHost)), FIVE_SECONDS);
            var serviceProxy   = new ServiceProxy(appConfig.ServiceAddress, new ProxyObjectFactory(), ModuleLogger(nameof(ServiceProxy)));
            var sessionContext = new SessionContext();
            var uiFactory      = new UserInterfaceFactory(text);

            var bootstrapOperations = new Queue <IOperation>();
            var sessionOperations   = new Queue <IRepeatableOperation>();

            bootstrapOperations.Enqueue(new I18nOperation(logger, text, textResource));
            bootstrapOperations.Enqueue(new CommunicationHostOperation(runtimeHost, logger));

            sessionOperations.Enqueue(new SessionInitializationOperation(configuration, logger, runtimeHost, sessionContext));
            sessionOperations.Enqueue(new ConfigurationOperation(args, configuration, new HashAlgorithm(), logger, sessionContext));
            sessionOperations.Enqueue(new ClientTerminationOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, THIRTY_SECONDS));
            sessionOperations.Enqueue(new KioskModeTerminationOperation(desktopFactory, explorerShell, logger, processFactory, sessionContext));
            sessionOperations.Enqueue(new ServiceOperation(logger, runtimeHost, serviceProxy, sessionContext, THIRTY_SECONDS));
            sessionOperations.Enqueue(new KioskModeOperation(desktopFactory, explorerShell, logger, processFactory, sessionContext));
            sessionOperations.Enqueue(new ClientOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, THIRTY_SECONDS));
            sessionOperations.Enqueue(new SessionActivationOperation(logger, sessionContext));

            var bootstrapSequence = new OperationSequence(logger, bootstrapOperations);
            var sessionSequence   = new RepeatableOperationSequence(logger, sessionOperations);

            RuntimeController = new RuntimeController(
                appConfig,
                logger,
                messageBox,
                bootstrapSequence,
                sessionSequence,
                runtimeHost,
                serviceProxy,
                sessionContext,
                shutdown,
                text,
                uiFactory);
        }
Exemplo n.º 12
0
        public void Function_OverloadsWithConflictingTypes()
        {
            RuntimeHost.AddType("TestTypeConversion", typeof(TestTypeConversion));

            object rez = Script.RunCode(@"
         x=true; y =1; return TestTypeConversion.WriteLine('Value of x {0} and y {1}',x,y);
      ");

            Assert.AreEqual("Value of x True and y 1", rez);
        }
Exemplo n.º 13
0
        public void AssemblyManagerFiltersTypes()
        {
            RuntimeHost.InitializingTypes += RuntimeHostInitializingTypes;
            RuntimeHost.Initialize(TestConfig);

            Assert.True(RuntimeHost.AssemblyManager.HasNamespace("UnitTests"));
            Assert.False(RuntimeHost.AssemblyManager.HasNamespace("System.Text"));

            RuntimeHost.CleanUp();
        }
 private static IEnumerable <AssemblyName> FindAssembliesInGac(params string[] names)
 {
     foreach (var name in names)
     {
         foreach (var assemblyName in RuntimeHost.FindAssemblies(name))
         {
             yield return(assemblyName);
         }
     }
 }
Exemplo n.º 15
0
        public void IndexerDefinedByExplicitInterface()
        {
            Script script = Script.Compile(@"
          s = new SQLiteDataReader();
          return s['Test Value'];");

            RuntimeHost.AddType("SQLiteDataReader", typeof(SQLiteDataReader));

            Assert.Equal(10, script.Execute());
        }
Exemplo n.º 16
0
        public void Initialize()
        {
            hostObject        = new Mock <IHostObject>();
            hostObjectFactory = new Mock <IHostObjectFactory>();
            logger            = new Mock <ILogger>();

            hostObjectFactory.Setup(f => f.CreateObject(It.IsAny <string>(), It.IsAny <ICommunication>())).Returns(hostObject.Object);

            sut = new RuntimeHost("net:pipe://some/address", hostObjectFactory.Object, logger.Object, 0);
        }
Exemplo n.º 17
0
        public ScriptIsExpr(AstNodeArgs args)
            : base(args)
        {
            Debug.Assert(oper == "is");

            @operator = RuntimeHost.GetBinaryOperator(oper);
            if (@operator == null)
            {
                throw new ScriptException("RuntimeHost did not initialize property. Can't find binary operators.");
            }
        }
Exemplo n.º 18
0
        public ScriptIsExpr(AstNodeArgs args)
            : base(args)
        {
            Debug.Assert(Oper == "is");

            _operator = RuntimeHost.GetBinaryOperator(Oper);
            if (_operator == null)
            {
                throw new ScriptRuntimeException(string.Format(Strings.MissingOperatorError, "is"));
            }
        }
Exemplo n.º 19
0
        public void DisableBindingToStringMethod()
        {
            RuntimeHost.Binder = new MyBinder();
            RuntimeHost.Initialize(TestConfig);

            Script script = Script.Compile(@"
            b = 'a';
            b.ToString();
       ");

            script.Execute();
        }
Exemplo n.º 20
0
        public void DisableBindingToStringMethod()
        {
            RuntimeHost.Binder = new MyBinder();
            RuntimeHost.Initialize(TestConfig);

            Script script = Script.Compile(@"
            b = 'a';
            b.ToString();
       ");

            Assert.Throws <ScriptMethodNotFoundException>(() => script.Execute());
        }
Exemplo n.º 21
0
        public void CustomOperatorHandling()
        {
            RuntimeHost.Initialize(TestConfig);
            RuntimeHost.RegisterOperatorHandler("$", new DollarHandler());

            Script script = Script.Compile(@"
              return $'1234';
       ");
            object rez    = script.Execute();

            Assert.Equal(1234, rez);
        }
Exemplo n.º 22
0
        public void GenericTypes()
        {
            RuntimeHost.AddType("Generic", typeof(Generic <>));
            ScriptContext context = new ScriptContext();
            Script        script  = Script.Compile(@"
          return Generic<|int|>.TypeName;
      ");

            object result = script.Ast.Execute(context);

            Assert.AreEqual(Generic <int> .TypeName, result);
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            RuntimeHost.Initialize();
            RuntimeHost.AddType <Person>("Person");

            object o = Script.RunCode(@"
 
N = 100;
l = new List<|int|>(N);
for (i = 0; i < N; i++) l.Add(i);

function calc(x){
  return 1;
}

for (j = 0; j < 5; j++){

 sw = Stopwatch.StartNew();
// s2 = l.AsParallel<|int|>().Sum<|int|>(calc);
// Console.WriteLine('Time for parallel:' +sw.ElapsedMilliseconds+' result:'+s2);

 sw = Stopwatch.StartNew();
 //s1 = l.Sum<|int|>(calc);
 //Console.WriteLine('Time for 1 thread:' + sw.ElapsedMilliseconds+' result:'+s1);

}

al = ArrayList.Synchronized(new ArrayList());
l.AsParallel<|int|>().ForAll<|int|>(function(l1){ al.Add( l1*l1 ); });

");

            //string test_01 = "for (i = 0; i <= 100000; i++) { }";
            //string test_02 = "for (i = 0; i <= 100000; i = i + 1) { }";
            string test_03 = "for (i = 0; i <= 100000; i++) {  i.ToString(); }";

            //string test_04 = "a = [1,2,3]; x = 0; for (i = 0; i < 100000; i++) { x = a[1]; }";
            //string test_05 = "a = [1,2,3]; for (i = 0; i < 100000; i++) { a[0] = i; }";
            //string test_06 = "x = null; p = new Person(); for (i = 0; i < 100000; i++) { x = p[\"testme\"]; }";
            //string test_07 = "x = null; p = new Person(); for (i = 0; i < 100000; i++) { p[\"name\"] = \"test\"; }";
            //string test_08 = "for (i = 0; i <= 100000; i++) { i.ToString(null); }";
            //string test_09 = "p = new Person(); for (i = 0; i <= 100000; i++) { p.Name = \"Denis\"; }";
            //string test_10 = "p = new CustomObject(); for (i = 0; i <= 100000; i++) { p.Name = \"Denis\"; }";
            TestCode("Performance_40_03__.txt", test_03, 50);

            //string code = "p = new dynamic(); p.Name = \"Denis Vuyka\"; p.Age = 28; Console.WriteLine(p.Name); Console.WriteLine(p.Age);";
            //string code = "Console.WriteLine(1 == 1);";
            //Script.RunCode(code);

            Console.WriteLine("Press a key to exit");
            Console.ReadKey();
        }
Exemplo n.º 24
0
        public ScriptBinExpr(AstNodeArgs args)
            : base(args)
        {
            left  = (ScriptExpr)ChildNodes[0];
            oper  = ((Token)ChildNodes[1]).Text;
            right = (ScriptExpr)ChildNodes[2];

            operatorFunction = RuntimeHost.GetBinaryOperator(oper);
            if (operatorFunction == null)
            {
                throw new ScriptException("RuntimeHost did not initialize property. Can't find binary operators.");
            }
        }
Exemplo n.º 25
0
        public void PlusEqualOperator()
        {
            Script rez = Script.Compile(@"
         a = new SumOp();
         a.a += 2;   

         return a.a;  
       ");

            RuntimeHost.AddType("SumOp", typeof(SumOp));

            Assert.Equal(2, rez.Execute());
        }
Exemplo n.º 26
0
        public void BaseAssemblyAddingRemovingAssembly()
        {
            RuntimeHost.AssemblyManager = new BaseAssemblyManager();
            RuntimeHost.Initialize(TestConfig);

            Assert.False(RuntimeHost.AssemblyManager.HasNamespace("UnitTests"));
            RuntimeHost.AssemblyManager.AddAssembly(typeof(Runtime).Assembly);
            Assert.True(RuntimeHost.AssemblyManager.HasNamespace("UnitTests"));
            RuntimeHost.AssemblyManager.RemoveAssembly(typeof(Runtime).Assembly);
            Assert.False(RuntimeHost.AssemblyManager.HasNamespace("UnitTests"));

            RuntimeHost.CleanUp();
        }
Exemplo n.º 27
0
        public void ISupportAssignTest()
        {
            RuntimeHost.AddType("Point", typeof(TestPoint));
            Script script = Script.Compile(@"
        mObj = [ Text -> 'Hello' , X -> 10, Y -> 150];
        point = new Point(20,300);  
        point:= mObj;
        point.X;");

            object rez = script.Execute();

            Assert.AreEqual(10, rez);
        }
Exemplo n.º 28
0
        private static void Main(string[] pArgs)
        {
            RegisterFileAssociation(".msb", "MapleShark", "MapleShark Binary File", Assembly.GetExecutingAssembly().Location, string.Empty, 0);

            //FileStream fs = new FileStream("Log.txt", FileMode.Create);
            //StreamWriter sw = new StreamWriter(fs);
            //Console.SetOut(sw);

            RuntimeHost.Initialize();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm(pArgs));
        }
Exemplo n.º 29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RuntimeHost runtimeHost = GetAndSetupRuntimeHost();

            if (runtimeHost.NotStarted)
            {
                Response.Output.WriteLine("Server was set not to start. Please check your configuration files.");
                Response.End();
                return;
            }

            HandleCallActionResult(
                runtimeHost.CallAction(Request, Session, Page.RouteData));
        }
Exemplo n.º 30
0
        public ScriptAssignExpr(AstNodeArgs args)
            : base(args)
        {
            nameExpr = (ScriptQualifiedName)args.ChildNodes[0];
            oper     = ((Token)args.ChildNodes[1]).Text;
            if (args.ChildNodes.Count == 3)
            {
                rightExpr = (ScriptExpr)args.ChildNodes[2];
            }

            Debug.Assert(oper == "=" || oper == ":=" || oper == "+=" || oper == "-=" || oper == "++" || oper == "--" || oper == ":=");

            switch (oper)
            {
            case "=":
                assignOperation = Assign;
                break;

            case ":=":
                assignOperation = AssignEx;
                break;

            case "++":
                assignOperation = PlusPlus;
                break;

            case "--":
                assignOperation = MinusMinus;
                break;

            case "+=":
                assignOperation = PlusEqual;
                break;

            case "-=":
                assignOperation = MinusEqual;
                break;

            default:
                throw new ScriptException("Assignment operator:" + oper + " is not supported");
            }

            minus = RuntimeHost.GetBinaryOperator("-");
            plus  = RuntimeHost.GetBinaryOperator("+");

            if (plus == null || minus == null)
            {
                throw new ScriptException("RuntimeHost did not initialize property. Can't find binary operators.");
            }
        }
Exemplo n.º 31
0
		private void btnLaunch_Click(object sender, EventArgs e)
		{
			// Create an instance of the OpenSpan Runtime, passing in the global ServiceContainer
			mRuntimeHost = new RuntimeHost(mServiceContainer);

			// Listen for notification that the project has started
			mRuntimeHost.Started += new ContextEventHandler(RuntimeHost_Started);

			// Listen for notification that the project has stopped
			mRuntimeHost.Stopped += new EventHandler(RuntimeHost_Stopped);

			// Load the SampleSolution from the application directory
			mRuntimeHost.ProjectPath = @"SampleSolution.OpenSpan";

			// Start the OpenSpan Runtime
			mRuntimeHost.Start();
		}