Skip to content

Commit 0552827

Browse files
author
Rustam
committed
added support for cls, mac, int, inc, dfi files
1 parent e9b0e17 commit 0552827

File tree

2 files changed

+195
-4
lines changed

2 files changed

+195
-4
lines changed

CacheUpdater/Task.cls.xml

Lines changed: 189 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Export generator="Cache" version="25">
2+
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2016.1 (Build 656U)" ts="2016-07-25 16:07:12">
33
<Class name="CacheUpdater.Task">
44
<Super>%SYS.Task.Definition</Super>
5+
<TimeChanged>64121,39819.499352</TimeChanged>
56
<TimeCreated>63603,52252.541311</TimeCreated>
67

78
<Parameter name="TaskName">
@@ -164,19 +165,27 @@ Download list of files on https://raw.githubusercontent.com/ server.<br>
164165
Set st = $$$OK
165166
166167
For i = 1:1:Links.Count() {
167-
Set streq = Request.Get($e(Links.GetAt(i),35,*)) // Remove "https://raw.githubusercontent.com/" from URL.
168+
Set link = Links.GetAt(i)
169+
Set streq = Request.Get($e(link,35,*)) // Remove "https://raw.githubusercontent.com/" from URL.
168170
Set:$$$ISERR(streq) st=$$$ADDSC(st, streq)
169171
170172
Set binarystream = Request.HttpResponse.Data
171173
Do binarystream.Rewind() // just in case
172174
173175
Set stream=##class(%GlobalCharacterStream).%New() //translating binary stream into character stream
174176
While 'binarystream.AtEnd {
175-
Do stream.Write(binarystream.Read())
177+
Do stream.WriteLine(binarystream.ReadLine())
176178
}
177179
Do stream.Rewind()
178180
179-
Set stload = $system.OBJ.LoadStream(stream,"",.error,.items,,,,"UTF8")
181+
182+
Set strload = ""
183+
If ..IsUDLFormat(link) {
184+
Set stload = ..LoadUDLFile(stream, link)
185+
}
186+
Else {
187+
Set stload = $system.OBJ.LoadStream(stream,"",.error,.items,,,,"UTF8")
188+
}
180189
181190
Set:$$$ISERR(stload) st=$$$ADDSC(st, stload)
182191
Merge Items = items // Does not overwrite existing array keys: Items(itemname)=""
@@ -187,6 +196,182 @@ Download list of files on https://raw.githubusercontent.com/ server.<br>
187196
]]></Implementation>
188197
</Method>
189198

199+
<Method name="LoadUDLFile">
200+
<Description><![CDATA[
201+
Imports the file in UDL file in the project
202+
<b>contentStream</b> - the stream which contains the source code in udl format.<br>
203+
<b>url</b> - the url where the file is located in the web.<br>]]></Description>
204+
<ClassMethod>1</ClassMethod>
205+
<FormalSpec>contentStream:%GlobalCharacterStream,url:%String</FormalSpec>
206+
<ReturnType>%Status</ReturnType>
207+
<Implementation><![CDATA[
208+
Set st = $$$OK
209+
Set ext = ..GetExt(url)
210+
If ext = "cls" {
211+
Set st = ..CreateClass(contentStream, url)
212+
}
213+
Elseif ext = "dfi" {
214+
Set st = ..CreateDFI(contentStream, url)
215+
}
216+
Else {
217+
Set st = ..CreateOther(contentStream, url)
218+
}
219+
220+
Return st
221+
]]></Implementation>
222+
</Method>
223+
224+
<Method name="CreateClass">
225+
<Description><![CDATA[
226+
Creates and imports the class into the project from stream
227+
<b>contentStream</b> - the stream which contains the source code in udl format.<br>
228+
<b>url</b> - the url where the file is located in the web.<br>]]></Description>
229+
<ClassMethod>1</ClassMethod>
230+
<FormalSpec>contentStream:%CharacterStream,url:%String</FormalSpec>
231+
<ReturnType>%Status</ReturnType>
232+
<Implementation><![CDATA[
233+
Set st = ..GetClassName(url, .className)
234+
Do contentStream.Rewind()
235+
Return:$$$ISERR(st) st
236+
237+
If '..IsClassExist(className) {
238+
Set clsDef = ##class(%Dictionary.ClassDefinition).%New()
239+
Set clsDef.Name = className
240+
Set st = clsDef.%Save()
241+
Return:$$$ISERR(st) st
242+
}
243+
244+
245+
Set namespace = $namespace
246+
247+
Set st = ##class(%Compiler.UDL.TextServices).SetTextFromStream(namespace, className, contentStream)
248+
Return st
249+
]]></Implementation>
250+
</Method>
251+
252+
<Method name="CreateDFI">
253+
<Description><![CDATA[
254+
Creates and imports the dfi file into the project from stream
255+
<b>contentStream</b> - the stream which contains the source code in udl format.<br>
256+
<b>url</b> - the url where the file is located in the web.<br>]]></Description>
257+
<ClassMethod>1</ClassMethod>
258+
<FormalSpec>contentStream:%CharacterStream,url:%String</FormalSpec>
259+
<ReturnType>%Status</ReturnType>
260+
<Implementation><![CDATA[
261+
Set st = $$$OK
262+
Try {
263+
Set st = ..GetDFIName(url, .name)
264+
Return:$$$ISERR(st) st
265+
266+
Set tDoc = ##class(%DeepSee.UI.FolderItemDocument).%New(name)
267+
Set st = tDoc.ImportFromXML(contentStream)
268+
Return:$$$ISERR(st) st
269+
270+
Set st = tDoc.Save()
271+
Return:$$$ISERR(st) st
272+
} Catch e {
273+
Set st = e.AsStatus()
274+
}
275+
Return st
276+
]]></Implementation>
277+
</Method>
278+
279+
<Method name="IsClassExist">
280+
<Description><![CDATA[
281+
Checks whether the class exists
282+
<b>className</b> - name of the class.<br>]]></Description>
283+
<ClassMethod>1</ClassMethod>
284+
<FormalSpec>className:%String</FormalSpec>
285+
<ReturnType>%Boolean</ReturnType>
286+
<Implementation><![CDATA[
287+
Set query = "SELECT TOP 1 COUNT(ID) FROM %Dictionary.ClassDefinition WHERE ID = ?"
288+
Set statement = ##class(%SQL.Statement).%New()
289+
Set st = statement.%Prepare(query)
290+
Set rset = statement.%Execute(className)
291+
If rset.%Next() && (rset.%ROWCOUNT > 0) {
292+
Return 1
293+
}
294+
Return 0
295+
]]></Implementation>
296+
</Method>
297+
298+
<Method name="GetClassName">
299+
<Description><![CDATA[
300+
Gets the name of the class by url
301+
<b>url</b> - the url where the file is located in the web.<br>
302+
<b>name</b> - simply a variable which is injected by a class name<br>]]></Description>
303+
<ClassMethod>1</ClassMethod>
304+
<FormalSpec><![CDATA[url:%String,&name]]></FormalSpec>
305+
<ReturnType>%Status</ReturnType>
306+
<Implementation><![CDATA[
307+
Set formattedUrl = $Translate($Translate(url, "\", "/"), "/", ".")
308+
Set name = $Replace($Extract(formattedUrl, $Find(formattedUrl, "cls."), *), ".cls", "")
309+
Return $$$OK
310+
]]></Implementation>
311+
</Method>
312+
313+
<Method name="GetDFIName">
314+
<Description><![CDATA[
315+
Gets the name of the dfi file by url
316+
<b>url</b> - the url where the file is located in the web.<br>
317+
<b>name</b> - simply a variable which is injected by a dfi file name<br>]]></Description>
318+
<ClassMethod>1</ClassMethod>
319+
<FormalSpec><![CDATA[url:%String,&name]]></FormalSpec>
320+
<ReturnType>%Status</ReturnType>
321+
<Implementation><![CDATA[
322+
Set formattedUrl = $Translate($Translate(url, "\", "/"), "/", ".")
323+
Set name = $Replace($Extract(formattedUrl, $Find(formattedUrl, "dfi."), *), "%20", " ")
324+
Return $$$OK
325+
]]></Implementation>
326+
</Method>
327+
328+
<Method name="CreateOther">
329+
<Description><![CDATA[
330+
Creates and imports other files into the project from stream
331+
<b>contentStream</b> - the stream which contains the source code in udl format.<br>
332+
<b>url</b> - the url where the file is located in the web.<br>]]></Description>
333+
<ClassMethod>1</ClassMethod>
334+
<FormalSpec>contentStream:%GlobalCharacterStream,url:%String</FormalSpec>
335+
<ReturnType>%Status</ReturnType>
336+
<Implementation><![CDATA[
337+
Set internalName = $Piece(url, "/", *)
338+
339+
Set rtn = ##class(%Routine).%New(internalName)
340+
Set status = rtn.CopyFrom(contentStream)
341+
Return:$$$ISERR(status) status
342+
343+
Set status = rtn.Save()
344+
Return:$$$ISERR(status) status
345+
346+
Set status = rtn.Compile()
347+
Return status
348+
]]></Implementation>
349+
</Method>
350+
351+
<Method name="GetExt">
352+
<Description><![CDATA[
353+
Get extension of the file by url
354+
<b>url</b> - the url where the file is located in the web.<br>]]></Description>
355+
<ClassMethod>1</ClassMethod>
356+
<FormalSpec>url:%String</FormalSpec>
357+
<ReturnType>%String</ReturnType>
358+
<Implementation><![CDATA[ Return $ZConvert($Piece(url, ".", *), "l")
359+
]]></Implementation>
360+
</Method>
361+
362+
<Method name="IsUDLFormat">
363+
<Description><![CDATA[
364+
Checks whether the url contains a file in udl format
365+
<b>url</b> - the url where the file is located in the web.<br>]]></Description>
366+
<ClassMethod>1</ClassMethod>
367+
<FormalSpec>url:%String</FormalSpec>
368+
<ReturnType>%Boolean</ReturnType>
369+
<Implementation><![CDATA[
370+
Set extensions = "cls,mac,int,inc,dfi"
371+
Return $Find(extensions, $Piece(url, ".", *))
372+
]]></Implementation>
373+
</Method>
374+
190375
<Method name="CreateRequest">
191376
<ClassMethod>1</ClassMethod>
192377
<FormalSpec>Username:%String,Password:%String</FormalSpec>

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ To create task for syncing GitHub repository → Cache instance do the followin
2323

2424
After task runs at least once you will get <i>GitHubURL</i> repository contents in <i>Namespace</i>
2525

26+
27+
Note that in order to sync CLS, MAC, INT, INC and DFI files they need to be stored<br>
28+
at corresponding folders. For example: <br>
29+
<b>for CLS</b>: cls/packagename/file.cls<br>
30+
<b>for MAC</b>: mac/file.mac
31+
2632
Continuous Integration
2733
-----------
2834

0 commit comments

Comments
 (0)