Skip to content

Commit ffeb51f

Browse files
committed
Code cleanup and typings improvement
1 parent ca7d633 commit ffeb51f

Some content is hidden

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

43 files changed

+654
-449
lines changed
Lines changed: 126 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,157 @@
1-
import { Schedule } from "./fake-scheduler";
2-
import { FakeSchedulerServer } from "./fake-scheduler-server";
3-
4-
import * as querystring from 'querystring';
1+
import * as fs from 'fs';
52
import * as http from 'http';
6-
import * as url from 'url';
7-
import * as fs from 'fs';
83
import * as path from 'path';
4+
import * as querystring from 'querystring';
5+
import * as url from 'url';
6+
import { Schedule } from './fake-scheduler';
7+
import { FakeSchedulerServer } from './fake-scheduler-server';
98

109
const port = 3000;
1110

1211
const mimeTypeResolver = (fileName: string) => {
13-
const extension = path.extname(fileName).toUpperCase();
12+
const extension = path.extname(fileName).toUpperCase();
13+
14+
switch (extension) {
15+
case '.HTML':
16+
return 'text/html';
17+
case '.CSS':
18+
return 'text/css';
19+
case '.js':
20+
return 'application/javascript';
21+
default:
22+
return null;
23+
}
24+
};
1425

15-
switch (extension) {
16-
case '.HTML': return 'text/html';
17-
case '.CSS': return 'text/css';
18-
case '.js': return 'application/javascript';
19-
default: return null;
20-
}
26+
const SECONDS = (x: number) => x * 1000;
27+
const MINUTES = (x: number) => SECONDS(60 * x);
28+
29+
const options = {
30+
version: 'dev',
31+
quartzVersion: 'nodejs-emulation',
32+
dotNetVersion: 'none',
33+
timelineSpan: 3600 * 1000,
34+
schedulerName: 'DemoScheduler',
2135
};
2236

23-
const
24-
SECONDS = (x: number) => x * 1000,
25-
MINUTES = (x: number) => SECONDS(60 * x);
26-
27-
const
28-
options = {
29-
version: 'dev',
30-
quartzVersion: 'nodejs-emulation',
31-
dotNetVersion: 'none',
32-
timelineSpan: 3600 * 1000,
33-
schedulerName: 'DemoScheduler',
34-
},
37+
const now = new Date().getTime();
3538

36-
now = new Date().getTime(),
37-
38-
schedule: Schedule = {
39-
'Maintenance': {
40-
'DB_Backup': {
41-
duration: SECONDS(20),
42-
triggers: {
43-
'db_trigger_1': { repeatInterval: MINUTES(1), initialDelay: SECONDS(5) },
44-
'db_trigger_2': { repeatInterval: MINUTES(1.5) },
45-
}
46-
},
47-
'Compress_Logs': {
48-
duration: MINUTES(1),
49-
triggers: {
50-
'logs_trigger_1': { repeatInterval: MINUTES(3) },
51-
'logs_trigger_2': { repeatInterval: MINUTES(4), pause: true }
52-
}
53-
}
39+
const schedule: Schedule = {
40+
Maintenance: {
41+
DB_Backup: {
42+
duration: SECONDS(20),
43+
triggers: {
44+
db_trigger_1: { repeatInterval: MINUTES(1), initialDelay: SECONDS(5) },
45+
db_trigger_2: { repeatInterval: MINUTES(1.5) },
46+
},
47+
},
48+
Compress_Logs: {
49+
duration: MINUTES(1),
50+
triggers: {
51+
logs_trigger_1: { repeatInterval: MINUTES(3) },
52+
logs_trigger_2: { repeatInterval: MINUTES(4), pause: true },
53+
},
54+
},
55+
},
56+
Domain: {
57+
Email_Sender: {
58+
duration: SECONDS(10),
59+
triggers: {
60+
email_sender_trigger_1: { repeatInterval: MINUTES(2), repeatCount: 5 },
61+
},
62+
},
63+
Remove_Inactive_Users: {
64+
duration: SECONDS(30),
65+
triggers: {
66+
remove_users_trigger_1: {
67+
repeatInterval: MINUTES(3),
68+
repeatCount: 5,
69+
persistAfterExecution: true,
5470
},
55-
'Domain': {
56-
'Email_Sender': {
57-
duration: SECONDS(10),
58-
triggers: {
59-
'email_sender_trigger_1': { repeatInterval: MINUTES(2), repeatCount: 5 }
60-
}
61-
},
62-
'Remove_Inactive_Users': {
63-
duration: SECONDS(30),
64-
triggers: {
65-
'remove_users_trigger_1': { repeatInterval: MINUTES(3), repeatCount: 5, persistAfterExecution: true }
66-
}
67-
}
71+
},
72+
},
73+
},
74+
Reporting: {
75+
'Daily Sales': {
76+
duration: MINUTES(7),
77+
triggers: {
78+
ds_trigger: { repeatInterval: MINUTES(60) },
79+
},
80+
},
81+
'Services Health': {
82+
duration: MINUTES(2),
83+
triggers: {
84+
hr_trigger: { repeatInterval: MINUTES(30), startDate: now + MINUTES(1) },
85+
},
86+
},
87+
'Resource Consumption': {
88+
duration: MINUTES(1),
89+
triggers: {
90+
rc_trigger: {
91+
repeatInterval: MINUTES(10),
92+
startDate: now + MINUTES(2),
93+
endDate: now + MINUTES(40),
94+
persistAfterExecution: true,
6895
},
69-
'Reporting': {
70-
'Daily Sales': {
71-
duration: MINUTES(7),
72-
triggers: {
73-
'ds_trigger': { repeatInterval: MINUTES(60), }
74-
}
75-
},
76-
'Services Health': {
77-
duration: MINUTES(2),
78-
triggers: {
79-
'hr_trigger': { repeatInterval: MINUTES(30), startDate: now + MINUTES(1) }
80-
}
81-
},
82-
'Resource Consumption': {
83-
duration: MINUTES(1),
84-
triggers: {
85-
'rc_trigger': { repeatInterval: MINUTES(10), startDate: now + MINUTES(2), endDate: now + MINUTES(40), persistAfterExecution: true }
86-
}
87-
}
88-
}
96+
},
8997
},
98+
},
99+
};
90100

91-
schedulerServer = new FakeSchedulerServer({
92-
dotNetVersion: options.dotNetVersion,
93-
quartzVersion: options.quartzVersion,
94-
schedule: schedule,
95-
schedulerName: options.schedulerName,
96-
timelineSpan: options.timelineSpan,
97-
version: options.version,
98-
errorEmulation: {
99-
'get_data': { probability: 1 }
100-
}
101-
});
101+
const schedulerServer = new FakeSchedulerServer({
102+
dotNetVersion: options.dotNetVersion,
103+
quartzVersion: options.quartzVersion,
104+
schedule: schedule,
105+
schedulerName: options.schedulerName,
106+
timelineSpan: options.timelineSpan,
107+
version: options.version,
108+
errorEmulation: {
109+
get_data: { probability: 1 },
110+
},
111+
});
102112

103113
const requestHandler = (request: any, response: any) => {
104-
const requestUrl = url.parse(request.url, true);
114+
const requestUrl = url.parse(request.url, true);
105115

106-
if (request.method === 'GET') {
107-
console.log(request.url);
116+
if (request.method === 'GET') {
117+
console.log(request.url);
108118

109-
const filePath = requestUrl.query.path
110-
? 'dist/' + requestUrl.query.path
111-
: 'dist/index.html';
119+
const filePath = requestUrl.query.path ? 'dist/' + requestUrl.query.path : 'dist/index.html';
112120

113-
if (fs.existsSync(filePath)) {
114-
response.writeHead(200, { "Content-Type": mimeTypeResolver(filePath) });
115-
response.write(fs.readFileSync(filePath));
116-
response.end();
117-
return;
118-
}
119-
120-
response.writeHead(404, { "Content-Type": 'text/plain' });
121-
response.write('Not found');
122-
response.end();
123-
} else {
124-
request.on(
125-
'data',
126-
(data: any) => {
127-
data = data.toString();
128-
var POST = querystring.parse(data);
129-
130-
console.log(POST);
131-
132-
const result = schedulerServer.handleRequest(POST);
133-
response.writeHead(200, { "Content-Type": 'application/json' });
134-
response.write(JSON.stringify(result));
135-
response.end();
136-
});
121+
if (fs.existsSync(filePath)) {
122+
response.writeHead(200, { 'Content-Type': mimeTypeResolver(filePath) });
123+
response.write(fs.readFileSync(filePath));
124+
response.end();
125+
return;
137126
}
127+
128+
response.writeHead(404, { 'Content-Type': 'text/plain' });
129+
response.write('Not found');
130+
response.end();
131+
} else {
132+
request.on('data', (data: any) => {
133+
data = data.toString();
134+
const POST = querystring.parse(data);
135+
136+
console.log(POST);
137+
138+
const result = schedulerServer.handleRequest(POST);
139+
response.writeHead(200, { 'Content-Type': 'application/json' });
140+
response.write(JSON.stringify(result));
141+
response.end();
142+
});
143+
}
138144
};
139145

140146
const server = http.createServer(requestHandler);
141147

142148
server.listen(
143-
port /*,
149+
port /*,
144150
(err: any) => {
145151
if (err) {
146152
return console.log('something bad happened', err);
147153
}
148154
149155
console.log(`server is listening on ${port}`);
150-
}*/);
156+
}*/
157+
);

src/CrystalQuartz.Application.Client2/dev/fake-scheduler-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class FakeSchedulerServer {
2121
private readonly _commandHandlers: { [command: string]: (args: any) => any };
2222
private readonly _getError: (code: string) => { _err: string } | undefined;
2323

24-
constructor(options: IFakeSchedulerOptions) {
24+
public constructor(options: IFakeSchedulerOptions) {
2525
this._scheduler = new FakeScheduler(options.schedulerName, options.schedule);
2626

2727
this._getError = (code: string): { _err: string } | undefined => {
@@ -261,7 +261,7 @@ export class FakeSchedulerServer {
261261
this._scheduler.start();
262262
}
263263

264-
handleRequest(data: any) {
264+
public handleRequest(data: any) {
265265
const handler = this._commandHandlers[data.command];
266266

267267
if (handler) {

0 commit comments

Comments
 (0)