#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- #include "..\Includes\DotNet.au3" #include "..\Includes\DotNetUtils.au3" Opt( "MustDeclareVars", 1) ;These 3 function calls are if we want to optimize the .NET Framework Host (do not need them if default suffices) ;Start() ;StartDomain() ;StopDomain() LoadAssembly() LoadCSCode() Local $DapperReference = "C:\Users\noah.applebaum\Desktop\AutoItToNET\AtoCLib\packages\Dapper.1.50.5\lib\netstandard2.0\Dapper.dll" Local $DataReference = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll" Local $LinqReference = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.Linq.dll" Local $LinqReference1 = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Linq.dll" Local $LinqReference3 = "C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\Microsoft.NETCore.UniversalWindowsPlatform\6.1.5\ref\uap10.0.15138\System.Linq.dll" Local $DataExtension = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.DataSetExtensions.dll" Local $SqlClientReference = "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.data.sqlclient\4.4.3\runtimes\win\lib\netstandard2.0\System.Data.SqlClient.dll" Local $WindowsFormsReference = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Windows.Forms.dll" Local $System = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll" Local $SystemCore = "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Core.dll" Global $AllReferences = $DapperReference & " | " & $DataReference & " | " & $SqlClientReference & " | " & $WindowsFormsReference & " | " & $LinqReference1 & " | " & $System & " | " & $SystemCore LoadDBCScode() Func Start() ; Start the latest version of .NET Framework ; DotNet_Start() is automatically called by the other functions in DotNet.au3 ; You only have to call DotNet_Start() if you need an older version of .NET Framework DotNet_Start() If @error Then Return ConsoleWrite( "DotNet_Start ERR" & @CRLF ) ConsoleWrite( "DotNet_Start OK" & @CRLF ) EndFunc Func StartDomain() Local $oMyDomain ; Creates and starts a user domain to run .NET code ; A default domain is automatically created by the other functions in DotNet.au3 ; You only need to call DotNet_StartDomain() if you want to specify a base directory for the domain DotNet_StartDomain( $oMyDomain ) If Not IsObj( $oMyDomain ) Then Return ConsoleWrite( "DotNet_StartDomain ERR" & @CRLF ) ConsoleWrite( "DotNet_StartDomain OK" & @CRLF ) DotNet_ListDomainsEx() EndFunc Func StopDomain() Local $oMyDomain DotNet_StartDomain( $oMyDomain, "MyDomain", "C:\Windows\Temp" ) If Not IsObj( $oMyDomain ) Then Return ConsoleWrite( "DotNet_StartDomain ERR" & @CRLF ) ConsoleWrite( "DotNet_StartDomain OK" & @CRLF ) DotNet_ListDomainsEx() ; Unloads .NET assemblies loaded into the user domain and stops the domain DotNet_StopDomain( $oMyDomain ) ConsoleWrite( "DotNet_StopDomain OK" & @CRLF ) DotNet_ListDomainsEx() DotNet_StartDomain( $oMyDomain, "MyDomain", "C:\Windows\Temp" ) If Not IsObj( $oMyDomain ) Then Return ConsoleWrite( "DotNet_StartDomain ERR" & @CRLF ) ConsoleWrite( "DotNet_StartDomain OK" & @CRLF ) DotNet_ListDomainsEx() ; Unloads .NET assemblies loaded into the user domain and stops the domain DotNet_StopDomain( $oMyDomain ) ConsoleWrite( "DotNet_StopDomain OK" & @CRLF ) DotNet_ListDomainsEx() EndFunc Func LoadAssembly() ; Loads a .NET assembly DLL-file into the default domain Local $classLib = DotNet_LoadAssembly( "..\..\AtoCLib\AtoCLib\bin\Debug\AtoCLib.dll" ) If @error Then Return ConsoleWrite( "DotNet_LoadAssembly ERR" & @CRLF ) ConsoleWrite( "DotNet_LoadAssembly OK" & @CRLF ) ;DotNet_ListDomainsEx() ;DotNet_ListAssembliesEx() #forceref $classLib EndFunc Func LoadCSCode() ; Compiles C# source code on the fly ; Creates a .NET assembly DLL-file in memory ; Loads the memory assembly file into the default domain Local $oCode = DotNet_LoadCScode( FileRead( "..\..\AtoCLib\AtoCLib\Class1.cs" )) If @error Then Return ConsoleWrite( "DotNet_LoadCScode ERR" & @CRLF ) ConsoleWrite( "DotNet_LoadCScode OK" & @CRLF ) Local $oClass1 = DotNet_CreateObject( $oCode, "AtoCLib.Class1" ) Local $oPatient = DotNet_CreateObject($oCode, "AtoCLib.Patient") Local $MRN = "x123" Local $patient = $oClass1.getPatient($MRN) Local $info = $patient.lName ;MsgBox(0, "dsf", $info) EndFunc Func LoadDBCScode() Local $oDBCode = DotNet_LoadCScode(FileRead("..\..\AtoCLib\AtoCLib\DataAccessLayer.cs"), $AllReferences ) If @error Then Return ConsoleWrite("DotNet_LoadCScode ERR" & @CRLF) ConsoleWrite( "DotNet_LoadCScode OK" & @CRLF ) Local $oConnect = DotNet_CreateObject($oDBCode, "AtoCLib.DataAccessLayer") Local $Customers = $oConnect.connect() If Not IsObj($Customers) Then MsgBox(0, "", "Customers is not an Object") EndFunc