Example #1
0
 void ExecuteAndUnloadScript(string script)
 {
     using (CSScriptLibrary.AsmHelper helper = new CSScriptLibrary.AsmHelper(CSScriptLibrary.CSScript.Compile(Path.GetFullPath(script), null, true), null, true))
     {
         helper.Invoke("*.Execute", this);
     }
 }
Example #2
0
    static void Main()
    {
        Assembly assembly = CSScript.LoadCode(
            @"using System;
              public class Calculator : ICalculator
              {
                  public int Add(int a, int b)
                  {
                      return a + b;
                  }

                  public string Join(string a, string b)
                  {
                      return a + b;
                  }
              }");

        AsmHelper calc = new AsmHelper(assembly);
        object instance = calc.CreateObject("Calculator"); //calc.CreateObject("*") can be used too if assembly has only one class defined
        FastInvokeDelegate methodInvoker = calc.GetMethodInvoker("Calculator.Add", 0, 0);

        int numOfLoops = 1000000;

        TestReflection(numOfLoops, calc, instance);
        TestFastInvoking(numOfLoops, calc, instance);
        TestDelegates(numOfLoops, methodInvoker, instance);
        TestInterface(numOfLoops, instance);
        TestInterfaceAlignment(numOfLoops, instance);
        TestDynamic(numOfLoops, instance);
        TestCompiledCode(numOfLoops);
        TestCompiledDelegate(numOfLoops);

        //TestMethodDelegates();
    }
Example #3
0
 void ExecuteAndUnloadScript(string script)
 {
     using (CSScriptLibrary.AsmHelper helper = new CSScriptLibrary.AsmHelper(CSScriptLibrary.CSScript.Compile(Path.GetFullPath(script), null, true), null, true))
     {
         helper.Invoke("*.Execute", this);
     }
 }
Example #4
0
		//static Regex torlinkRegex = new Regex(@"http://www1\.newstorrentsspace\.info/freeone/file\.php/.{7}\.html");

		static void Main(string[] args)
		{
			List<string> lsgurl = new List<string>();

			if (Directory.Exists("spider")) Directory.CreateDirectory("spider");
			Directory.GetFiles("spider","*.cs").ToList().ForEach(s =>
				{
					dynamic script = new AsmHelper(CSScript.Load(s)).CreateObject("SpiderHost.script.spider");
					lsgurl.AddRange(script.getUrls());
				});
			

			//Parallel.For(1, 2, (i =>
			//{
			//	lsgurl.Add("http://opp.hegc1024.com/pw/thread.php?fid=5&page=" + i);
			//}));

			//Parallel.For(1,2, ( i=>{
			//	lsgurl.Add("http://opp.hegc1024.com/pw/thread.php?fid=22&page=" + i);
			//}));


			dowload_av(lsgurl.ToArray());

			Console.ForegroundColor = ConsoleColor.Green;
			Console.WriteLine("Done!");
			Console.ForegroundColor = ConsoleColor.White;
			Console.ReadLine();


		}
Example #5
0
    static void Main()
    {
        CSScript.GlobalSettings.UseAlternativeCompiler = Path.GetFullPath("CSSCodeProvider.dll"); //compiler that understands JS/VB.NET/C++ and classless-C#

        var script = new AsmHelper(CSScript.Load("Hello.js"));
        script.Invoke("*.Main");
    }
Example #6
0
    void Start()
    {
        CreateDocument();

        var script = new AsmHelper(CSScript.Load("script.cs", null, true));
        script.Invoke("*.Execute", this);
    }
Example #7
0
 /// <summary>
 /// Executes the script and adds it to the current app domain
 /// NOTE: This locks the assembly script file
 /// </summary>
 public void ExecuteScriptInternal(String script, Boolean random)
 {
     if (!File.Exists(script)) throw new FileNotFoundException();
     String file = random ? Path.GetTempFileName() : null;
     AsmHelper helper = new AsmHelper(CSScript.Load(script, file, false, null));
     helper.Invoke("*.Execute");
 }
Example #8
0
 static void ExecuteAndUnloadScript(string script)
 {
     using (AsmHelper helper = new AsmHelper(CSScript.Compile(script), null, true))
     {
         helper.Invoke("*.Execute");
     }
 }
Example #9
0
 void ExecuteAndUnloadScript(string script)
 {
     using (AsmHelper helper = new AsmHelper(CSScript.Compile(script, Path.GetFullPath("ExternalAsm.dll")), null, true))
     {
         helper.Invoke("*.Execute");
     }
 }
Example #10
0
    static void Main()
    {
        Assembly assembly = CSScript.LoadCode(
            @"using System;
              public class Claculator : IClaculator
              {
                  public void Sum(int a, int b)
                  {
                      Console.WriteLine(a + b);
                  }

                  public void Multiply(int a, int b)
                  {
                      Console.WriteLine(a * b);
                  }
              }");

        AsmHelper script = new AsmHelper(assembly);
        object instance = script.CreateObject("Claculator");

        TypeUnsafeReflection(script, instance);
        TypeSafeInterface(instance);
        TypeSafeAlignedInterface(instance);
        TypeSafeDelegate(script, instance);
        TypeUnSafeDelegate(script, instance);
    }
Example #11
0
 private void CompileClasses(string code)
 {
     //    FileInfo fi = new FileInfo( @"C:\src\xgc3\xgc3\Generated.cs");
     //  string code = File.ReadAllText(fi.FullName);
     m_helper = new AsmHelper(CSScriptLibrary.CSScript.LoadCode(code)); //, null, true));
     //CreateInstance("test", "xgc3.Generated.Test");
 }
Example #12
0
 /// <summary>
 /// Executes the script in a seperate appdomain and then unloads it
 /// NOTE: This is more suitable for one pass processes
 /// </summary>
 public void ExecuteScriptExternal(String script)
 {
     if (!File.Exists(script)) throw new FileNotFoundException();
     using (AsmHelper helper = new AsmHelper(CSScript.Compile(script, null, true), null, true))
     {
         helper.Invoke("*.Execute");
     }
 }
    static void CallStaticMethodOfTheOnlyClassAvailableInClasslessScript()
    {
        CSScript.GlobalSettings.UseAlternativeCompiler =
            Environment.ExpandEnvironmentVariables(@"%CSSCRIPT_DIR%\Lib\CSSCodeProvider.dll");

        var helper = new AsmHelper(CSScript.Load("script1.ccs", null, true));
        helper.Invoke("*.SayHello", "Hello World!");
    }
    static void CallStaticMethodOfSpecifiedClassWithNamespaceInClasslessScript()
    {
        CSScript.GlobalSettings.UseAlternativeCompiler =
            Environment.ExpandEnvironmentVariables(@"%CSSCRIPT_DIR%\Lib\CSSCodeProvider.dll");

        var helper = new AsmHelper(CSScript.Load("script2.ccs", null, true));
        helper.Invoke("MyNamespace.MyClass.SayHello", "Hello World!");
    }
Example #15
0
        public ScriptingEngine( string code)
        {
            //    FileInfo fi = new FileInfo( @"C:\src\xgc3\xgc3\Generated.cs");
              //  string code = File.ReadAllText(fi.FullName);

            m_helper = new AsmHelper(CSScript.LoadCode(code) ); //, null, true));
            CreateInstance("test", "xgc3.Generated.Test");
        }
Example #16
0
    static void TypeSafeDelegate(AsmHelper script, object instance)
    {
        FastInvokeDelegate sumInvoker = script.GetMethodInvoker("Claculator.Sum", 0, 0); //type unsafe delegate
        Action<int, int> Sum = delegate(int a, int b) { sumInvoker(instance, a, b); }; //type safe delegate

        Sum(1, 2);
        Sum(4, 7);
    }
Example #17
0
    static void TestWithAsmHelper()
    {
        //Note usage of CreateObject("Script") is also acceptable

        var script = new AsmHelper(CSScript.Load("HelloScript.cs"))
                                           .CreateObject("*")
                                           .AlignToInterface<IScript>();

        script.Hello("Hi there...");
    }
Example #18
0
    static void CallStaticMethod1()
    {
        //AsmHelper allows accessing scripts methods with wild card
        Assembly assembly = CSScript.LoadMethod(
            @"public static void SayHello(string greeting)
              {
                  Console.WriteLine(greeting);
              }");

        AsmHelper script = new AsmHelper(assembly);
        script.Invoke("*.SayHello", "Hello World!");
    }
Example #19
0
    static void CallStaticMethod2()
    {
        //AsmHelper can generate "object FastInvokeDelegate(object instance, params object[] paramters)"
        //delegate which is more convenient to work with.
        FastInvokeDelegate SayHello = new AsmHelper(CSScript.LoadMethod(
            @"public static void SayHello(string greeting)
              {
                  Console.WriteLine(greeting);
              }"))
              .GetMethodInvoker("*.SayHello", "");

        SayHello(null, "Hello World!");
    }
Example #20
0
    static void CallInstanceMethod2()
    {
        Assembly assembly = CSScript.LoadMethod(
            @"public void SayHello(string greeting)
              {
                  Console.WriteLine(greeting);
              }");

        AsmHelper script = new AsmHelper(assembly);

        object instance = script.CreateObject("*"); //wild card * can be used as the assembly contains only one class defined
        script.InvokeInst(instance, "*.SayHello", "Hello World!");
    }
    static void CallStaticMethodOfDefaultClassInClasslessScript()
    {
        //There is a script file to execute.
        //The script consist of the only method definition.
        //Autoclass is injected by CS-Script engine and user has no control
        //on class name, which is always Scripting.DynamicClass

        CSScript.GlobalSettings.UseAlternativeCompiler =
            Environment.ExpandEnvironmentVariables(@"%CSSCRIPT_DIR%\Lib\CSSCodeProvider.dll");

        var helper = new AsmHelper(CSScript.Load("script1.ccs", null, true));
        helper.Invoke("script1.Script.SayHello", "Hello World!");
    }
Example #22
0
    static void Main()
    {
        var Sum = new AsmHelper(CSScript.LoadMethod(
            @"public static int Sum(int a, int b)
              {
                  System.Diagnostics.Debugger.Break();
                  Host.Log(""Calculating sum..."");
                  return a + b;
              }", null, true))
              .GetStaticMethod();

        int result = (int)Sum(1, 2);
    }
Example #23
0
    static void CallInstanceMethod1()
    {
        //all classless scripts belong to DynamicClass type generated by the CS-Script engine
        Assembly assembly = CSScript.LoadMethod(
            @"public void SayHello(string greeting)
              {
                  Console.WriteLine(greeting);
              }");

        AsmHelper script = new AsmHelper(assembly);

        object instance = script.CreateObject("Scripting.DynamicClass"); // or script.CreateObject("*")
        script.InvokeInst(instance, "Scripting.DynamicClass.SayHello", "Hello World!");
    }
Example #24
0
        /**
         * Lädt das CS-Script interpretiert als FireSequence und führt 
         * Sequence aus.
         * @returns String Nachricht
         */
        public String LoadScript(String className)
        {
            String msg = ""; //Rückgabenachricht

            // Script laden und interpretieren
            var scriptAssembly = CSScript.Load("./Scripts/" + className + ".cs");
            AsmHelper assemblyHelper = new AsmHelper(scriptAssembly);

            var fireSequence = (IFireSequence)assemblyHelper.CreateObject(className);

            msg += ExecuteFiringSequence(fireSequence);

            return msg;
        }
Example #25
0
 void Initialise()
 {
     InitializeComponent();
     upBtn.Text =
     downBtn.Text = "";
     if (Environment.Version.Major >= 2)
     {
         // the following code must be generated dynamically as ShellEx is guaranteed to be run 
         //under CLR 1.1 as part of the installation sequence (config.cs) and 1.1 cannot handle 
         //"this.treeView1.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.treeView1_DrawNode);"
         treeViewExtension = new AsmHelper(CSScript.LoadCode(treeViewExtensionCode, null, false, this.GetType().Assembly.Location));
         treeViewExtension.Invoke("*.Extend", treeView1);
     }
 }
Example #26
0
    static void CallStaticMethod3()
    {
        //AsmHelper can generate "object MethodDelegate(params object[] paramters)"
        //delegate which is more convenient to work with.
        //MethodDelegate is just specialized version of FastInvokeDelegate

        var SayHello = new AsmHelper(CSScript.LoadMethod(
            @"public static void SayHello(string greeting)
              {
                  Console.WriteLine(greeting);
              }"))
              .GetStaticMethod("*.SayHello", "");

        SayHello("Hello World!");
    }
    static void Run1()
    {
        var code =
            @"public static void Hello(string greeting)
              {
                  SayHello(greeting);
              }
              static void SayHello(string greeting)
              {
                  Console.WriteLine(greeting);
              }";

        var script = new AsmHelper(CSScript.LoadMethod(code)); // /call first Hello method found with Reflection based MethodInvoker
        script.Invoke("*.Hello", "Hello World!");
    }
Example #28
0
    public static void Main(string[] args)
    {
        try
        {
            // Create a new, empty permission set so we don't mistakenly grant some permission we don't want
            PermissionSet permissionSet = new PermissionSet(PermissionState.None);
            // Set the permissions that you will allow, in this case we only want to allow execution of code
            permissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
            // Make sure we have the permissions currently
            permissionSet.Demand();

            // Create the security policy level for this application domain
            PolicyLevel policyLevel = PolicyLevel.CreateAppDomainLevel();
            // Give the policy level's root code group a new policy statement based on the new permission set.
            policyLevel.RootCodeGroup.PolicyStatement = new PolicyStatement(permissionSet);

            CSScript.GlobalSettings.AddSearchDir(Environment.CurrentDirectory);

            File.Copy("Danger.cs", "Danger1.cs", true);
            var script = new AsmHelper(CSScript.Load("Danger.cs"));

            // Update the application domain's policy now
            AppDomain.CurrentDomain.SetAppDomainPolicy(policyLevel);

            var script1 = new AsmHelper(CSScript.Load("Danger1.cs"));

            Console.WriteLine();
            Console.WriteLine("Access local file from host application assembly...");
            using (FileStream f = File.Open("somefile.txt", FileMode.OpenOrCreate)) //OK because executing assembly was loaded before the new policy set
                Console.WriteLine("  Ok");
            Console.WriteLine();

            Console.WriteLine("Access local file from Script assembly (before security policy set)...");
            script.Invoke("*.SayHello"); //OK because executing assembly was loaded before the new policy set
            Console.WriteLine();

            Console.WriteLine("Access local file from Script assembly (after security policy set)...\n");
            script1.Invoke("*.SayHello"); //ERROR because executing assembly was loaded after the new policy set

            Console.WriteLine("The end...");
        }
        catch (Exception e)
        {
            Console.WriteLine();
            Console.WriteLine(e.Message);
            Console.WriteLine();
        }
    }
Example #29
0
    static void Main()
    {
        CSScript.GlobalSettings = new Settings(); //create default settings instance instead of using the one initialized from CS-Script installation (if present)

        var Sum = new AsmHelper(CSScript.LoadMethod(
           @"public static int Sum(int a, int b)
              {
                  Host.Log(""Calculating sum..."");
                  return a + b;
              }"))
             .GetStaticMethod();

        int result = (int)Sum(1, 2);

        Log("Result: " + result);
    }
        public static void ResetGrabber()
        {
          if (_asmHelper != null)
          {
            _asmHelper.Dispose();
            _asmHelper = null;
          }

          if (_movieImagesGrabber != null)
          {
            _movieImagesGrabber.SafeDispose();
            _movieImagesGrabber = null;
          }

          _movieImagesGrabberLoaded = false;
        }
Example #31
0
 private void validateToolStripMenuItem_Click(object sender, EventArgs e)
 {
   textBox_error.Text = "";
   try
   {
     Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
     CSScript.AssemblyResolvingEnabled = true;
     AsmHelper script =
       new AsmHelper(CSScriptLibrary.CSScript.LoadCode(textBox_code.Text, Path.GetTempFileName(), true));
     MessageBox.Show("No error");
   }
   catch (Exception ex)
   {
     textBox_error.Text = ex.Message;
   }
 }
Example #32
0
 void ExecuteScript(string script)
 {
     CSScriptLibrary.AsmHelper helper = new CSScriptLibrary.AsmHelper(CSScriptLibrary.CSScript.Load(script, null, true));
     helper.Invoke("*.Execute", this);
 }