From 4d433e6f7bcba5371738e339313075227cd1db74 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 27 Jun 2018 14:20:36 +0200 Subject: [PATCH] Error Handling and Logging Improved --- AABrowserAPI/UserAuthentication.js | 12 +- Canvas.js | 7 +- Dashboard.js | 77 ++++++++---- Files/FileCursor.js | 2 +- Scripts/AppLoader.js | 186 +++++++++++++++++------------ Scripts/AppPreLoader.js | 27 ++++- 6 files changed, 202 insertions(+), 109 deletions(-) diff --git a/AABrowserAPI/UserAuthentication.js b/AABrowserAPI/UserAuthentication.js index 407862402..dd983412b 100644 --- a/AABrowserAPI/UserAuthentication.js +++ b/AABrowserAPI/UserAuthentication.js @@ -5,7 +5,7 @@ let thisObject = { authenticateUser: authenticateUser, initialize: initialize - } + }; let sessionManager; let storageAccessManager; @@ -15,7 +15,7 @@ function initialize(pSessionManager, pStorageAccessManager) { sessionManager = pSessionManager; - storageAccessManager = pStorageAccessManager; + storageAccessManager = pStorageAccessManager; } @@ -35,7 +35,7 @@ return; } - /* The second posiibility is that the session is not found. */ + /* The second posiibility is that the session is not found. */ let session = sessionManager.getSession(pSessionToken); @@ -72,7 +72,7 @@ console.log(devTeam.codeName + "." + "READ" + ":" + readPermission); console.log(devTeam.codeName + "." + "WRITE" + ":" + writePermission); console.log(devTeam.codeName + "." + "DELETE" + ":" + writePermission); - + /* Each devTeam potentially depends on data from other devTeams. The user will need the storage permissions to read that data. */ for (j = 0; j < devTeam.devTeamDependencies.length; j++) { @@ -89,7 +89,7 @@ } } - + /* In order to be able to download a bot source code, the user will need READ permissions over the Platform container. */ let container = "aaplatform"; @@ -99,4 +99,4 @@ callBackFunction(global.DEFAULT_OK_RESPONSE, userProfile); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/Canvas.js b/Canvas.js index 99f8eeb73..bd5b86428 100644 --- a/Canvas.js +++ b/Canvas.js @@ -11,6 +11,7 @@ function newCanvas() { const MODULE_NAME = "Canvas"; const INFO_LOG = true; const ERROR_LOG = true; + const INTENSIVE_LOG = false; const logger = newWebDebugLog(); logger.fileName = MODULE_NAME; @@ -166,7 +167,7 @@ function newCanvas() { } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onAnimationInitialized -> onFunctionAdded -> -> err = " + err); } + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onAnimationInitialized -> onFunctionAdded -> err = " + err); } callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); } } @@ -470,7 +471,7 @@ function newCanvas() { try { - if (INFO_LOG === true) { logger.write("[INFO] onMouseMove -> Entering function."); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] onMouseMove -> Entering function."); } viewPort.mousePosition.x = event.pageX; viewPort.mousePosition.y = event.pageY; @@ -551,7 +552,7 @@ function newCanvas() { try { - if (INFO_LOG === true) { logger.write("[INFO] checkDrag -> Entering function."); } + if (INTENSIVE_LOG === true) { logger.write("[INFO] checkDrag -> Entering function."); } if (containerDragStarted === true || floatingObjectDragStarted === true || viewPortBeingDragged === true) { diff --git a/Dashboard.js b/Dashboard.js index 0739c7469..f6bed3383 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -105,7 +105,6 @@ function convertTimePeriodToName(pTimePeriod) { let cloudVM = newCloudVM(); window.AT_BREAKPOINT = false; -const DEBUG_START_UP_DELAY = 0 //3000; // This is a waiting time in case there is a need to debug the very first steps of initialization, to be able to hit F12 on time. const INITIAL_DEFAULT_MARKET = 2; // This is the market that will be shown when loading the site for the first time. const DEFAULT_EXCHANGE = "Poloniex"; const DEFAULT_MARKET = { @@ -178,31 +177,69 @@ maxDate.setDate(maxDate.getDate() + 10); const MAX_PLOTABLE_DATE = maxDate; -function dashboardStart() { +function newDashboard() { - setTimeout(start, DEBUG_START_UP_DELAY); - -} + const MODULE_NAME = "Dashboard"; + const INFO_LOG = true; + const ERROR_LOG = true; + const INTENSIVE_LOG = false; + const logger = newWebDebugLog(); + logger.fileName = MODULE_NAME; - -function start() { - - const ID_EXCHANGE_POLONIEX = 1; - - /* For now, we are supporting only one market. */ - - let market = { - id: 2, - assetA: "USDT", - assetB: "BTC" + let thisObject = { + start: start }; - markets = new Map(); + const DEBUG_START_UP_DELAY = 0 //3000; // This is a waiting time in case there is a need to debug the very first steps of initialization, to be able to hit F12 on time. - markets.set(market.id, market); + return thisObject; - canvas = newCanvas(); - canvas.initialize(); + function start() { + try { + + if (INFO_LOG === true) { logger.write("[INFO] start -> Entering function."); } + + setTimeout(delayedStart, DEBUG_START_UP_DELAY); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] start -> err = " + err); } + + } + } + + + function delayedStart() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] delayedStart -> Entering function."); } + + const ID_EXCHANGE_POLONIEX = 1; + + /* For now, we are supporting only one market. */ + + let market = { + id: 2, + assetA: "USDT", + assetB: "BTC" + }; + + markets = new Map(); + + markets.set(market.id, market); + + canvas = newCanvas(); + canvas.initialize(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] delayedStart -> err = " + err); } + + } + } } + + diff --git a/Files/FileCursor.js b/Files/FileCursor.js index f996cff5d..4170f206f 100644 --- a/Files/FileCursor.js +++ b/Files/FileCursor.js @@ -17,7 +17,7 @@ function newFileCursor() { getExpectedFiles: getExpectedFiles, initialize: initialize, finalize: finalize - } + }; let minCursorSize = 10; let maxCursorSize = 30; diff --git a/Scripts/AppLoader.js b/Scripts/AppLoader.js index f46bcbfec..7ba9e2eb8 100644 --- a/Scripts/AppLoader.js +++ b/Scripts/AppLoader.js @@ -1,9 +1,11 @@ function newAppLoader() { - const INFO_LOG = false; - const LOG_FILE_CONTENT = false; - const MODULE_NAME = "App Loader"; + const INFO_LOG = true; + const ERROR_LOG = true; + const INTENSIVE_LOG = false; + const logger = newWebDebugLog(); + logger.fileName = MODULE_NAME; let thisObject = { loadModules: loadModules @@ -13,106 +15,136 @@ function loadModules() { - let modulesArray = [ + try { - /* CloudWebScripts */ + if (INFO_LOG === true) { logger.write("[INFO] loadModules -> Entering function."); } - /* Plotters */ + let modulesArray = [ - /* PlotterPanels */ + /* CloudWebScripts */ - "BottomSpace/DeleteTradingHistory.js", + /* Plotters */ - "TopSpace/PlayStopButton.js", - "TopSpace/CompanyLogo.js", - "TopSpace/CurrentStartMode.js", - "TopSpace/CurrentProcess.js", - "TopSpace/CurrentBot.js", - "TopSpace/DevTeam.js", - "TopSpace/EndUser.js", + /* PlotterPanels */ - "Panels/TimeControlPanel.js", - "Panels/ProductsPanel.js", + "BottomSpace/DeleteTradingHistory.js", - "Spaces/BottomSpace.js", - "Spaces/TopSpace.js", - "Spaces/PanelsSpace.js", - "Spaces/ChartSpace.js", - "Spaces/FloatingSpace.js", + "TopSpace/PlayStopButton.js", + "TopSpace/CompanyLogo.js", + "TopSpace/CurrentStartMode.js", + "TopSpace/CurrentProcess.js", + "TopSpace/CurrentBot.js", + "TopSpace/DevTeam.js", + "TopSpace/EndUser.js", - "Files/SingleFile.js", - "Files/FileCloud.js", - "Files/MarketFiles.js", - "Files/DailyFiles.js", - "Files/FileCursor.js", - "Files/FileSequence.js", + "Panels/TimeControlPanel.js", + "Panels/ProductsPanel.js", - "FloatingSpace/NoteSets.js", - "FloatingSpace/Note.js", - "FloatingSpace/ProfileBalls.js", - "FloatingSpace/ProfileBall.js", - "FloatingSpace/FloatingObject.js", - "FloatingSpace/FloatingLayer.js", + "Spaces/BottomSpace.js", + "Spaces/TopSpace.js", + "Spaces/PanelsSpace.js", + "Spaces/ChartSpace.js", + "Spaces/FloatingSpace.js", - "CloudVM/PoloniexAPIClient.js", - "CloudVM/CloudSupport.js", - "CloudVM/CloudRequire.js", - "CloudVM/WebFS.js", - "CloudVM/CloudVM.js", + "Files/SingleFile.js", + "Files/FileCloud.js", + "Files/MarketFiles.js", + "Files/DailyFiles.js", + "Files/FileCursor.js", + "Files/FileSequence.js", - "BreakpointsBar.js", - "WebDebugLog.js", - "Plotter.js", - "PlotterPanel.js", + "FloatingSpace/NoteSets.js", + "FloatingSpace/Note.js", + "FloatingSpace/ProfileBalls.js", + "FloatingSpace/ProfileBall.js", + "FloatingSpace/FloatingObject.js", + "FloatingSpace/FloatingLayer.js", - "ProductStorage.js", - "CompetitionStorage.js", - "ProductCard.js", - "Ecosystem.js", + "CloudVM/PoloniexAPIClient.js", + "CloudVM/CloudSupport.js", + "CloudVM/CloudRequire.js", + "CloudVM/WebFS.js", + "CloudVM/CloudVM.js", - "SplashScreen.js", - "Canvas.js", - "TextButton.js", - "ImageButton.js", - "EventHandler.js", - "Frame.js", + "BreakpointsBar.js", + "Plotter.js", + "PlotterPanel.js", - "ViewPort.js", - "TimeMachine.js", - "Candle.js", - "VolumeBar.js", - "ChartUtilities.js", - "TimelineChart.js", - "ChartGrid.js", - "Animation.js", + "ProductStorage.js", + "CompetitionStorage.js", + "ProductCard.js", + "Ecosystem.js", - "Container.js", - "Displace.js", + "SplashScreen.js", + "Canvas.js", + "TextButton.js", + "ImageButton.js", + "EventHandler.js", + "Frame.js", - "Azure/azure-storage.blob.js", - "TimeLineCoordinateSystem.js", - "Utilities.js", - "Dashboard.js" - ]; + "ViewPort.js", + "TimeMachine.js", + "Candle.js", + "VolumeBar.js", + "ChartUtilities.js", + "TimelineChart.js", + "ChartGrid.js", + "Animation.js", - let downloadedCounter = 0; + "Container.js", + "Displace.js", - for (let i = 0; i < modulesArray.length; i++) { + "Azure/azure-storage.blob.js", + "TimeLineCoordinateSystem.js", + "Utilities.js", + "Dashboard.js" + ]; - let path = modulesArray[i]; + let downloadedCounter = 0; - REQUIREJS([path], onRequired); + for (let i = 0; i < modulesArray.length; i++) { - function onRequired(pModule) { + let path = modulesArray[i]; - //console.log(MODULE_NAME + ": " + path + " downloaded."); - downloadedCounter++; + REQUIREJS([path], onRequired); - if (downloadedCounter === modulesArray.length) { + if (INFO_LOG === true) { logger.write("[INFO] loadModules -> Module Requested."); } + if (INFO_LOG === true) { logger.write("[INFO] loadModules -> path = " + path); } + if (INFO_LOG === true) { logger.write("[INFO] loadModules -> total requested = " + (i + 1)); } - dashboardStart(); // This formally starts the app. + function onRequired(pModule) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] loadModules -> onRequired -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] loadModules -> onRequired -> Module Downloaded."); } + if (INFO_LOG === true) { logger.write("[INFO] loadModules -> onRequired -> path = " + path); } + + downloadedCounter++; + + if (INFO_LOG === true) { logger.write("[INFO] loadModules -> onRequired -> downloadedCounter = " + downloadedCounter); } + + if (downloadedCounter === modulesArray.length) { + + if (INFO_LOG === true) { logger.write("[INFO] loadModules -> onRequired -> Starting Advanced Algos Platform."); } + + let dashboard = newDashboard(); + + dashboard.start(); + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] loadModules -> onRequired -> err = " + err); } + + } } } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] loadModules -> err = " + err); } + } } } \ No newline at end of file diff --git a/Scripts/AppPreLoader.js b/Scripts/AppPreLoader.js index b018bf194..a7a1f5259 100644 --- a/Scripts/AppPreLoader.js +++ b/Scripts/AppPreLoader.js @@ -30,6 +30,8 @@ GLOBAL.CUSTOM_FAIL_RESPONSE = { function loadAdvancedAlgosPlatform() { + console.log("AppPreLoader : " + "[INFO] loadAdvancedAlgosPlatform -> Entering function."); + /* The first thing to do here is to add the canvas where all the action is going to happen. */ let canvas = document.createElement('canvas'); @@ -54,6 +56,8 @@ function loadAdvancedAlgosPlatform() { function onServerReponded(pResponseFromServer) { + console.log("AppPreLoader : " + "[INFO] loadAdvancedAlgosPlatform -> onServerReponded -> Entering function."); + let responseFromServer = JSON.parse(pResponseFromServer); err = responseFromServer.err; @@ -67,20 +71,39 @@ function loadAdvancedAlgosPlatform() { window.USER_PROFILE = responseFromServer.userProfile; - loadModules(); + loadDebugModule(); + } + + function loadDebugModule() { + + console.log("AppPreLoader : " + "[INFO] loadDebugModule -> Entering function."); + + let path = "WebDebugLog.js"; + + REQUIREJS([path], onRequired); + + function onRequired(pModule) { + + console.log("AppPreLoader : " + "[INFO] " + path + " downloaded."); + + loadModules(); + + } } /* And Finally, we start loading all the scripts we will inmediatelly need. */ function loadModules() { + console.log("AppPreLoader : " + "[INFO] loadModules -> Entering function."); + let path = "Scripts/AppLoader.js"; REQUIREJS([path], onRequired); function onRequired(pModule) { - console.log(path + " downloaded."); + console.log("AppPreLoader : " + "[INFO] " + path + " downloaded."); let APP_LOADER_MODULE = newAppLoader(); APP_LOADER_MODULE.loadModules();