Skip to content

Commit 911a26e

Browse files
committed
Fix
1 parent cc64532 commit 911a26e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+199
-189
lines changed

src/Configuration/IotConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IotResult,StatusResult } from '../IotResult';
77
import { IotConfigurationFolder } from './IotConfigurationFolder';
88
import { IotBuiltInConfig } from './IotBuiltInConfig';
99
import { IoTHelper } from '../Helper/IoTHelper';
10-
import { LogLevel } from '../LogLevel';
10+
import { LogLevel } from '../shared/LogLevel';
1111
import { Constants } from "../Constants"
1212

1313
export class IotConfiguration {

src/Configuration/IotConfigurationFolder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'path';
55
import * as os from 'os';
66
import { IoTHelper } from '../Helper/IoTHelper';
77
import { IotResult,StatusResult } from '../IotResult';
8-
import { EntityType } from '..//Entity/EntityType';
8+
import { EntityType } from '../Entity/EntityType';
99
import { Constants } from "../Constants"
1010

1111
export class IotConfigurationFolder {

src/Entity/EntityBase.ts

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { IoTHelper } from '../Helper/IoTHelper';
88
import { IotResult,StatusResult } from '../IotResult';
99

1010
export abstract class EntityBase<T extends EntityBaseAttribute> {
11-
protected _entityIntLabel:string; //for understandable log
11+
protected readonly _entityLabel:string; //for understandable log
12+
protected readonly _entitiesLabel:string; //for understandable log
1213
private _yamlFilePath:string=""; //YAML file
1314
public get YAMLFilePath(): string {
1415
return this._yamlFilePath;}
@@ -39,11 +40,12 @@ export abstract class EntityBase<T extends EntityBaseAttribute> {
3940

4041
protected _pathFolderSchemas: string;
4142

42-
constructor(entityIntLabel:string,
43+
constructor( entityLabel:string, entitiesLabel:string,
4344
TCreator: new(pathFolderSchemas?: string) => T,
4445
pathFolderSchemas: string
4546
){
46-
this._entityIntLabel=entityIntLabel;
47+
this._entityLabel=entityLabel;
48+
this._entitiesLabel=entitiesLabel;
4749
this.Attributes=new TCreator(pathFolderSchemas);
4850
//
4951
this._pathFolderSchemas=pathFolderSchemas;
@@ -52,24 +54,28 @@ export abstract class EntityBase<T extends EntityBaseAttribute> {
5254

5355
public Init(type:EntityType,yamlFilePath:string,recoverySourcePath?:string)
5456
{
55-
this.Type= type;
56-
this._recoverySourcePath=recoverySourcePath;
57-
this._yamlFilePath=yamlFilePath;
58-
this.ValidateEntityBase();
59-
if(!this.IsValid) return;
60-
//if(this.IsValid) this.Parse(path);
61-
let attributes = this.Attributes as any;
62-
attributes.Init(this.YAMLFilePath);
63-
if(attributes.IsValid) {
64-
//ok
65-
//check if folder matches entity and id
66-
if(this.RootNameDir!=attributes.Id)
67-
this._validationErrors.push(`${this._entityIntLabel} folder name ${this.RootNameDir} `+
68-
`does not match id value ${attributes.Id}.`+
69-
`You need to rename the folder or change the ${this._entityIntLabel} id.`);
70-
}else{
71-
//error
72-
this._validationErrors = attributes.ValidationErrors.slice();
57+
try {
58+
this.Type= type;
59+
this._recoverySourcePath=recoverySourcePath;
60+
this._yamlFilePath=yamlFilePath;
61+
this.ValidateEntityBase();
62+
if(!this.IsValid) return;
63+
//if(this.IsValid) this.Parse(path);
64+
let attributes = this.Attributes as any;
65+
attributes.Init(this.YAMLFilePath);
66+
if(attributes.IsValid) {
67+
//ok
68+
//check if folder matches entity and id
69+
if(this.RootNameDir!=attributes.Id)
70+
this._validationErrors.push(`${this._entityLabel} folder name ${this.RootNameDir} `+
71+
`does not match id value ${attributes.Id}.`+
72+
`You need to rename the folder or change the ${this._entityLabel} id.`);
73+
}else{
74+
//error
75+
this._validationErrors = attributes.ValidationErrors.slice();
76+
}
77+
} catch (err: any){
78+
this._validationErrors.push(`Error Init ${this._entitiesLabel}. Error: ${err}`);
7379
}
7480
}
7581

@@ -92,9 +98,9 @@ export abstract class EntityBase<T extends EntityBaseAttribute> {
9298
//replace fields
9399
const fileName=this.YAMLFilePath.substring(this.RootDir.length+1);
94100
this._yamlFilePath= path.join(destDir, fileName);
95-
result = new IotResult(StatusResult.Ok,`${this._entityIntLabel}. ${this.RootDir} folder successfully moved to ${destDir} folder`);
101+
result = new IotResult(StatusResult.Ok,`${this._entityLabel}. ${this.RootDir} folder successfully moved to ${destDir} folder`);
96102
} catch (err: any){
97-
result = new IotResult(StatusResult.Error,`Unable to move ${this._entityIntLabel} from folder ${this.RootDir} to folder ${destDir}`,err);
103+
result = new IotResult(StatusResult.Error,`Unable to move ${this._entityLabel} from folder ${this.RootDir} to folder ${destDir}`,err);
98104
}
99105
//result
100106
return result;
@@ -104,14 +110,13 @@ export abstract class EntityBase<T extends EntityBaseAttribute> {
104110
let result:IotResult;
105111
try {
106112
//delete
107-
if (fs.existsSync(this.RootDir))
108-
{
113+
if (fs.existsSync(this.RootDir)) {
109114
fs.emptyDirSync(this.RootDir);
110115
fs.removeSync(this.RootDir);
111116
}
112117
result = new IotResult(StatusResult.Ok,`Folder has been deleted: ${this.RootDir}`);
113118
} catch (err: any){
114-
result = new IotResult(StatusResult.Error,`Unable to delete ${this._entityIntLabel} folder: ${this.RootDir}`,err);
119+
result = new IotResult(StatusResult.Error,`Unable to delete ${this._entityLabel} folder: ${this.RootDir}`,err);
115120
}
116121
//result
117122
return result;
@@ -136,14 +141,13 @@ export abstract class EntityBase<T extends EntityBaseAttribute> {
136141
let result:IotResult;
137142
const fileZipPath=`${this.RecoverySourcePath}\\${this.RootNameDir}.zip`;
138143
result= IoTHelper.UnpackFromZip(fileZipPath,path.dirname(this.RootDir));
139-
if(result.Status==StatusResult.Error) result.AddMessage(`${this._entityIntLabel} restore error`);
144+
if(result.Status==StatusResult.Error) result.AddMessage(`${this._entityLabel} restore error`);
140145
//result
141146
return result;
142147
}
143148

144-
public IsCompatibleByEndDeviceArchitecture(endDeviceArchitecture?:string):boolean
149+
public IsCompatibleByEndDeviceArchitecture(endDeviceArchitecture:string):boolean
145150
{
146-
if(!endDeviceArchitecture) return false;
147151
const result=this.Attributes.EndDeviceArchitecture.find(x=>x==endDeviceArchitecture);
148152
if(result) return true; else return false;
149153
}

src/Entity/EntityCollection.ts

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { EntityBaseAttribute } from './EntityBaseAttribute';
77
import { EntityType } from './EntityType';
88
import { EntityRecovery } from './EntityRecovery';
99
import { IotResult,StatusResult } from '../IotResult';
10-
import { EventDispatcher,Handler } from '../EventDispatcher';
11-
import { LogLevel } from '../LogLevel';
10+
import { LogLevel } from '../shared/LogLevel';
1211
import { IoTHelper } from '../Helper/IoTHelper';
1312
import { EntityDownload, EntityDownloader } from './EntityDownloader';
1413
import { IotBuiltInConfig } from '../Configuration/IotBuiltInConfig';
14+
import { ClassWithEvent } from '../Shared/ClassWithEvent';
15+
import { ContainsType } from '../Shared/ContainsType';
1516

16-
export abstract class EntityCollection <A extends EntityBaseAttribute, T extends EntityBase<A>> {
17+
export abstract class EntityCollection <A extends EntityBaseAttribute, T extends EntityBase<A>> extends ClassWithEvent {
1718

1819
protected _items:Map<string,T>;
1920
protected readonly _entityLabel:string; //for understandable log
@@ -25,26 +26,11 @@ export abstract class EntityCollection <A extends EntityBaseAttribute, T extends
2526
public get Count(): number {
2627
return this._items.size;}
2728

28-
//Event--------------------------------------
29-
protected ChangedStateDispatcher = new EventDispatcher<IChangedStateEvent>();
30-
31-
public OnChangedStateSubscribe(handler: Handler<IChangedStateEvent>):Handler<IChangedStateEvent> {
32-
this.ChangedStateDispatcher.Register(handler);
33-
return handler;
34-
}
35-
36-
public OnChangedStateUnsubscribe (handler: Handler<IChangedStateEvent>) {
37-
this.ChangedStateDispatcher.Unregister(handler);
38-
}
39-
40-
protected FireChangedState(event: IChangedStateEvent) {
41-
this.ChangedStateDispatcher.Fire(event);
42-
}
43-
//-------------------------------------------
4429
constructor(
4530
entityLabel:string, entitiesLabel:string, TCreator: new(pathFolderSchemas: string) => T,
4631
getDirEntitiesCallback:(type:EntityType) =>string, config:IConfigEntityCollection
4732
){
33+
super();
4834
this._items = new Map<string,T>();
4935
this._entityLabel=entityLabel;
5036
this._entitiesLabel=entitiesLabel;
@@ -65,12 +51,7 @@ export abstract class EntityCollection <A extends EntityBaseAttribute, T extends
6551

6652
public Remove(id:string):boolean
6753
{
68-
try {
69-
this._items.delete(id);
70-
return true;
71-
} catch (err: any){
72-
return false;
73-
}
54+
return this._items.delete(id);
7455
}
7556

7657
public Update(newValue:T):boolean
@@ -414,23 +395,9 @@ export abstract class EntityCollection <A extends EntityBaseAttribute, T extends
414395
if (fs.existsSync(dir)) fs.emptyDirSync(dir);
415396
}
416397

417-
protected CreateEvent(message?:string|IotResult,logLevel?:LogLevel,increment?:number)
418-
{
419-
//Event
420-
this.FireChangedState({
421-
message:message,
422-
logLevel:logLevel,
423-
increment:increment
424-
});
425-
}
426-
427398
}
428399

429-
export interface IChangedStateEvent {
430-
message?:string|IotResult,
431-
logLevel?:LogLevel,
432-
increment?:number
433-
}
400+
//TODO убрать, заменить на Interface IConfig
434401

435402
export interface IConfigEntityCollection {
436403
extVersion: string;
@@ -444,10 +411,3 @@ export interface IConfigEntityCollection {
444411
urlsUpdateEntitiesCommunity:string[];
445412
urlUpdateEntitiesSystem:string;
446413
}
447-
448-
export enum ContainsType {
449-
no = "no",
450-
yesSameVersion = "yes same version",
451-
yesMoreVersion = "yes more version",
452-
yesVersionSmaller = "yes version smaller"
453-
}

src/Entity/EntityDownloader.ts

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ export class EntityDownloader {
2222
//unpack
2323
let unpackPath=`${destPath}\\${item.Id}`;
2424
//delete
25-
if (fs.existsSync(unpackPath))
26-
{
25+
if (fs.existsSync(unpackPath)) {
2726
fs.emptyDirSync(unpackPath);
2827
fs.removeSync(unpackPath);
2928
}
@@ -61,7 +60,7 @@ export class EntityDownloader {
6160
let item=obj.entitys[index];
6261
if(item) {
6362
const downloadEntity=this.ParseEntityDownload(item,url);
64-
listDownload.push(downloadEntity);
63+
if (downloadEntity) listDownload.push(downloadEntity);
6564
//next position
6665
index=index+1;
6766
}else break;
@@ -77,30 +76,34 @@ export class EntityDownloader {
7776
return Promise.resolve(result);
7877
}
7978

80-
protected ParseEntityDownload(obj:any,url:string):EntityDownload
79+
protected ParseEntityDownload(obj:any,url:string):EntityDownload|undefined
8180
{
82-
const objId=obj.id;
83-
const objVersion=obj.version;
84-
const objforVersionExt=obj.forVersionExt;
85-
const objUrl=url.substring(0,url.lastIndexOf('/'))+"/"+objId+".zip";
86-
//const filename = uri.split('/').pop()?.substring(0,uri.split('/').pop()?.lastIndexOf('.'));
87-
//const fileZipPath=this._config.Folder.Temp+"\\"+filename+".zip";
88-
//arrays
89-
let platform:Array<string>=[];
90-
let index=0;
91-
//platform
92-
index=0;
93-
do {
94-
let item=obj.platform[index];
95-
if(item) {
96-
platform.push(<string>item);
97-
//next position
98-
index=index+1;
99-
}else break;
100-
}
101-
while(true)
102-
const downloadEntity=new EntityDownload(objId,objVersion,objUrl,
103-
objforVersionExt,platform);
81+
let downloadEntity:EntityDownload|undefined;
82+
try {
83+
const objId=obj.id;
84+
const objVersion=obj.version;
85+
const objforVersionExt=obj.forVersionExt;
86+
const objUrl=url.substring(0,url.lastIndexOf('/'))+"/"+objId+".zip";
87+
//const filename = uri.split('/').pop()?.substring(0,uri.split('/').pop()?.lastIndexOf('.'));
88+
//const fileZipPath=this._config.Folder.Temp+"\\"+filename+".zip";
89+
//arrays
90+
let platform:Array<string>=[];
91+
let index=0;
92+
//platform
93+
index=0;
94+
do {
95+
let item=obj.platform[index];
96+
if(item) {
97+
platform.push(<string>item);
98+
//next position
99+
index=index+1;
100+
}else break;
101+
}
102+
while(true)
103+
downloadEntity=new EntityDownload(objId,objVersion,objUrl,
104+
objforVersionExt,platform);
105+
} catch (err: any){}
106+
//result
104107
return downloadEntity;
105108
}
106109
}

src/Entity/EntityRecovery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class EntityRecovery {
2929
{
3030
let listNames:Array<string>=[];
3131
//getting a list of entity files
32+
if (!fs.existsSync(sourceDir)) return listNames;
3233
const files = fs.readdirSync(sourceDir);
3334
files.forEach(name => {
3435
//file

src/EventDispatcher.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Helper/IoTHelper.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ export class IoTHelper {
215215
return listFiles;
216216
}
217217

218-
static SetTimeFiles(filesPath:string[],timestamp:number):IotResult
218+
static SetTimeFiles(filesPath:string[],
219+
timestamp:number=Date.now() /*Unix epoch, i.e. Unix timestamp*/):IotResult
219220
{
220221
let result:IotResult;
221222
let lastFile:string|undefined;
@@ -232,13 +233,6 @@ export class IoTHelper {
232233
return result;
233234
}
234235

235-
static SetCurrentTimeToFiles(dirPath:string)
236-
{
237-
//Unix epoch, i.e. Unix timestamp:
238-
const dateNow=Date.now();
239-
this.SetTimeFiles(this.GetAllFile(dirPath),dateNow);
240-
}
241-
242236
static SetLineEnding(content:string):string
243237
{
244238
//https://github.com/Neoklosch/crlf-helper/

src/Helper/dotnetHelper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export class dotnetHelper {
7777
static GetTargetFrameworkFromCsprojFile(filePath:string): string|undefined {
7878
try {
7979
//read *.csproj for get TargetFramework
80+
if (!fs.existsSync(filePath)) return undefined;
8081
const xmlFile:string= fs.readFileSync(filePath, 'utf8');
8182
let xpath = require('xpath');
8283
let dom = require('xmldom').DOMParser;
@@ -85,7 +86,8 @@ export class dotnetHelper {
8586
const targetFramework=nodes[0].firstChild.data;
8687
return targetFramework;
8788
} catch (err: any){
88-
return undefined;
89-
}
89+
90+
}
91+
return undefined;
9092
}
9193
}

src/Helper/launchHelper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ export class launchHelper {
7777
let checklabel=newLabel;
7878
if(increment) checklabel=`${newLabel} ${suffix}${increment}`;
7979
const item = arrayName.find(x=>x==checklabel);
80-
if(item)
81-
{
80+
if(item) {
8281
if(!increment) increment=0;
8382
increment++;
8483
checklabel=launchHelper.GetUniqueLabel(newLabel,suffix,increment,arrayName);

0 commit comments

Comments
 (0)