go to post Julius Kavay · Jan 23 do res.HttpResponse.Data.Rewind() set dynObj = {}.%FromJSON(res.HttpResponse.Data) // now, you can use the JSON-Data write dynObj.propName // if it's a dynObject write dynObj.%Get(0) // if it's a dynArray
go to post Julius Kavay · Dec 22, 2022 If you want to reorder JSON properties (alphabetically or just put some of them at the beginning) then use a utility method, like this, especially if you have several object(types) to reorder Class DC.Utility Extends %RegisteredObject { /// Reorder a JSON Object or Array /// /// obj: JSON-Object /// ord: prop1, prop2, ... Desired order for (some) properties /// (Properties not listed are copied in the order in which they were created) /// If ord not present, properties will be reordered in aplphabetical order /// /// obj: JSON-Array /// ord: pos1, pos2, ... Desired order for (some) array items /// (Items not listed are copied in ascending order) /// ClassMethod ReOrder(obj As %DynamicAbstractObject, ord... As %String) { i obj.%Extends("%DynamicObject") { s new={}, itr=obj.%GetIterator() i '$g(ord) { while itr.%GetNext(.k) { s done(k)=0 } s k="" f s k=$o(done(k)) q:k="" d new.%Set(k,obj.%Get(k)) } else { f i=1:1:$g(ord) { s k=ord(i),done(k)=1 d:$e(obj.%GetTypeOf(k),1,2)'="un" new.%Set(k,obj.%Get(k)) } while itr.%GetNext(.k,.v) { d:'$d(done(k)) new.%Set(k,v) } } } elseif obj.%Extends("%DynamicArray") { s new=[], itr=obj.%GetIterator(), max=obj.%Size(), done="" f i=1:1:$g(ord) { s k=ord(i) i k,k<=max d new.%Push(obj.%Get(k-1)) s $bit(done,k)=1 } while itr.%GetNext(.k,.v) { d:'$bit(done,k+1) new.%Push(v) } } else { s new=obj } q new } } Some examples s car={"color":"red", "fuel":"diesel", "maxspeed":150, "maker":"Audi", "model":"Quattro Q5", "power":300, "available":true, "rating":8, "allWheel":true } s car1=##class(DC.Utility).ReOrder(car) // order all props alphabetically s car2=##class(DC.Utility).ReOrder(car,"maker","model","available") // start with maker, model, etc. w car.%ToJSON(),!,car1.%ToJSON(),!,car2.%ToJSON() ---> {"color":"red","fuel":"diesel","maxspeed":150,"maker":"Audi","model":"Quattro Q5","power":300,"available":true,"rating":8,"allWheel":true} {"allWheel":"1","available":"1","color":"red","fuel":"diesel","maker":"Audi","maxspeed":150,"model":"Quattro Q5","power":300,"rating":8} {"maker":"Audi","model":"Quattro Q5","available":"1","color":"red","fuel":"diesel","maxspeed":150,"power":300,"rating":8,"allWheel":"1"}
go to post Julius Kavay · Dec 16, 2022 Is NOT the same. You can it prove by adding a label to the line with the read command and a new line at the end // DOT VERSION // Use fic old Read *R:20 Else Do Quit ;;;; comando else aplicado a read. . Use 0 Write !!!,"Expired time." If $c(R)="a" d . Use 0 Write !!!,"A letter a has been read." . Quit write !,"If there are more lines, they will be executed",! quit // LITTLE BIT MODERN VERSION // Use fic new Read *R:20 If $Test { Use 0 Write !!!,"One character read" Quit } Else { Use 0 Write !!!,"Expired time." } write !,"If there are more lines, they will be executed",! quit now let run both of them... do old // let the timeout occur do old // now with some input do new // let the timeout occur do new // now with some input Do you see the difference? If there are more lines (at end) they will be executed in opposite cases (timeout/notimeout)
go to post Julius Kavay · Dec 15, 2022 Things are not so easy as they seem, you have to consider scopes too. Take the above class (DC.LineNumber) and add three more methods: ClassMethod CaseA(x) { if x goto zTest quit "A0" zTest quit "A1" } ClassMethod CaseB(x) { if x goto Test quit "B0" Test quit "B1" } ClassMethod Test() { write ..CaseA(0),..CaseA(1) set linenumber=..SrcLineNumberFromStack(.routine,.label,.offset,.src) do prt write ..CaseB(1),..CaseB(0) set linenumber=..SrcLineNumberFromStack(.routine,.label,.offset,.src) do prt quit // debug prt write !,"routine: ",routine write !,"label: ",label write !,"offset: ",offset write !,"linenumber: ",linenumber write !,"src:",src,!! } and now do the test: do ##class(DC.LineNumber).Test() and check the output... OK, I know, this is a (very) constructed case and shouldn't coincide with an everyday development style, but who knows, what a mad programer sometimes produces...
go to post Julius Kavay · Nov 16, 2022 If your serial class is named Data.Serial (as in your example code) then you should use the same name for the serial property too Class Data.Persistent Extends %Persistent { Property MPID as %Integer; Property Name as Data.Serial; <--- !!!!! } The correct way to set the values Set Obj=##Class(Data.Persistent).%New() Set Obj.MPID=MPID Set Obj.Name.FirstName=FirstName ; <---- Set Obj.Name.LastName=LastName ; <---- Set tSC=Obj.%Save()
go to post Julius Kavay · Nov 14, 2022 I think, I have a solution for you ClassMethod GetImage() { s req=##class(%Net.HttpRequest).%New() s req.Server="www.distrelec.de" s req.SSLConfiguration="SSL" s req.ReadRawMode=1 // <<---- this is your solution d req.Get("/Web/WebShopImages/landscape_medium/_t/if/sortimentsboxen-1.jpg") q req.HttpResponse } To get the image s rsp=##class(Some.Class).GetImage() i rsp.StatusCode=200 { s file="c:\temp\imageName.jpg" o file:"nwu":0 i $t u file d rsp.Data.Rewind(),rsp.Data.OutputToDevice() c file } That's all...
go to post Julius Kavay · Nov 8, 2022 I never had this kind of problem, but a quick and dirty method would be: 1) remove the 'Mount Read-only' flag, 2) run the tune table utility, 3) reenable the 'Mount Read-only flag'. I hope, you do not have some mean application, waiting for the chance of his life, to get a writable database...
go to post Julius Kavay · Nov 4, 2022 One of the problems could be the Bas64 encoding. This function inserts after each 76th byte a CRLF which possibly confuses the other party. Try with Set EncryptedBase64=$SYSTEM.Encryption.Base64Encode(encrypted, 1) The parameter 1 says, do not insert CRLFs. Also, the text you encrypt must be an ANSI (8bit) text. If you are on a unicode system, you should call Set encrypted=$SYSTEM.Encryption.AESCBCEncrypt($zcvt(text,"O","UTF8"),key,iv)
go to post Julius Kavay · Nov 2, 2022 You are just one letter away from solution... set db=##Class(SYS.Database).%OpenId("/trak/base/tc/db/ct",,.sc) //................................^^^ Id, not ID!
go to post Julius Kavay · Oct 20, 2022 I do not use Ensemble, but I would try using the JSON-Adaptor, something like this Class MessageB Extends (Ens.Request, %JSON.Adaptor) { Property ClientId As %String(MAXLEN = ""); Property message As %Stream.TmpBinary; } For example s r=##class(MessageB).%New() s r.ClientId=12345 d r.message.Write("part1") d r.message.Write("part2") w r.%JSONExportToStream(.s) d s.Rewind() w s.Read(s.Size) --> {"ClientId":"12345","message":"cGFydDFwYXJ0Mg=="}