@@ -25,10 +25,9 @@ export class IotTemplateCollection extends EntityCollection<IotTemplateAttribute
2525 {
2626 this . ContextUI . Output ( "Loading system templates" ) ;
2727 const type = EntityType . system ;
28- //
2928 const path = `${ this . BasePath } \\${ type } ` ;
3029 const result = await this . LoadFromFolder ( path , type , this . RecoverySourcePath ) ;
31- this . ContextUI . Output ( result . toString ( ) ) ;
30+ this . ContextUI . Output ( result ) ;
3231 }
3332
3433 public async LoadTemplatesUser ( ) :Promise < void >
@@ -38,7 +37,7 @@ export class IotTemplateCollection extends EntityCollection<IotTemplateAttribute
3837 //
3938 const path = `${ this . BasePath } \\${ type } ` ;
4039 const result = await this . LoadFromFolder ( path , type , undefined ) ;
41- this . ContextUI . Output ( result . toString ( ) ) ;
40+ this . ContextUI . Output ( result ) ;
4241 }
4342
4443 public async LoadTemplatesCommunity ( ) :Promise < void >
@@ -53,7 +52,8 @@ export class IotTemplateCollection extends EntityCollection<IotTemplateAttribute
5352
5453 protected async LoadFromFolder ( pathFolder :string , type :EntityType , recoverySourcePath :string | undefined ) :Promise < IotResult >
5554 {
56- let result = new IotResult ( StatusResult . Ok , undefined , undefined ) ;
55+ let result :IotResult ;
56+ const templatesCountBegin = this . Count ;
5757 //Recovery
5858 let recovery = new IotTemplateRecovery ( type ) ;
5959 if ( type == EntityType . system && recoverySourcePath )
@@ -66,7 +66,7 @@ export class IotTemplateCollection extends EntityCollection<IotTemplateAttribute
6666 //ckeck
6767 if ( listFolders . length == 0 )
6868 {
69- result = new IotResult ( StatusResult . Ok , `${ pathFolder } folder is empty. There are no templates to load. ` ) ;
69+ result = new IotResult ( StatusResult . Ok , `${ pathFolder } folder is empty. There are no templates to load` ) ;
7070 return Promise . resolve ( result ) ;
7171 }
7272 //checking all folders
@@ -81,11 +81,8 @@ export class IotTemplateCollection extends EntityCollection<IotTemplateAttribute
8181 this . ContextUI . Output ( `Template recovery: ${ path . dirname ( filePath ) } ` ) ;
8282 result = template . Recovery ( ) ;
8383 if ( result . Status == StatusResult . Ok )
84- {
85- template . Init ( type , filePath , recoverySourcePath ) ;
86- } else {
87- this . ContextUI . Output ( `Error. Template restore error. ${ result . Message } . ${ result . SystemMessage } ` ) ;
88- }
84+ template . Init ( type , filePath , recoverySourcePath ) ;
85+ else this . ContextUI . Output ( result ) ;
8986 }
9087 //main
9188 if ( template . IsValid )
@@ -103,48 +100,51 @@ export class IotTemplateCollection extends EntityCollection<IotTemplateAttribute
103100 }
104101 case ContainsType . yesVersionSmaller : {
105102 this . Update ( template . Attributes . Id , template ) ;
106- this . ContextUI . Output ( `Template updated: ${ filePath } ` ) ;
103+ this . ContextUI . Output ( `Template updated: [ ${ template . Attributes . Id } ] ${ template . ParentDir } ` ) ;
107104 break ;
108105 }
109- default : {
110- //statements;
106+ default : {
107+ this . ContextUI . Output ( `Adding a template was skipped because already in the collection: [ ${ template . Attributes . Id } ] ${ template . ParentDir } ` ) ;
111108 break ;
112109 }
113110 }
114111 } else {
115- this . ContextUI . Output ( `Error. The template ${ template . DescriptionFilePath } is for a newer version of the extension.` +
112+ this . ContextUI . Output ( `[ERROR] The template ${ template . DescriptionFilePath } is for a newer version of the extension.` +
116113 `Update the extension.` ) ;
117114 }
118115 } else {
119- this . ContextUI . Output ( `Error. The template ${ template . DescriptionFilePath } has not been validated` ) ;
120- this . LogValidationErrors ( template . ValidationErrors ) ;
116+ this . ContextUI . Output ( `[ERROR] The template ${ template . DescriptionFilePath } has not been validated. ` ) ;
117+ this . ContextUI . Output ( template . ValidationErrorsToString ) ;
121118 //delete system template
122119 if ( type == EntityType . system ) {
123120 result = template . Remove ( ) ;
124- this . ContextUI . Output ( ` ${ result . Status } . ${ result . Message } . ${ result . SystemMessage } ` ) ;
121+ this . ContextUI . Output ( result ) ;
125122 }
126123 }
127124 } ) ;
128125 //result
129- if ( this . Count > 0 ) {
130- result = new IotResult ( StatusResult . Ok , `Loading templates from ${ pathFolder } folder successfully completed` , undefined ) ;
126+ if ( ( this . Count - templatesCountBegin ) > 0 ) {
127+ result = new IotResult ( StatusResult . Ok , `Loading templates from ${ pathFolder } folder successfully completed` ) ;
131128 } else {
132- result = new IotResult ( StatusResult . Error , ` No template was loaded from the ${ pathFolder } folder`, undefined ) ;
129+ result = new IotResult ( StatusResult . None , ` No template was loaded from the ${ pathFolder } folder`) ;
133130 }
134131 return Promise . resolve ( result ) ;
135132 }
136133
137134 public async UpdateSystemTemplate ( url :string , tempPath :string ) :Promise < IotResult >
138135 {
139136 const result = await this . UpdateTemplate ( url , EntityType . system , tempPath ) ;
137+ if ( result . Status == StatusResult . Error )
138+ result . AddMessage ( `Error updating system templates` ) ;
140139 return result ;
141140 }
142141
143142 public async UpdateTemplate ( url :string , type :EntityType , tempPath :string ) :Promise < IotResult >
144143 {
145144 const destPath = `${ this . BasePath } \\${ type } ` ;
146145 let downloader = new IotTemplateDownloader ( ) ;
147- let result = new IotResult ( StatusResult . None , undefined , undefined ) ;
146+ let result :IotResult ;
147+ this . ContextUI . Output ( `Downloading a list of templates to update: ${ url } ` ) ;
148148 result = await downloader . GetDownloadListTemplate ( url ) ;
149149 if ( result . Status == StatusResult . Error ) return Promise . resolve ( result ) ;
150150 this . ContextUI . Output ( `List of templates loaded ${ url } ` ) ;
@@ -176,16 +176,15 @@ export class IotTemplateCollection extends EntityCollection<IotTemplateAttribute
176176 if ( template . IsValid )
177177 {
178178 result = template . Move ( path . join ( destPath , template . Attributes . Id ) ) ;
179- if ( result . Status == StatusResult . Error )
180- {
181- this . ContextUI . Output ( `Error. The template ${ template . DescriptionFilePath } . ${ result . Message } . ${ result . SystemMessage } ` ) ;
179+ if ( result . Status == StatusResult . Error ) {
180+ this . ContextUI . Output ( result ) ;
182181 break ;
183182 }
184183 this . Add ( template . Attributes . Id , template ) ;
185- this . ContextUI . Output ( `Template added: [${ template . Attributes . Id } ] ${ template . ParentDir } ` ) ;
184+ this . ContextUI . Output ( `Template added/updated : [${ template . Attributes . Id } ] ${ template . ParentDir } ` ) ;
186185 } else {
187- this . ContextUI . Output ( `Error. The template ${ template . DescriptionFilePath } has not been validated` ) ;
188- this . LogValidationErrors ( template . ValidationErrors ) ;
186+ this . ContextUI . Output ( `[ERROR] The template ${ template . DescriptionFilePath } has not been validated` ) ;
187+ this . ContextUI . Output ( template . ValidationErrorsToString ) ;
189188 }
190189 }
191190 break ;
@@ -201,19 +200,17 @@ export class IotTemplateCollection extends EntityCollection<IotTemplateAttribute
201200 if ( template . IsValid )
202201 {
203202 result = template . Move ( path . join ( destPath , template . Attributes . Id ) ) ;
204- if ( result . Status == StatusResult . Error )
205- {
206- this . ContextUI . Output ( `Error. The template ${ template . DescriptionFilePath } . ${ result . Message } . ${ result . SystemMessage } ` ) ;
203+ if ( result . Status == StatusResult . Error ) {
204+ this . ContextUI . Output ( result ) ;
207205 break ;
208- }
206+ }
209207 this . Update ( template . Attributes . Id , template ) ;
210- this . ContextUI . Output ( `Template updated: [${ template . Attributes . Id } ] ${ template . DescriptionFilePath } ` ) ;
208+ this . ContextUI . Output ( `Template added/ updated: [${ template . Attributes . Id } ] ${ template . ParentDir } ` ) ;
211209 } else {
212- this . ContextUI . Output ( `Error. The template ${ template . DescriptionFilePath } has not been validated` ) ;
213- this . LogValidationErrors ( template . ValidationErrors ) ;
210+ this . ContextUI . Output ( `[ERROR] The template ${ template . DescriptionFilePath } has not been validated` ) ;
211+ this . ContextUI . Output ( template . ValidationErrorsToString ) ;
214212 }
215213 }
216- break ;
217214 }
218215 default : {
219216 //statements;
0 commit comments