Difference between revisions of "UBIK Console"
Line 3: | Line 3: | ||
== Concept == | == Concept == | ||
C# code will be interpreted like script code. This script can be either loaded from file and executed at start up or directly typed into a console window. When starting up the console it will automatically execute some common using statements in order to comfortably with code from these assemblies: System, UBIK, UBIK.Kernel, System.Collections.Generic, UBIK.Dynamic, System.Linq. If you need other namespaces you need to load them in your code. | C# code will be interpreted like script code. This script can be either loaded from file and executed at start up or directly typed into a console window. When starting up the console it will automatically execute some common using statements in order to comfortably with code from these assemblies: System, UBIK, UBIK.Kernel, System.Collections.Generic, UBIK.Dynamic, System.Linq. If you need other namespaces you need to load them in your code. | ||
+ | |||
+ | [[File:UBIK.Console.PNG|500px|]] | ||
== Using the console == | == Using the console == |
Revision as of 14:50, 23 April 2018
The UBIK® Console project allows a user to interact with UBIK via C# script-code.
Contents
Concept
C# code will be interpreted like script code. This script can be either loaded from file and executed at start up or directly typed into a console window. When starting up the console it will automatically execute some common using statements in order to comfortably with code from these assemblies: System, UBIK, UBIK.Kernel, System.Collections.Generic, UBIK.Dynamic, System.Linq. If you need other namespaces you need to load them in your code.
Using the console
By simply executing UBIK.Console.exe
Semikolon or not, that is the question
Mono and Roslyn
Example using Script file
In order to execute a C# script file using the UBIK® Console you need execute the UBIK.Console.exe using the -cmdfile parameter. If you add the -connectionstring parameter as shown in the example the console will instantiate UBIKEnvironmentConnection variable called ubikEnvironmentConnection. This variable is then accessible in your script and can be used. Also the current customizing assembly will be added to the script.
The following script code is taken from the example script file and shows how to work with UBIK® Console via script file. If you store these six lines to a text file you can directly run it. In line one a new dependency is loaded, namely the DBTool. Line two creates a SqlConnectionStringBuilder in order to work comfortably with the connectionstring provided by ubikEnvironmentConnection. Line four calls a method from the customizing assembly which has been loaded by the console for us as mention earlier. Line 6 uses the DBTool project and creates a backup of the database.
2. System.Data.SqlClient.SqlConnectionStringBuilder scsb = new System.Data.SqlClient.SqlConnectionStringBuilder(ubikEnvironmentConnection.ConnectionString);
3. string backUpDir = @"C:\SQL\bakup";
4. bool isTrue = UBIK.Runtime.WorkflowUtility.Str2Bool("1");
5. System.Console.WriteLine(isTrue.ToString());
6. DBTool.MSSQLTools.BackupDatabase(scsb.DataSource, scsb.UserID, scsb.Password, false, scsb.InitialCatalog, bak: string.Format(@"{0}\{1}_{2}_{3}.bak", backUpDir, scsb.InitialCatalog, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmm")));
CmdLine
PwdTool
If you do not want to type in your password in plain text you can first generate an encrypted password by executing Pwd.Encrpyt in the UBIK® Console.