Jump to: navigation, search

UBIK Console


The UBIK® Console allows a user to interact with UBIK via C# script-code.

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.

UBIK.Console.PNG

Using the console

As UBIK.Console is a command line application without any graphical user interface, it can be started in two ways:

  • Start UBIK.Console.exe which will open a commandline interface
  • Start directly out of a windows command line (e.g. powershell or cmd.exe)

Mono and Roslyn

The console can either execute using Roslyn or Mono. By typing #mono or #roslyn you can switch between these engines. The default is Roslyn.

Example using Script file to connect to a Database

>//build up a connection to a UBIK database
>var demo = new UBIKEnvironmentConnection("Data Source = AUGLNZ2SQL2016; Initial Catalog = UBIK.DEMO.262; Persist Security Info = True; User ID = sa; Password = ****");
//Connecting ('Data Source=AUGLNZ2SQL2016;Initial Catalog=UBIK.DEMO.262;Persist Security Info=True;User ID=sa;Password=********')
//Database version: 2.6.2.0
//Kernel version: 2.6.0.0
//Customizing version: 2.6.215
//Session mgmt. type: SingleLocal_Management
//USAM ignored.
//bma (AUGBMA02) now connected to 'UBIK.DEMO.262'.

>//get one of the metaclasses
>var metaclassOfPump = demo.Environment.UBIKDataFactory().MetaClass(new Guid("b81a9d31-03b2-4dbd-91aa-b62c499011f7"));

>//find a content object (e.g. the first one with the name "PU212")
>var myFavouritePump = metaclassOfPump.AllInstances("PU212").FirstOrDefault();

>//show all interesting propertyvalues
>foreach(var prop in myFavouritePump.Properties.Where(p => p.DisplayValue() != "")) //%
>{ //%
>    Console.WriteLine("//{0} = {1}", prop.Description, prop.DisplayValue()); //%
>}
//Shutdown finished = False
//RPM = 2920
//Flow rate = 68
//Nominal Diameter DN1 = 80
//Protection = II 2 G c TX
//Nominal Power (Process) = 55
//Static Head = 18
//Nominal Power (electrical) = 50
//Live RPM = (RPM)
//Live Flow = (Flow1)
//Height = 750
//Nominal Diameter DN2 = 60
//Nominal Pressure PN2 = 20
//Variable Frequency Drive = False
//Volt = 400
//Impeller Diameter = 120
//Nominal Pressure PN1 = 16
//Weight = 234
//Installation Level = 60
//Parent POI Group ID = DEMO_LEVEL_1 (Demo Level 1)
//Technical Status = 0
//Organisational Status = 0
//Type = KSB Kreiselpumpe
//Layer ID = ML_PUMP (Pumps)
//Position Number = A12345
//QR Code = PU212
//Order Number = SAP987456
//Barcode = PU212
//Marker ID = 2
//OCRText = PU212
//Weblink = http://www.augmensys.com
//Progress = 50
//Manufacturer = KSB AG
//Weight = 6
//Maintenance finished = False
//Geo data = 46,6152954101563;14,2624282836914;0
//Scan = PU212
//SAP-ID = 210100092
//Namespace = DemoHL
//Name = PU212
//Description = Effluent Discharge Pumpx
//Created on = 22.07.2013 14:43:20
//Delete status = 0
//UTS = 27.11.2018 17:18:33
//Update session = MHM@unknown device -- 27.11.2018 10:40:13
//Version = 983
>
>

Example using Script file to connect to a UBIK Web Service

>var demo = new UBIKServiceConnection("console", "ubik", "*****", "APP_DEMO", "CXT_DEMO", "https://52.178.138.55:777/UBIK/DEMO.250/Usam/USAM.svc/SOAP", "https://52.178.138.55:777/UBIK/DEMO.250/Content/UBIKContent.svc/SOAP");
>var rootObjects = demo.GetRoot();
Fetching root objects.
Fetching token for 'ubik@console' from 'https://52.178.138.55:777/UBIK/DEMO.250/Usam/USAM.svc/SOAP'.
ok (105 ms).
Service request delivered 4 objects (218 ms).
>@"\\" + string.Join(", ", rootObjects.Select(item => item.DisplayStrings[0]))
\\Plant, Inspection, Playground, Commissioning


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.

UBIK.Console.exe  -cmdfile "\\PathToScript\script.txt" -connectionstring "Data Source = ...; Initial Catalog = ...; User ID = ...; Password = ..."

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.

1. #r "C:\\Users\\cle\\Documents\\Dev\\UBIK.Server\\Branches\\2.6\\UBIK.Console\\bin\\Debug\\DBTool.exe"
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

CmdLine.Execute.PNG

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.

PwdTool.Encrypt.PNG