示例#1
0
exports.search = function(string, prop) {
  var styleSheet = CSSOM.parse(string)

  if (!styleSheet || !styleSheet.cssRules) { return }

  var Enumerable = linq.From(styleSheet.cssRules)
    , rDigital = /-?\d+/

  var results = Enumerable.Where(function(x) {
    return x.style && !_.isUndefined(x.style[prop])
  }).Select(function(x) {
    return {
      value: x.style[prop]
    , selector: x.selectorText
    }
  }).GroupBy('$.value', '$.selector', function(key, group) {
    return {
      value: key
    , selectors: group.source
    }
  }).OrderBy(function(x) {
    var match = x.value.match(rDigital)
    return match ? +match[0]: x.value
  }).ToArray()

  return results
}
示例#2
0
var metaTable = function (doc) {
    this.doc = doc;
    for (var i in doc.Indexies)
        if (doc.Indexies[i].PrimaryKey) {
            //var
        }
    doc.cols = [];
    var i = 0;
    Enumerable.From(doc.Columns).ForEach(function (obj) {
        if (i < 10) doc.cols.push(obj);
        obj.PK = true;
        i++;
    });
}
示例#3
0
    path.exists(filename, function(exists) {
        if ( filename.endsWith("\\") || !exists ) {
			if (req.url.startsWith(NewMessagesAction)) {
				if (req.method == 'POST') {
					var bodyJson = qs.parse(body);					
					if (buddies.containsId(bodyJson.userId)) {
						var buddy = buddies.getById(bodyJson.userId);
						buddy.timestamp = (new Date()).getTime();
					}

					res.writeHead(200, { 'Content-Type': 'application/json' }); 
					var newMessages = [];
					var timestamp = bodyJson.timestamp;
					Enumerable.From(messages).Where(function(msg) { return msg.timestamp > timestamp; }).Select().ForEach(function (msg)
					{
					    newMessages.push(msg);
					});

			  		res.write(JSON.stringify({ timestamp: (new Date()).getTime(), messages: newMessages }));
			  		res.end();

				}
				else {
		  				res.writeHead(403);
	  					res.end("Método no permitido");
	  			}
			}
			if (req.url.startsWith(GetBuddiesAction)) {
				if (req.method == 'POST') {
					var bodyJson = qs.parse(body);
					if (buddies.containsId(bodyJson.userId)) {
						var buddy = buddies.getById(bodyJson.userId);
						buddy.timestamp = (new Date()).getTime();
					}
			  		res.write(JSON.stringify(buddies.getAll()));
			  		res.end();
		  		}
		  		else {
		  				res.writeHead(403);
	  					res.end("Método no permitido");
		  		}
			}
			if (req.url.startsWith(SendMessageAction)) {
				if (req.method == 'POST') {
					var bodyJson = qs.parse(body);
					if (typeof bodyJson.message === "undefined") {
						res.writeHead(404);
						res.end("Debe escribir un mensaje");
					}
					else {
						if (buddies.containsId(bodyJson.userId)) {
							var buddy = buddies.getById(bodyJson.userId);
							var time = (new Date()).getTime() - buddy.timestamp;
							if (time < timeout) {
								buddy.timestamp = (new Date()).getTime();
								messages.push({ message : bodyJson.message, name: buddy.name, timestamp: (new Date()).getTime()});
								res.writeHead(200);
					  			res.end("OK!");	
				  			}
				  			else {
				  				res.writeHead(500);
			  					res.end("Método no permitido");
				  			}
						}
			  		}
				}
				else {
					res.writeHead(403);
			  		res.end("Método no permitido");		
				}
			}
			if (req.url.startsWith(RegisterAction)) {
				if (req.method == 'POST') {
					var bodyJson = qs.parse(body);
					if (typeof bodyJson.name === "undefined") {
						res.writeHead(404);
						res.end("Debe escribir un nombre");
					}
					else {
						var name = bodyJson.name;
						var timestamp = (new Date()).getTime();
						var id = name + timestamp.toString();
						if (buddies.containsName(name)) {
							var buddy = buddies.getByName(name);
							var time = timestamp - buddy.timestamp;
							if (time > timeout) {
								buddies.add(id, name, timestamp);
				  				res.write(JSON.stringify({ id: id }));
				  				res.end();
							}
							else {
								res.writeHead(500);
				  				res.end("Ese usuario ya está registrado");
							}
						}
						else {
							buddies.add(id, name, timestamp);
			  				res.write(JSON.stringify({ id: id }));
			  				res.end();
						}
			  		}
				}
				else {
					res.writeHead(403);
			  		res.end("Método no permitido");		
				}
			}
			else if (req.url.startsWith(CheckUserAction)) {
				if (req.method == 'POST') {
					var bodyJson = qs.parse(body);
					if (typeof bodyJson.name === "undefined" || typeof bodyJson.userId === "undefined" ) {
						res.writeHead(403);
						res.end("Petición no válida");
					}
					else {
						if (buddies.containsId(bodyJson.userId)) {
							var buddy = buddies.getById(bodyJson.userId);
							buddy.timestamp = (new Date()).getTime();
			  				res.write(JSON.stringify({ id: buddy.id }));
			  				res.end();
						}
						else {
							res.writeHead(500);
			  				res.end("Ese usuario no existe");
						}
			  		}
				}
				else {
					res.writeHead(501);
			  		res.end("Método no permitido");		
				}
			}
			else if (req.url == HomeAction) {
		        res.writeHead(200, mimeType);
		        var fileStream = fs.createReadStream(path.join(process.cwd() + "\\static_files", "index.html"));
		        fileStream.pipe(res);
			}
			else {
				res.writeHead(404);
				res.end("No encontrado.");
			}
        }
        else {
	        var mimeType = mimeTypes[path.extname(filename).split(".")[1]];
	        res.writeHead(200, mimeType);
	        var fileStream = fs.createReadStream(filename);
	        fileStream.pipe(res);
    	}
    });