-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started working on new frontend area
- Loading branch information
1 parent
0c652ae
commit dea606a
Showing
171 changed files
with
14,080 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
src/CrystalQuartz.Application.Client2/dev/dev-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import { Schedule } from "./fake-scheduler"; | ||
import { FakeSchedulerServer } from "./fake-scheduler-server"; | ||
|
||
import * as querystring from 'querystring'; | ||
import * as http from 'http'; | ||
import * as url from 'url'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
const port = 3000; | ||
|
||
const mimeTypeResolver = (fileName: string) => { | ||
const extension = path.extname(fileName).toUpperCase(); | ||
|
||
switch (extension) { | ||
case '.HTML': return 'text/html'; | ||
case '.CSS': return 'text/css'; | ||
case '.js': return 'application/javascript'; | ||
default: return null; | ||
} | ||
}; | ||
|
||
const | ||
SECONDS = (x: number) => x * 1000, | ||
MINUTES = (x: number) => SECONDS(60 * x); | ||
|
||
const | ||
options = { | ||
version: 'dev', | ||
quartzVersion: 'nodejs-emulation', | ||
dotNetVersion: 'none', | ||
timelineSpan: 3600 * 1000, | ||
schedulerName: 'DemoScheduler', | ||
}, | ||
|
||
now = new Date().getTime(), | ||
|
||
schedule: Schedule = { | ||
'Maintenance': { | ||
'DB_Backup': { | ||
duration: SECONDS(20), | ||
triggers: { | ||
'db_trigger_1': { repeatInterval: MINUTES(1), initialDelay: SECONDS(5) }, | ||
'db_trigger_2': { repeatInterval: MINUTES(1.5) }, | ||
} | ||
}, | ||
'Compress_Logs': { | ||
duration: MINUTES(1), | ||
triggers: { | ||
'logs_trigger_1': { repeatInterval: MINUTES(3) }, | ||
'logs_trigger_2': { repeatInterval: MINUTES(4), pause: true } | ||
} | ||
} | ||
}, | ||
'Domain': { | ||
'Email_Sender': { | ||
duration: SECONDS(10), | ||
triggers: { | ||
'email_sender_trigger_1': { repeatInterval: MINUTES(2), repeatCount: 5 } | ||
} | ||
}, | ||
'Remove_Inactive_Users': { | ||
duration: SECONDS(30), | ||
triggers: { | ||
'remove_users_trigger_1': { repeatInterval: MINUTES(3), repeatCount: 5, persistAfterExecution: true } | ||
} | ||
} | ||
}, | ||
'Reporting': { | ||
'Daily Sales': { | ||
duration: MINUTES(7), | ||
triggers: { | ||
'ds_trigger': { repeatInterval: MINUTES(60), } | ||
} | ||
}, | ||
'Services Health': { | ||
duration: MINUTES(2), | ||
triggers: { | ||
'hr_trigger': { repeatInterval: MINUTES(30), startDate: now + MINUTES(1) } | ||
} | ||
}, | ||
'Resource Consumption': { | ||
duration: MINUTES(1), | ||
triggers: { | ||
'rc_trigger': { repeatInterval: MINUTES(10), startDate: now + MINUTES(2), endDate: now + MINUTES(40), persistAfterExecution: true } | ||
} | ||
} | ||
} | ||
}, | ||
|
||
schedulerServer = new FakeSchedulerServer({ | ||
dotNetVersion: options.dotNetVersion, | ||
quartzVersion: options.quartzVersion, | ||
schedule: schedule, | ||
schedulerName: options.schedulerName, | ||
timelineSpan: options.timelineSpan, | ||
version: options.version | ||
}); | ||
|
||
const requestHandler = (request: any, response: any) => { | ||
const requestUrl = url.parse(request.url, true); | ||
|
||
if (request.method === 'GET') { | ||
console.log(request.url); | ||
|
||
const filePath = requestUrl.query.path | ||
? 'dist/' + requestUrl.query.path | ||
: 'dist/index.html'; | ||
|
||
if (fs.existsSync(filePath)) { | ||
response.writeHead(200, { "Content-Type": mimeTypeResolver(filePath) }); | ||
response.write(fs.readFileSync(filePath)); | ||
response.end(); | ||
return; | ||
} | ||
|
||
response.writeHead(404, { "Content-Type": 'text/plain' }); | ||
response.write('Not found'); | ||
response.end(); | ||
} else { | ||
//var POST = {}; | ||
request.on( | ||
'data', | ||
(data: any) => { | ||
data = data.toString(); | ||
var POST = querystring.parse(data); | ||
|
||
// data = data.split('&'); | ||
// for (var i = 0; i < data.length; i++) { | ||
// var _data = data[i].replace(/\+/g, ' ').split("="); | ||
// POST[_data[0]] = _data[1]; | ||
// } | ||
console.log(POST); | ||
|
||
const result = schedulerServer.handleRequest(POST); | ||
response.writeHead(200, { "Content-Type": 'application/json' }); | ||
response.write(JSON.stringify(result)); | ||
response.end(); | ||
}); | ||
} | ||
}; | ||
|
||
const server = http.createServer(requestHandler); | ||
|
||
server.listen( | ||
port /*, | ||
(err: any) => { | ||
if (err) { | ||
return console.log('something bad happened', err); | ||
} | ||
console.log(`server is listening on ${port}`); | ||
}*/); |
Oops, something went wrong.