Advertisement
filmee24

Scriptmanager

Jan 22nd, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.34 KB | None | 0 0
  1. Public Module ScriptManager
  2.  
  3.     Private _scripts As New List(Of Script)
  4.  
  5.     Public Sub LoadScripts()
  6.         For Each s In IO.Directory.GetFiles(Application.StartupPath & "\Scripts")
  7.             _scripts.Add(New Script(s))
  8.         Next
  9.     End Sub
  10.  
  11.     Public Function [Get](filename As String) As Script
  12.         For Each s In From s1 In _scripts Where s1.Filename = filename
  13.             Return s
  14.         Next
  15.         Return Nothing
  16.     End Function
  17.  
  18.     Public Sub Run(scriptname As String, method As String, ParamArray arguments As Object())
  19.         For Each l In _scripts
  20.             If l.Extension = ".vb" Or l.Extension = ".cs" Then
  21.                 Dim engine As New rScripting.CompileEngine(l.Extension)
  22.                 If l.Extension = ".vb" Then
  23.                     engine.Compiler = "vb"
  24.                 Else
  25.                     engine.Compiler = "C#"
  26.                 End If
  27.  
  28.                 engine.AddAssemblyReference("System.dll")
  29.                 engine.AddAssemblyReference("System.Core.dll")
  30.                 engine.AddAssemblyReference("System.Deployment.dll")
  31.                 engine.AddAssemblyReference("System.Windows.Forms.dll")
  32.                 engine.AddAssemblyReference("System.Drawing.dll")
  33.                 engine.AddAssemblyReference(Application.StartupPath & "\DotNetLib.dll")
  34.                 engine.AddAssemblyReference(Application.StartupPath & "\Calculator.exe")
  35.                 engine.AddAssemblyReference(Application.StartupPath & "\NeturalMath.dll")
  36.  
  37.                 l.compiled = engine.Compile({l.content})
  38.  
  39.                 If engine.HasErrors Then
  40.                     MsgBox(engine.Errors)
  41.                 End If
  42.  
  43.                 If l.compiled Then
  44.                     Dim obj As New rScripting.LateBinding.ScriptFactory(engine.CompiledAssembly)
  45.                     obj.GetScript(scriptname).InvokeMethod(method, arguments)
  46.                 End If
  47.             End If
  48.         Next
  49.     End Sub
  50.  
  51. End Module
  52. Public Class Script
  53.  
  54.     Sub New(script As String)
  55.         Filename = script
  56.         Extension = IO.Path.GetExtension(script)
  57.         content = My.Computer.FileSystem.ReadAllText(script)
  58.     End Sub
  59.  
  60.     Public Property Extension As String = ".cs"
  61.     Public Property Filename As String = ""
  62.     Public Property content As String = ""
  63.     Public Property compiled As Boolean = False
  64.  
  65. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement