|  | 
|  | 1 | +/// Utility methods | 
|  | 2 | +Class isc.barcode.Utils | 
|  | 3 | +{ | 
|  | 4 | + | 
|  | 5 | +/// Main class to import | 
|  | 6 | +Parameter JARPATH = "C:\java\barcode.jar"; | 
|  | 7 | + | 
|  | 8 | +Parameter CLASS = "isc.barcode"; | 
|  | 9 | + | 
|  | 10 | +/// Gateway name to create/use | 
|  | 11 | +Parameter GATEWAY = "jtest"; | 
|  | 12 | + | 
|  | 13 | +/// Load Jar from path. | 
|  | 14 | +/// w ##class(isc.barcode.Utils).UpdateJar() | 
|  | 15 | +/// Write $System.Status.GetErrorText(##class(isc.barcode.Utils).UpdateJar()) | 
|  | 16 | +ClassMethod UpdateJar(gatewayName = {..#GATEWAY}, path As %String = {..#JARPATH}) | 
|  | 17 | +{ | 
|  | 18 | +	#dim sc As %Status = $$$OK | 
|  | 19 | +	//Set sc = ##class(Ens.Director).StopProduction(, 1) | 
|  | 20 | +	quit:$$$ISERR(sc) sc | 
|  | 21 | +	 | 
|  | 22 | +	//Set sc = ##class(%Net.Remote.Service).StopGateway(gatewayName) | 
|  | 23 | +	quit:$$$ISERR(sc) sc | 
|  | 24 | + | 
|  | 25 | +	set gateway = ..Connect(gatewayName, path, .sc) | 
|  | 26 | +	quit:$$$ISERR(sc) sc | 
|  | 27 | + | 
|  | 28 | +	set sc = gateway.%Import(..#CLASS) | 
|  | 29 | +	quit:$$$ISERR(sc) sc | 
|  | 30 | +	set:'##class(%Dictionary.CompiledClass).%ExistsId(..#CLASS) sc = $$$ERROR($$$GeneralError, $$$FormatText("Class '%1' does not exist",..#CLASS)) | 
|  | 31 | +	quit:$$$ISERR(sc) sc | 
|  | 32 | +	 | 
|  | 33 | +	set sc = ##class(%Net.Remote.Service).StopGateway(gatewayName) | 
|  | 34 | +	 | 
|  | 35 | +	//Set sc = ##class(Ens.Director).StartProduction() | 
|  | 36 | +	quit sc | 
|  | 37 | +} | 
|  | 38 | + | 
|  | 39 | +ClassMethod Connect(gatewayName As %String = {..#GATEWAY}, path As %String = {..#JARPATH}, Output sc As %Status) As %Net.Remote.Gateway | 
|  | 40 | +{ | 
|  | 41 | +	set gateway = "" | 
|  | 42 | +	set sc = ##class(%Net.Remote.Service).OpenGateway(gatewayName, .gatewayConfig) | 
|  | 43 | +	quit:$$$ISERR(sc) gateway | 
|  | 44 | +	set sc = ##class(%Net.Remote.Service).ConnectGateway(gatewayConfig, .gateway, path, $$$YES) | 
|  | 45 | +	quit gateway | 
|  | 46 | +} | 
|  | 47 | + | 
|  | 48 | +/// set stream = ##class(isc.barcode.Utils).createQRCode("test.png", "Hi, world!", 240, "png") | 
|  | 49 | +/// w ##class(isc.barcode.Utils).createQRCode() | 
|  | 50 | +ClassMethod createQRCode(fileName As %String, qrCodeText As %String, fileSize As %String, fileType As %String, debug As %Boolean = {$$$YES}) As %GlobalBinaryStream | 
|  | 51 | +{ | 
|  | 52 | +    #dim gateway as %Net.Remote.Gateway | 
|  | 53 | +    #dim exception as %Exception.AbstractException | 
|  | 54 | +    set sc = $$$OK | 
|  | 55 | + | 
|  | 56 | +#; for test  | 
|  | 57 | +#;    set fileName = "C:\java\test.png" | 
|  | 58 | +#;    set qrCodeText = "hi" | 
|  | 59 | +#;    set fileSize = 240 | 
|  | 60 | +#;    set fileType = "png" | 
|  | 61 | +     | 
|  | 62 | +    try { | 
|  | 63 | +        set gateway = ..Connect() | 
|  | 64 | +        set start = $zh | 
|  | 65 | +         | 
|  | 66 | +        set reader = ##class(isc.barcode).%New(gateway) | 
|  | 67 | +         | 
|  | 68 | +        set end1 = $zh | 
|  | 69 | +         | 
|  | 70 | +        set qrCodeStream = reader.generateQRCode(fileName,qrCodeText,fileSize,fileType)  | 
|  | 71 | + | 
|  | 72 | +#; for test  | 
|  | 73 | +#;        set file1 = ##class(%FileBinaryStream).%New() | 
|  | 74 | +#;        set file1.Filename = "C:\java\test2.png" | 
|  | 75 | +#;        w file1.CopyFromAndSave(qrCodeStream),! | 
|  | 76 | +        | 
|  | 77 | +		set end2 = $zh | 
|  | 78 | +		 | 
|  | 79 | +		if debug { | 
|  | 80 | +			write !,"Init: ",end1-start | 
|  | 81 | +			write !,"Reader: ",end2-end1, ! | 
|  | 82 | +			zw barcodes | 
|  | 83 | +		} | 
|  | 84 | + | 
|  | 85 | +        set sc = gateway.%Disconnect() | 
|  | 86 | + | 
|  | 87 | +    } catch ex { | 
|  | 88 | +	    break:debug | 
|  | 89 | +        set sc = $$$ADDSC(ex.AsStatus(), $g(%objlasterror)) | 
|  | 90 | +    } | 
|  | 91 | + | 
|  | 92 | +    quit qrCodeStream | 
|  | 93 | +} | 
|  | 94 | + | 
|  | 95 | +/// Get barcode | 
|  | 96 | +/// Write $System.Status.GetErrorText(##class(isc.barcode.Utils).getBarCode()) | 
|  | 97 | +ClassMethod getBarCode(file As %String, debug As %Boolean = {$$$YES}) As %Status | 
|  | 98 | +{ | 
|  | 99 | +    #dim gateway as %Net.Remote.Gateway | 
|  | 100 | +    #dim exception as %Exception.AbstractException | 
|  | 101 | + | 
|  | 102 | +    set sc = $$$OK | 
|  | 103 | +    try { | 
|  | 104 | +        set gateway = ..Connect() | 
|  | 105 | +        set start = $zh | 
|  | 106 | +         | 
|  | 107 | +        set reader = ##class(isc.barcode).%New(gateway) | 
|  | 108 | +         | 
|  | 109 | +        set end1 = $zh | 
|  | 110 | +        set barcodes = reader.readBarCode(file)  | 
|  | 111 | +		set end2 = $zh | 
|  | 112 | +		 | 
|  | 113 | +		if debug { | 
|  | 114 | +			write !,"Init: ",end1-start | 
|  | 115 | +			write !,"Reader: ",end2-end1, ! | 
|  | 116 | +			zw barcodes | 
|  | 117 | +	        //break | 
|  | 118 | +		} | 
|  | 119 | + | 
|  | 120 | +        set sc = gateway.%Disconnect() | 
|  | 121 | + | 
|  | 122 | +    } catch ex { | 
|  | 123 | +	    break:debug | 
|  | 124 | +        set sc = $$$ADDSC(ex.AsStatus(), $g(%objlasterror)) | 
|  | 125 | +    } | 
|  | 126 | + | 
|  | 127 | +    quit sc | 
|  | 128 | +} | 
|  | 129 | + | 
|  | 130 | +} | 
|  | 131 | + | 
0 commit comments