Exemplo n.º 1
0
 opts.retry_strategy = function(options) {
     logger.dev("initClient:", options);
     if (options.total_retry_time > connect_timeout || (lib.isArray(opts.servers) && options.attempt > max_attempts)) {
         setTimeout(self.onError.bind(self, self.name, { code: 'CONNECTION_BROKEN', message: opts.error && opts.error.message }), 100);
         return undefined;
     }
     return Math.min(100, Math.min((options.attempt % max_attempts) * 200, retry_max_delay));
 }
Exemplo n.º 2
0
 isCircularRef = function(token, stack){
     var found = false;
     for (var i = 0, l = stack.length; i < l; i++){
         if(stack[i] == token){
             found = true;
             log.dev('circular Ref Found :', token, stack);
             return found;
         }
     }
     
     return found;
 },
Exemplo n.º 3
0
function assertions () {
  assert.equal(is.main(), process.type === 'browser', 'is.main() not ok!')
  assert.equal(is.renderer(), process.type === 'renderer', 'is.renderer() not ok!')

  assert.equal(is.osx(), process.platform === 'darwin', 'is.osx() not ok!')
  assert.equal(is.macOS(), process.platform === 'darwin', 'is.macOS() not ok!')
  assert.equal(is.windows(), process.platform === 'win32', 'is.windows() not ok!')
  assert.equal(is.linux(), process.platform === 'linux', 'is.linux() not ok!')

  assert.equal(is.x86(), process.arch === 'ia32', 'is.x86() not ok!')
  assert.equal(is.x64(), process.arch === 'x64', 'is.x64() not ok!')

  assert.equal(is.production(), (process.env.NODE_ENV || 'dev') === 'production', 'is.production() not ok!')
  assert.equal(is.dev(), (process.env.NODE_ENV || 'dev') === 'dev', 'is.dev() not ok!')

  assert.equal(is.sandbox(), ('APP_SANDBOX_CONTAINER_ID' in process.env), 'is.sandbox() not ok!')
  assert.equal(is.mas(), process.mas === true, 'is.mas() not ok!')
  assert.equal(is.windowsStore(), process.windowsStore === true, 'is.windowsStore() not ok!')

  assert.equal(is.all(is.osx, is.x64), is.osx() && is.x64(), 'is.all() 1 not ok!')
  assert.equal(is.all(is.osx, is.x86), is.osx() && is.x86(), 'is.all() 2 not ok!')
  assert.equal(is.none(is.windows, is.x86), !is.windows() && !is.x86(), 'is.none() 1 not ok!')
  assert.equal(is.none(is.windows, is.x64), !is.windows() && !is.x64(), 'is.none() 2 not ok!')
  assert.equal(is.one(is.windows, is.osx), is.windows() || is.osx(), 'is.one() 1 not ok!')
  assert.equal(is.one(is.windows, is.linux), is.windows() || is.linux(), 'is.one() 2 not ok!')

  if (is.osx()) {
    const osx = osxRelease()
    // mac el capitan
    assert.equal(is.release(osx), true, 'is.release() not ok!')

    assert.equal(is.gtRelease(osx), false, 'is.gtRelease() 1 not ok!')
    assert.equal(is.gtRelease('100.100.100'), true, 'is.gtRelease() 2 not ok!')
    assert.equal(is.gtRelease('1.0.0'), false, 'is.gtRelease() 3 not ok!')

    assert.equal(is.ltRelease(osx), false, 'is.ltRelease() 1 not ok!')
    assert.equal(is.ltRelease('100.100.100'), false, 'is.ltRelease() 2 not ok!')
    assert.equal(is.ltRelease('1.0.0'), true, 'is.ltRelease() 3 not ok!')
  } else if (is.windows()) {
    // tests Windows 10 AU
    assert.equal(is.release('10.0'), true, 'is.release() not ok!')
    assert.equal(is.release('10.0.14393'), true, 'is.release() not ok!')
  } else {
    assert.equal(is.release('1.2.3'), null, 'is.release() not ok!')
  }

  return true
}
Exemplo n.º 4
0
 Api.findById(api_req, null, null, function (err, api) {
     if (api) {
         apiDev(api, api_uri, function (err, result) {
             if (err) {
                 res.render("apiError", {
                     current_page: 'device',
                     err: err,
                     user: req.user,
                     session: req.session,
                     schoolList: schoolList
                 });
             } else {
                 res.send(result);
             }
         });
     }
 });
Exemplo n.º 5
0
 fs.readFile(path.dirname(filePath) + '/' + partialName + '.html', 'utf-8', function(error, content){
     if(error){
         log.write(error);
         res.writeHead(500);
         res.end('error occured when processing view partial:' + partialName, 'utf-8');
         return;
     }
     
     //开始解析之前,先把内容include进来
     log.dev('pre replace ---', matched[0]);
     entireContent = entireContent.replace(matched[0], content);
     asyncPartialMap[partialName] = content;
     
     parsePartial(partialName, _refStack, content, function(){
         
         /*log.dev('partialCount - before', partialCount);
         partialCount--;
         log.dev('partialCount - after', partialCount);
         */
         if(--branchNum == 0){
             callback();
         }
     });
 });
Exemplo n.º 6
0
	var buildModelTemp = function(){
		//var modelPath = path.join(process.dstDir, 'server/tmp/model.js');
		//console.log('modelPath :' + modelPath);
        
        var appPath  = __dirname + '/../../app' + 
            ((typeof process.BAE == 'undefined' && process.argv[2]) ? '/' +process.argv[2] : '');
        var allTheDirFiles = [];
        var modelBaseDir = appPath + '/model';
        var Model = Model || {};
        var findAllTheDirFiles = function(theDir) {                                 
            var theDirFiles = fs.readdirSync(theDir);
            for (var i = 0, len = theDirFiles.length; i < len; i++) {
                var thePath = theDir + '/' + theDirFiles[i];
                theDirFiles[i].indexOf('.') === -1 ? 
                  findAllTheDirFiles(thePath) : allTheDirFiles.push(thePath);
            }
        };
        
        if(fs.existsSync(modelBaseDir)){
           findAllTheDirFiles(modelBaseDir);
           allTheDirFiles.forEach(function(file) {
                if (path.extname(file) == '.js'
                    && path.basename(file, '.js') != 'package') {
                    var content = fs.readFileSync(file, 'utf-8');
                    eval(content);
                };
            });
        }else{
            log.dev(modelBaseDir + ' 目录不存在!!!');
        }
        
		var modelDef = Model;
		for (var model in modelDef){
	        var exports = {},
	            fieldsMap = {};
	           
	        modelDef[model](exports);
	        //只记录fields中的每个子model到当前父层model的对应关系,多层嵌套的关系留在查询关系的时候层层反应出来。
	        if(exports['config'] && exports['config']['fields']){
	            var fields = exports.config.fields;
	            
	            for (var i = 0, l = fields.length; i < l; i++){
					var oneField = fields[i];
					if(oneField['type']=='model'&& typeof oneField['model'] != 'undefined'){
						oneField.model = oneField.model.replace(/Model\./, ''); 
						
                        fw.model.modelRelation[oneField.model] = fw.model.modelRelation[oneField.model] || [];
                        if (fw.model.modelRelation[oneField.model].indexOf(model) == -1) {
                            fw.model.modelRelation[oneField.model].push(model);
                        };
					}

					fieldsMap[oneField['name']] = oneField;
	            }

	            fieldsMap[fw.idField] = {name : fw.idField, type : 'int'};
				//fieldsMap[fw.clientIdField] = {name : fw.clientIdField, type	:	'string'};
	        }
	        fw.model.modelTempContainter[model] = fieldsMap;
	        fw.model.modelTempContainter[model].needAuth = exports['config'].needAuth;
	    }
	}
Exemplo n.º 7
0
 (function(matched){
     if(matched.length == 2){
         var partialName = matched[1];
         //check circular include
         if(isCircularRef(partialName, _refStack)){
             entireContent = entireContent.replace(matched[0], "<p style='color:red'>circular include found : " + partialName + '</p>');
             
             //如果本次循环都全部触发了循环引用检查,那么手动触发一次回调,使上层递归继续执行
             //partialCount--;
             if(--branchNum == 0){
                 callback();
             }
             /*if(i == l - 1 && !haveReachedParse){
                 callback();
             } else {
                 log.dev('partialCount ciruclar - before', partialCount);
                 //partialCount--;
                 log.dev('partialCount circular - after', partialCount);
             }*/
             //这里其实是continue的意思,但由于构造了闭包,所以直接return当前闭包即可
             return;
         }
         
         haveReachedParse = true;
         
         log.dev('checkCache', (partialName), typeof asyncPartialMap[(partialName)]);
         
         if(typeof asyncPartialMap[partialName] == 'undefined'){
             
             fs.readFile(path.dirname(filePath) + '/' + partialName + '.html', 'utf-8', function(error, content){
                 if(error){
                     log.write(error);
                     res.writeHead(500);
                     res.end('error occured when processing view partial:' + partialName, 'utf-8');
                     return;
                 }
                 
                 //开始解析之前,先把内容include进来
                 log.dev('pre replace ---', matched[0]);
                 entireContent = entireContent.replace(matched[0], content);
                 asyncPartialMap[partialName] = content;
                 
                 parsePartial(partialName, _refStack, content, function(){
                     
                     /*log.dev('partialCount - before', partialCount);
                     partialCount--;
                     log.dev('partialCount - after', partialCount);
                     */
                     if(--branchNum == 0){
                         callback();
                     }
                 });
             });
         } else {
             log.dev('hitCacheViewPartial', matched[0]);
             entireContent = entireContent.replace(matched[0], asyncPartialMap[partialName]);
             
             parsePartial(matched[1], _refStack, asyncPartialMap[matched[1]], function(){
                 /*log.dev('partialCount cache - before', partialCount);
                 partialCount--;
                 log.dev('partialCount cache - after', partialCount);
                 */
                 if(--branchNum == 0){
                     callback();
                 }
             });
             //entireContent = entireContent.replace(matched[0], asyncPartialMap[partialName]);
             //callback();
         }
     }
 })(matched);
Exemplo n.º 8
0
 parsePartial = function(parseToken, refStack, content, callback){
     //先去掉所有HTML的注释
     var commentRegExp = /(<!--([\s\S]*?)-->)/mg; // means <!--xxx-->
     log.dev('view remove comment', content.match(commentRegExp));
     
     /*
     var tplRoleOpenPart = /<!--([\s]*tpl-role[\s]*=[\s]*[\s\S]*?)-->/g,
         tplRoleClosePart = /<!--([\s]*\/tpl-role[\s]*)-->/g;
     
     entireContent = entireContent.replace(tplRoleRegExp, function($0){
        //先替换close的
        $0 = $0.replace(tplRoleClosePart, function($0, $1){
            return '!!--' + $1 + '--!!';
        });
        $0 = $0.replace(tplRoleOpenPart,function($0, $1){
            return '!!--' + $1 + '--!!';
        });
        return $0;
     });
     content = content.replace(tplRoleRegExp, function($0){
        
        $0 = $0.replace(tplRoleClosePart, function($0, $1){
            return '!!--' + $1 + '--!!';
        });
        $0 = $0.replace(tplRoleOpenPart,function($0, $1){
            return '!!--' + $1 + '--!!';
        });
        return $0;
     });
     */
     
     entireContent = entireContent.replace(commentRegExp, '');
     content = content.replace(commentRegExp, '');
     
     var _refStack = JSON.parse(JSON.stringify(refStack));
     _refStack.push(parseToken);
     
                 
     /*NOTES:这里为了考虑循环引用的路径一致,禁止了include时使用../的能力。
     在写正则的时候为了方便,直接把策略写成了include的token中不能包括小数点。
     这样等于同时也禁止了写.html这类后缀的能力,感觉挺好,先这样*/
     var syntaxMatcher = content.match(/{{>\s*([^}\.\s*]+)}}/mig);
     if(syntaxMatcher === null){
         syntaxMatcher = [];//兼容下列循环和length判断
     }
 
     var branchNum = syntaxMatcher.length || 1;
     //partialCount += branchNum;
     
     log.dev('branchNum', branchNum, parseToken);
     
     if(syntaxMatcher.length == 0){
         //替换为实际内容(再无进一步include命令的)
         log.dev('hit plain text', parseToken);
         asyncPartialMap[parseToken] = content;
         var replaceSeg = new RegExp('{{>\\s*' + parseToken +  '\\s*}}');
         entireContent = entireContent.replace(replaceSeg, content);
         callback();
         return;
     } else {
         var haveReachedParse = false;
         
         for(var i = 0, l = syntaxMatcher.length; i < l; i++){
             var matched = syntaxMatcher[i].match(/{{>\s*([^}\.\s*]+)}}/i);
             //因为整体逻辑中有readFile导致异步,创建闭包保持matched的值不被后续循环污染
             (function(matched){
                 if(matched.length == 2){
                     var partialName = matched[1];
                     //check circular include
                     if(isCircularRef(partialName, _refStack)){
                         entireContent = entireContent.replace(matched[0], "<p style='color:red'>circular include found : " + partialName + '</p>');
                         
                         //如果本次循环都全部触发了循环引用检查,那么手动触发一次回调,使上层递归继续执行
                         //partialCount--;
                         if(--branchNum == 0){
                             callback();
                         }
                         /*if(i == l - 1 && !haveReachedParse){
                             callback();
                         } else {
                             log.dev('partialCount ciruclar - before', partialCount);
                             //partialCount--;
                             log.dev('partialCount circular - after', partialCount);
                         }*/
                         //这里其实是continue的意思,但由于构造了闭包,所以直接return当前闭包即可
                         return;
                     }
                     
                     haveReachedParse = true;
                     
                     log.dev('checkCache', (partialName), typeof asyncPartialMap[(partialName)]);
                     
                     if(typeof asyncPartialMap[partialName] == 'undefined'){
                         
                         fs.readFile(path.dirname(filePath) + '/' + partialName + '.html', 'utf-8', function(error, content){
                             if(error){
                                 log.write(error);
                                 res.writeHead(500);
                                 res.end('error occured when processing view partial:' + partialName, 'utf-8');
                                 return;
                             }
                             
                             //开始解析之前,先把内容include进来
                             log.dev('pre replace ---', matched[0]);
                             entireContent = entireContent.replace(matched[0], content);
                             asyncPartialMap[partialName] = content;
                             
                             parsePartial(partialName, _refStack, content, function(){
                                 
                                 /*log.dev('partialCount - before', partialCount);
                                 partialCount--;
                                 log.dev('partialCount - after', partialCount);
                                 */
                                 if(--branchNum == 0){
                                     callback();
                                 }
                             });
                         });
                     } else {
                         log.dev('hitCacheViewPartial', matched[0]);
                         entireContent = entireContent.replace(matched[0], asyncPartialMap[partialName]);
                         
                         parsePartial(matched[1], _refStack, asyncPartialMap[matched[1]], function(){
                             /*log.dev('partialCount cache - before', partialCount);
                             partialCount--;
                             log.dev('partialCount cache - after', partialCount);
                             */
                             if(--branchNum == 0){
                                 callback();
                             }
                         });
                         //entireContent = entireContent.replace(matched[0], asyncPartialMap[partialName]);
                         //callback();
                     }
                 }
             })(matched);
         }
     }
     
 };
Exemplo n.º 9
0
IpcRedisClient.prototype.onMessage = function(name, channel, msg)
{
    logger.dev("onMessage:", name, channel, msg);
    this.emit(channel, msg);
}
Exemplo n.º 10
0
    var theDirFiles = fs.readdirSync(theDir);
    for (var i = 0, len = theDirFiles.length; i < len; i++) {
        var thePath = theDir + '/' + theDirFiles[i];
        theDirFiles[i].indexOf('.') === -1 ? findAllTheDirFiles(thePath) : allTheDirFiles.push(thePath);
    }
};

if (fs.existsSync(publishBaseDir)) {
    findAllTheDirFiles(publishBaseDir);
    allTheDirFiles.forEach(function(file) {
        if (path.extname(file) == '.js') {
            require(file)(fw);
        };
    });
} else {
    log.dev(publishBaseDir + ' didnot exist');
}

var runStub = function(db) {
    
    //向所有client发送config更新信息
    fw.pushUpdateOfConfig = function(configMap){
        var subscribersAll = SubscribeMgr ? SubscribeMgr : [];
        
        for (var i in subscribersAll){
            var subscribers = subscribersAll[i];
            subscribers.forEach(function(item, index){
            (function(item){
                netMessage.sendMessage(configMap,
                           'config_write_from_server',
                           item.socketId,