UBIK Console
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.
Invalid language.
You need to specify a language like this: <source lang="html4strict">...</source>
Supported languages for syntax highlighting:
4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, arm, asm, asp, asymptote, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcl, dcpu16, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, freeswitch, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, haxe, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, ldif, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, nagios, netrexx, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, octave, oobas, oorexx, oracle11, oracle8, oxygene, oz, parasail, parigp, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, pys60, python, q, qbasic, rails, rebol, reg, rexx, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, spark, sparql, sql, stonescript, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, upc, urbi, uscript, vala, vb, vbnet, vedit, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic
>//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 = ai#2011"); 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.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 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.