diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index 5b6ce0a02..9a858dd1e 100644 Binary files a/.vs/AAWeb/v15/.suo and b/.vs/AAWeb/v15/.suo differ diff --git a/Dashboard.js b/Dashboard.js index 8c31925bf..c886f0bd2 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -1,5 +1,31 @@ - +/* Callbacks default responses. */ +let GLOBAL = {}; + +GLOBAL.DEFAULT_OK_RESPONSE = { + result: "Ok", + message: "Operation Succeeded" +}; + +GLOBAL.DEFAULT_FAIL_RESPONSE = { + result: "Fail", + message: "Operation Failed" +}; + +GLOBAL.DEFAULT_RETRY_RESPONSE = { + result: "Retry", + message: "Retry Later" +}; + +GLOBAL.CUSTOM_OK_RESPONSE = { + result: "Ok, but check Message", + message: "Custom Message" +}; + +GLOBAL.CUSTOM_FAIL_RESPONSE = { + result: "Fail Because", + message: "Custom Message" +}; /* The Dashboard is the root object that contains all the other stuff in it. Some of that stuff is visible, some other is invisible. */ diff --git a/Files/FileCloud.js b/Files/FileCloud.js index 27f7467ad..fbf3912bf 100644 --- a/Files/FileCloud.js +++ b/Files/FileCloud.js @@ -1,7 +1,10 @@  function newFileCloud() { - const CONSOLE_LOG = false; + const MODULE_NAME = "File Cloud"; + const FULL_LOG = true; + const logger = newDebugLog(); + logger.fileName = MODULE_NAME; var fileCloud = { getFile: getFile, @@ -14,24 +17,30 @@ function newFileCloud() { function initialize(pBot) { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> pBot = " + pBot.codeName); } + blobService = AzureStorage.Blob.createBlobServiceWithSas(pBot.storage.fileUri, pBot.storage.sas); } function getFile(pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, callBackFunction) { + if (FULL_LOG === true) { logger.write("[INFO] getFile -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] getFile -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pSet.filePath + "-" + pSet.fileName); } + let fileName = pSet.fileName; let filePath = pSet.filePath; if (fileName === undefined) { - console.log("Inconsistant data. Check the following: "); - console.log(JSON.stringify(pDevTeam)); - console.log(JSON.stringify(pBot)); - console.log(JSON.stringify(pSet)); - console.log(JSON.stringify(pExchange)); - console.log(JSON.stringify(pMarket)); - console.log(JSON.stringify(pPeriodName)); + logger.write("[ERROR] getFile -> Inconsistant data. Check the following: "); + logger.write("[ERROR] getFile -> pDevTeam = " + JSON.stringify(pDevTeam)); + logger.write("[ERROR] getFile -> pBot = " + JSON.stringify(pBot)); + logger.write("[ERROR] getFile -> pSet = " + JSON.stringify(pSet)); + logger.write("[ERROR] getFile -> pExchange = " + JSON.stringify(pExchange)); + logger.write("[ERROR] getFile -> pMarket = " + JSON.stringify(pMarket)); + logger.write("[ERROR] getFile -> pPeriodName = " + JSON.stringify(pPeriodName)); throw ("Inconsistant data received."); } @@ -74,21 +83,46 @@ function newFileCloud() { fileName = fileName.replace("@Sequence", pSequence); } - blobService.getBlobToText('data', filePath + "/" + fileName, onFileReceived); + if (FULL_LOG === true) { logger.write("[INFO] getFile -> filePath = " + filePath); } + if (FULL_LOG === true) { logger.write("[INFO] getFile -> fileName = " + fileName); } - if (CONSOLE_LOG === true) { + try { - console.log("FileCloud -> File Requested -> " + filePath + "/" + fileName); + blobService.getBlobToText('data', filePath + "/" + fileName, onFileReceived); + + } catch (err) { + + if (FULL_LOG === true) { logger.write("[ERROR] getFile -> err = " + err); } } function onFileReceived(err, text, response) { + if (FULL_LOG === true) { logger.write("[INFO] getFile -> onFileReceived -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] getFile -> onFileReceived -> filePath = " + filePath); } + if (FULL_LOG === true) { logger.write("[INFO] getFile -> onFileReceived -> fileName = " + fileName); } + let data; if (err) { - data = JSON.parse("[]"); + if (err.code === "BlobNotFound") { + + let customErr = { + result: GLOBAL.CUSTOM_FAIL_RESPONSE.result, + message: "File does not exist." + }; + + if (FULL_LOG === true) { logger.write("[WARN] getFile -> onFileReceived -> customErr.message = " + customErr.message); } + + callBackFunction(customErr); + return; + } + + if (FULL_LOG === true) { logger.write("[ERROR] getFile -> onFileReceived -> Unexpected Error Ocurred."); } + if (FULL_LOG === true) { logger.write("[ERROR] getFile -> onFileReceived -> err = " + err); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; } else { @@ -96,15 +130,26 @@ function newFileCloud() { data = JSON.parse(text); + if (FULL_LOG === true) { logger.write("[INFO] getFile -> onFileReceived -> Data received is valid JSON."); } + + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, data); + return; + } catch (err) { - data = JSON.parse("[]"); + if (FULL_LOG === true) { logger.write("[WARN] getFile -> onFileReceived -> err = " + err); } + let customErr = { + result: GLOBAL.CUSTOM_OK_RESPONSE.result, + message: "Data not in JSON Format." + }; + + if (FULL_LOG === true) { logger.write("[WARN] getFile -> onFileReceived -> customErr.message = " + customErr.message); } + + callBackFunction(customErr, text); + return; } } - - callBackFunction(data); - } } } \ No newline at end of file diff --git a/Files/FileSequence.js b/Files/FileSequence.js index 9de4e7d2c..e74c90cf8 100644 --- a/Files/FileSequence.js +++ b/Files/FileSequence.js @@ -1,6 +1,11 @@  function newFileSequence() { + const MODULE_NAME = "File Sequence"; + const FULL_LOG = true; + const logger = newDebugLog(); + logger.fileName = MODULE_NAME; + let thisObject = { getFile: getFile, getExpectedFiles: getExpectedFiles, @@ -20,6 +25,9 @@ function newFileSequence() { function initialize(pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } + let exchange = ecosystem.getExchange(pProduct, pExchange); if (exchange === undefined) { @@ -35,7 +43,50 @@ function newFileSequence() { fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, "Sequence", onSequenceFileReceived); - function onSequenceFileReceived(file) { + function onSequenceFileReceived(err, file) { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } + + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received OK Response."); } + break; + } + + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received FAIL Response."); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + + case GLOBAL.CUSTOM_OK_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM OK Response."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); } + + callBackFunction(err); + return; + } + + case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM FAIL Response."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); } + + callBackFunction(err); + return; + } + + default: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received Unexpected Response."); } + callBackFunction(err); + return; + } + } maxSequence = Number(file); @@ -45,13 +96,44 @@ function newFileSequence() { fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, i, onFileReceived); - function onFileReceived(file) { + function onFileReceived(err, file) { + + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received OK Response."); } + break; + } + + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response."); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + + case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> err.message = " + err.message); } + + callBackFunction(err); + return; + } + + default: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response."); } + callBackFunction(err); + return; + } + } files.set(i, file); filesLoaded++; - callBackFunction(); // Note that the callback is called for every file loaded. + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); // Note that the callback is called for every file loaded. } } @@ -60,18 +142,25 @@ function newFileSequence() { function getFile(pSequence) { + if (FULL_LOG === true) { logger.write("[INFO] getFile -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] getFile -> pSequence = " + pSequence); } + return files.get(pSequence); } function getExpectedFiles() { + if (FULL_LOG === true) { logger.write("[INFO] getExpectedFiles -> Entering function."); } + return maxSequence + 1; } function getFilesLoaded() { + if (FULL_LOG === true) { logger.write("[INFO] getFilesLoaded -> Entering function."); } + return filesLoaded; } diff --git a/ProductStorage.js b/ProductStorage.js index 8f7d0027d..24d6d86d6 100644 --- a/ProductStorage.js +++ b/ProductStorage.js @@ -1,7 +1,10 @@  function newProductStorage(pName) { - const CONSOLE_LOG = false; + const MODULE_NAME = "Product Storage"; + const FULL_LOG = true; + const logger = newDebugLog(); + logger.fileName = MODULE_NAME; /* @@ -40,15 +43,12 @@ function newProductStorage(pName) { function initialize(pDevTeam, pBot, pProduct, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } + datetime = pDatetime; timePeriod = pTimePeriod; - if (CONSOLE_LOG === true) { - - console.log("Product storage initialize for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); - - } - let dataSetsToLoad = 0; let dataSetsLoaded = 0; @@ -59,68 +59,49 @@ function newProductStorage(pName) { switch (thisSet.type) { case 'Market Files': { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> Market Files -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } + thisObject.fileCache = newFileCache(); thisObject.fileCache.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onCacheFileReady); dataSetsToLoad++; - - if (CONSOLE_LOG === true) { - - console.log("Product storage initialize Market Files for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); - - } } break; case 'Daily Files': { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> Daily Files -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } + thisObject.fileCursorCache = newFileCursorCache(); thisObject.fileCursorCache.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, pDatetime, pTimePeriod, onFileCursorReady); dataSetsToLoad++; - - if (CONSOLE_LOG === true) { - - console.log("Product storage initialize Daily Files for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); - - } } break; case 'Single File': { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> Single File -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } + thisObject.file = newFile(); thisObject.file.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onSingleFileReady); dataSetsToLoad++; - - if (CONSOLE_LOG === true) { - - console.log("Product storage initialize Single File for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); - - } } break; case 'File Sequence': { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> File Sequence -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } + thisObject.fileSequence = newFileSequence(); thisObject.fileSequence.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onFileSequenceReady); dataSetsToLoad++; - - if (CONSOLE_LOG === true) { - - console.log("Product storage initialize File Sequence for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); - - } } break; } function onCacheFileReady() { - if (CONSOLE_LOG === true) { - - console.log("Product storage initialize onCacheFileReady for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); - - } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onCacheFileReady -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onCacheFileReady -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } let event = { totalValue: thisObject.fileCache.getExpectedFiles(), @@ -139,11 +120,8 @@ function newProductStorage(pName) { function onFileCursorReady() { - if (CONSOLE_LOG === true) { - - console.log("Product storage initialize onFileCursorReady for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); - - } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onFileCursorReady -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onFileCursorReady -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } let event = { totalValue: thisObject.fileCursorCache.getExpectedFiles(), @@ -162,11 +140,8 @@ function newProductStorage(pName) { function onSingleFileReady() { - if (CONSOLE_LOG === true) { - - console.log("Product storage initialize onSingleFileReady for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); - - } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } let event = { totalValue: 1, @@ -183,12 +158,40 @@ function newProductStorage(pName) { } } - function onFileSequenceReady() { + function onFileSequenceReady(err) { - if (CONSOLE_LOG === true) { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } - console.log("Product storage initialize onFileSequenceReady for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received OK Response."); } + break; + } + + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received FAIL Response."); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + + case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received CUSTOM FAIL Response."); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> err.message = " + err.message); } + + callBackFunction(err); + return; + } + + default: { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received Unexpected Response."); } + callBackFunction(err); + return; + } } let event = { @@ -208,15 +211,12 @@ function newProductStorage(pName) { function checkInitializeComplete() { - if (CONSOLE_LOG === true) { - - console.log("Product storage initialize checkInitializeComplete for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); - - } + if (FULL_LOG === true) { logger.write("[INFO] checkInitializeComplete -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] checkInitializeComplete -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } if (dataSetsLoaded === dataSetsToLoad) { - callBackFunction(); + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); } } @@ -225,6 +225,8 @@ function newProductStorage(pName) { function setDatetime(pDatetime) { + if (FULL_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } + /* If there is a change in the day, then we take some actions, otherwise, we dont. */ let currentDate = Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS); @@ -244,6 +246,8 @@ function newProductStorage(pName) { function setTimePeriod(pTimePeriod) { + if (FULL_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } + /* We are going to filter out the cases in which the timePeriod received is the same that the one we already know. */ if (timePeriod !== pTimePeriod) { diff --git a/Spaces/ChartSpace.js b/Spaces/ChartSpace.js index 1cc135f08..a4fd82ee3 100644 --- a/Spaces/ChartSpace.js +++ b/Spaces/ChartSpace.js @@ -9,7 +9,7 @@ changes, then all charts in it are replotted with the corresponging data. function newChartSpace() { const MODULE_NAME = "Chart Space"; - const FULL_LOG = true; + const FULL_LOG = false; const logger = newDebugLog(); logger.fileName = MODULE_NAME; diff --git a/TimelineChart.js b/TimelineChart.js index e50b18b11..1800e6c8a 100644 --- a/TimelineChart.js +++ b/TimelineChart.js @@ -1,7 +1,7 @@ function newTimelineChart() { const MODULE_NAME = "Timeline Chart"; - const FULL_LOG = false; + const FULL_LOG = true; const logger = newDebugLog(); logger.fileName = MODULE_NAME; @@ -100,7 +100,7 @@ storage.initialize(host, competition, onStorageInitialized); - function onStorageInitialized() { + function onStorageInitialized(err) { if (FULL_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onStorageInitialized -> Entering function."); } @@ -208,9 +208,41 @@ storage.initialize(pProductCard.devTeam, pProductCard.bot, pProductCard.product, DEFAULT_EXCHANGE, DEFAULT_MARKET, datetime, timePeriod, onStorageInitialized) ; - function onStorageInitialized() { + function onStorageInitialized(err) { if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> key = " + pProductCard.devTeam.codeName + "-" + pProductCard.bot.codeName + "-" + pProductCard.product.codeName); } + + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> Received OK Response."); } + if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> The plotter will be started."); } + break; + } + + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> Received FAIL Response."); } + if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> The plotter will not be started."); } + return; + } + + case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { + + if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> Received CUSTOM FAIL Response."); } + if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> err.message = " + err.message); } + if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> The plotter will not be started."); } + return; + } + + default: { + + if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> Received Unexpected Response."); } + if (FULL_LOG === true) { logger.write("[INFO] initializeProductPlotter -> onStorageInitialized -> The plotter will not be started."); } + return; + } + } /* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */