-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
142 lines (107 loc) · 3.75 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* Module dependencies.
*/
findStdOut = 'before'; // global variable for simulationID
var fileName, io, socketio, tail;
var connect = require('connect');
var socketio = require('socket.io');
var Tail = require('tail').Tail;
var fs = require('fs');
var express = require('express');
var http = require('http');
var path = require('path');
var routes = require('./routes/routes.js');
var testOpenstudio = require('./archive/testOpenstudio.js');
var app = express()
, server = require('http').createServer(app)
, io = socketio.listen(server);
server.listen(9099);
//module.exports.io = io;
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
//Show Folders & Files like Apache
express.static.mime.define({'text/plain': ['idf', 'osm', 'epw', 'err', 'idd', 'eio','audit','bnd','end', 'eso','mdd','mtd','mtr','rdd','shd']});
express.static.mime.default_type = "text/plain"; //to render files without an extention, i.e. stdout, stderr
app.use(express.directory('public'));
app.use('/simulations', express.directory('../simulations', {icons:true}));
app.use('/simulations', express.static('../simulations'));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', routes.getHome);
app.get('/form', routes.getForm);
app.get('/measure-list.html', routes.getMeasureList);
app.get('/tracking-sheet.html', routes.getTrackingSheet);
app.get('/data-structure', routes.getDataStructure);
app.get('/data', routes.getDataStructure);
app.get('/json', routes.getDataStructure);
app.get('/walls', routes.getWalls);
app.get('/tracking', routes.getTracking);
app.get('/output', routes.testOutput);
app.get('/outputs', routes.testOutput);
app.get("/presentation", function(req, res) {
res.redirect("http://developer.eebhub.org/archives/presentations/OpenStudio-Node.js-to-DOE-NREL-4.30.14.pdf");
});
//Simulate OpenStudio & EnergyPlus
//console.log("*********BEFORE");
var simulate = require("./routes/simulate.js");
app.post('/simulate', simulate.openstudio);
//console.log("*********After");
app.post('/rmt', testOpenstudio.simulateOpenstudio);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
io.sockets.on('connection', function(socket) {
console.log("CONNECT!");
socket.on('room1', function(value){
console.log("****room1: " + value + "%");
});
socket.on('room2', function(value){
console.log("****room2: " + value + "%");
});
socket.on('room3', function(value){
console.log("****room3: " + value + "%");
});
socket.on('room4', function(value){
console.log("****room4: " + value + "%");
});
socket.on('randomNumber', function(value){
//console.log("#################################EMITTED");
var outputFilePath = findStdOut + "1-EnergyPlus-0/stdout";
//console.log('###$$$###$$$###$$' + outputFilePath);
if (fs.existsSync(outputFilePath))
{
//console.log('###$$$###$$$###$$ FILE FOUND ');
tail = new Tail(outputFilePath);
io.sockets.emit('redirectPath', {
channel: 'stdout',
value: findStdOut});
tail.on('line', function(data) {
return io.sockets.emit('new-data', {
channel: 'stdout',
value: data
});
});
}
else
{
io.sockets.emit('fileNotFound', {
channel: 'stdout',
value: 'Stdout file not found'});
// console.log("file not found");
}
});
return socket.emit('new-data', {
channel: 'stdout',
value: ""
});
});