Difference between revisions of "UBIK Console"
Line 14: | Line 14: | ||
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 == | ||
<source lang=csharp> | <source lang=csharp> | ||
>//build up a connection to a UBIK 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 = ****"); | >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=********') | + | //Connecting ('Data Source=AUGLNZ2SQL2016;Initial Catalog=UBIK.DEMO.262;Persist Security Info=True;User ID=sa;Password=********') |
− | Database version: 2.6.2.0 | + | //Database version: 2.6.2.0 |
− | Kernel version: 2.6.0.0 | + | //Kernel version: 2.6.0.0 |
− | Customizing version: 2.6.215 | + | //Customizing version: 2.6.215 |
− | Session mgmt. type: SingleLocal_Management | + | //Session mgmt. type: SingleLocal_Management |
− | USAM ignored. | + | //USAM ignored. |
− | bma (AUGBMA02) now connected to 'UBIK.DEMO.262'. | + | //bma (AUGBMA02) now connected to 'UBIK.DEMO.262'. |
>//get one of the metaclasses | >//get one of the metaclasses | ||
Line 37: | Line 38: | ||
>} | >} | ||
− | Shutdown finished = False | + | //Shutdown finished = False |
− | RPM = 2920 | + | //RPM = 2920 |
− | Flow rate = 68 | + | //Flow rate = 68 |
− | Nominal Diameter DN1 = 80 | + | //Nominal Diameter DN1 = 80 |
− | Protection = II 2 G c TX | + | //Protection = II 2 G c TX |
− | Nominal Power (Process) = 55 | + | //Nominal Power (Process) = 55 |
− | Static Head = 18 | + | //Static Head = 18 |
− | Nominal Power (electrical) = 50 | + | //Nominal Power (electrical) = 50 |
− | Live RPM = (RPM) | + | //Live RPM = (RPM) |
− | Live Flow = (Flow1) | + | //Live Flow = (Flow1) |
− | Height = 750 | + | //Height = 750 |
− | Live Manz = | + | //Live Manz = |
− | Nominal Diameter DN2 = 60 | + | //Nominal Diameter DN2 = 60 |
− | Nominal Pressure PN2 = 20 | + | //Nominal Pressure PN2 = 20 |
− | Variable Frequency Drive = False | + | //Variable Frequency Drive = False |
− | Volt = 400 | + | //Volt = 400 |
− | Impeller Diameter = 120 | + | //Impeller Diameter = 120 |
− | Nominal Pressure PN1 = 16 | + | //Nominal Pressure PN1 = 16 |
− | Extension Weller = | + | //Extension Weller = |
− | Weight = 234 | + | //Weight = 234 |
− | ARMARKERID = | + | //ARMARKERID = |
− | TRANSLATIONY = | + | //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 = | + | //RFID Tag = |
− | Organisational Status = 0 | + | //Organisational Status = 0 |
− | Type = KSB Kreiselpumpe | + | //Type = KSB Kreiselpumpe |
− | TRANSLATIONX = | + | //TRANSLATIONX = |
− | Layer ID = ML_PUMP (Pumps) | + | //Layer ID = ML_PUMP (Pumps) |
− | ROTAIONY = | + | //ROTAIONY = |
− | ISFACINGCAMERA = | + | //ISFACINGCAMERA = |
− | Position Number = A12345 | + | //Position Number = A12345 |
− | QR Code = PU212 | + | //QR Code = PU212 |
− | ROTAIONZ = | + | //ROTAIONZ = |
− | Maintenance state = | + | //Maintenance state = |
− | ROTAIONX = | + | //ROTAIONX = |
− | Order Number = SAP987456 | + | //Order Number = SAP987456 |
− | Barcode = PU212 | + | //Barcode = PU212 |
− | Marker ID = 2 | + | //Marker ID = 2 |
− | OCRText = PU212 | + | //OCRText = PU212 |
− | SCALEX = | + | //SCALEX = |
− | ARMARKERSIDELENGTH = | + | //ARMARKERSIDELENGTH = |
− | Weblink = http://www.augmensys.com | + | //Weblink = http://www.augmensys.com |
− | Progress = 50 | + | //Progress = 50 |
− | TRANSLATIONZ = | + | //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 = | + | //Visio group ID = |
− | LK to Structure = | + | //LK to Structure = |
− | Scan = PU212 | + | //Scan = PU212 |
− | Order ID = | + | //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 = | + | //Create Session = |
− | Created on = 22.07. | + | //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 = | + | //Update session = USER01@iphonex -- 27.11.2018 10:40:13 |
− | Tenant = | + | //Tenant = |
− | Version = 983 | + | //Version = 983 |
> | > | ||
</source> | </source> |
Revision as of 14:00, 30 November 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
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
>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 found containing "PU212"
>var myFavouritePump = metaclassOfPump.AllChilds().First(p => p.DisplayString.Contains("PU212"));
>//show all propertyvalues
>foreach(var prop in myFavouritePump.Properties) //%
>{ //%
> 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
//Live Manz =
//Nominal Diameter DN2 = 60
//Nominal Pressure PN2 = 20
//Variable Frequency Drive = False
//Volt = 400
//Impeller Diameter = 120
//Nominal Pressure PN1 = 16
//Extension Weller =
//Weight = 234
//ARMARKERID =
//TRANSLATIONY =
//Installation Level = 60
//Parent POI Group ID = DEMO_LEVEL_1 (Demo Level 1)
//Technical Status = 0
//RFID Tag =
//Organisational Status = 0
//Type = KSB Kreiselpumpe
//TRANSLATIONX =
//Layer ID = ML_PUMP (Pumps)
//ROTAIONY =
//ISFACINGCAMERA =
//Position Number = A12345
//QR Code = PU212
//ROTAIONZ =
//Maintenance state =
//ROTAIONX =
//Order Number = SAP987456
//Barcode = PU212
//Marker ID = 2
//OCRText = PU212
//SCALEX =
//ARMARKERSIDELENGTH =
//Weblink = http://www.augmensys.com
//Progress = 50
//TRANSLATIONZ =
//Manufacturer = KSB AG
//Weight = 6
//Maintenance finished = False
//Geo data = 46,6152954101563;14,2624282836914;0
//Visio group ID =
//LK to Structure =
//Scan = PU212
//Order ID =
//SAP-ID = 210100092
//Namespace = DemoHL
//Name = PU212
//Description = Effluent Discharge Pumpx
//Create Session =
//Created on = 22.07.2018 14:43:20
//Delete status = 0
//UTS = 27.11.2018 17:18:33
//Update session = USER01@iphonex -- 27.11.2018 10:40:13
//Tenant =
//Version = 983
>
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.