Jump to: navigation, search

Difference between revisions of "UBIK Console"


 
(10 intermediate revisions by one other user not shown)
Line 1: Line 1:
The {{UBIK}} Console project allows a user to interact with UBIK via C# script-code.
+
{{Attention|UBIK Console is not available since 4.8}}
 +
 
 +
The {{UBIK}} Console allows a user to interact with UBIK via C# script-code.
  
 
== Concept ==
 
== Concept ==
Line 14: Line 16:
 
The console can either execute using Roslyn or Mono. By typing ''#mono'' or ''#roslyn'' you can switch between these engines. The default is 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 ==
+
== Example using Script file to connect to a Database ==
 
<source lang=csharp>
 
<source lang=csharp>
 
>//build up a connection to a UBIK database
 
>//build up a connection to a UBIK database
Line 29: Line 31:
 
>var metaclassOfPump = demo.Environment.UBIKDataFactory().MetaClass(new Guid("b81a9d31-03b2-4dbd-91aa-b62c499011f7"));
 
>var metaclassOfPump = demo.Environment.UBIKDataFactory().MetaClass(new Guid("b81a9d31-03b2-4dbd-91aa-b62c499011f7"));
  
>//find a content object (e.g. the first one found containing "PU212"
+
>//find a content object (e.g. the first one with the name "PU212")
>var myFavouritePump = metaclassOfPump.AllChilds().First(p => p.DisplayString.Contains("PU212"));
+
>var myFavouritePump = metaclassOfPump.AllInstances("PU212").FirstOrDefault();
  
>//show all propertyvalues
+
>//show all interesting propertyvalues
>foreach(var prop in myFavouritePump.Properties) //%
+
>foreach(var prop in myFavouritePump.Properties.Where(p => p.DisplayValue() != "")) //%
 
>{ //%
 
>{ //%
>    Console.WriteLine("{0} = {1}", prop.Description, prop.DisplayValue()); //%
+
>    Console.WriteLine("//{0} = {1}", prop.Description, prop.DisplayValue()); //%
 
>}
 
>}
 
 
//Shutdown finished = False
 
//Shutdown finished = False
 
//RPM = 2920
 
//RPM = 2920
Line 49: Line 50:
 
//Live Flow = (Flow1)
 
//Live Flow = (Flow1)
 
//Height = 750
 
//Height = 750
//Live Manz =
 
 
//Nominal Diameter DN2 = 60
 
//Nominal Diameter DN2 = 60
 
//Nominal Pressure PN2 = 20
 
//Nominal Pressure PN2 = 20
Line 56: Line 56:
 
//Impeller Diameter = 120
 
//Impeller Diameter = 120
 
//Nominal Pressure PN1 = 16
 
//Nominal Pressure PN1 = 16
//Extension Weller =
 
 
//Weight = 234
 
//Weight = 234
//ARMARKERID =
 
//TRANSLATIONY =
 
 
//Installation Level = 60
 
//Installation Level = 60
 
//Parent POI Group ID = DEMO_LEVEL_1 (Demo Level 1)
 
//Parent POI Group ID = DEMO_LEVEL_1 (Demo Level 1)
 
//Technical Status = 0
 
//Technical Status = 0
//RFID Tag =
 
 
//Organisational Status = 0
 
//Organisational Status = 0
 
//Type = KSB Kreiselpumpe
 
//Type = KSB Kreiselpumpe
//TRANSLATIONX =
 
 
//Layer ID = ML_PUMP (Pumps)
 
//Layer ID = ML_PUMP (Pumps)
//ROTAIONY =
 
//ISFACINGCAMERA =
 
 
//Position Number = A12345
 
//Position Number = A12345
 
//QR Code = PU212
 
//QR Code = PU212
//ROTAIONZ =
 
//Maintenance state =
 
//ROTAIONX =
 
 
//Order Number = SAP987456
 
//Order Number = SAP987456
 
//Barcode = PU212
 
//Barcode = PU212
 
//Marker ID = 2
 
//Marker ID = 2
 
//OCRText = PU212
 
//OCRText = PU212
//SCALEX =
 
//ARMARKERSIDELENGTH =
 
 
//Weblink = http://www.augmensys.com
 
//Weblink = http://www.augmensys.com
 
//Progress = 50
 
//Progress = 50
//TRANSLATIONZ =
 
 
//Manufacturer = KSB AG
 
//Manufacturer = KSB AG
 
//Weight = 6
 
//Weight = 6
 
//Maintenance finished = False
 
//Maintenance finished = False
 
//Geo data = 46,6152954101563;14,2624282836914;0
 
//Geo data = 46,6152954101563;14,2624282836914;0
//Visio group ID =
 
//LK to Structure =
 
 
//Scan = PU212
 
//Scan = PU212
//Order ID =
 
 
//SAP-ID = 210100092
 
//SAP-ID = 210100092
 
//Namespace = DemoHL
 
//Namespace = DemoHL
 
//Name = PU212
 
//Name = PU212
 
//Description = Effluent Discharge Pumpx
 
//Description = Effluent Discharge Pumpx
//Create Session =
+
//Created on = 22.07.2013 14:43:20
//Created on = 22.07.2018 14:43:20
+
 
//Delete status = 0
 
//Delete status = 0
 
//UTS = 27.11.2018 17:18:33
 
//UTS = 27.11.2018 17:18:33
//Update session = USER01@iphonex -- 27.11.2018 10:40:13
+
//Update session = MHM@unknown device -- 27.11.2018 10:40:13
//Tenant =
+
 
//Version = 983
 
//Version = 983
 +
>
 
>
 
>
 
</source>
 
</source>
 +
 +
== Example using Script file to connect to a UBIK Web Service==
 +
<source lang=csharp>
 +
>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
 +
</source>
 +
 +
  
 
== Example using Script file ==
 
== Example using Script file ==
Line 131: Line 128:
 
[[File:PwdTool.Encrypt.PNG]]
 
[[File:PwdTool.Encrypt.PNG]]
  
[[Category:Pages with broken file links|UBIK Console]]
+
[[Category:FAQ|UBIK Console]]

Latest revision as of 14:30, 1 July 2024

IC Attention.pngUBIK Console is not available since 4.8

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