From 84c92a60fa0b86190ec6283dae9b25c9125c5ca7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 7 May 2018 11:53:52 +0200 Subject: [PATCH] Some Error Handling at timelineChart --- .vs/AAWeb/v15/.suo | Bin 70656 -> 70656 bytes TimelineChart.js | 202 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 153 insertions(+), 49 deletions(-) diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index 3cfb77eec571a7d2a4a94252aaa6b5b4cc0657a0..50bb7d328d55197286a63c93089df7f18de22b25 100644 GIT binary patch delta 298 zcmZoz!P2mTWkU`VE5lt`&6k@CnSL{~78vkp0hw(5b0;Tmw4J=>bjW0d)t-|*m)K5z zBg?m0b*TiWU=$+*6lfmE0kU}}A6%aTQnLB|Izd+K`nKjW@~($z1Jc_!&)*io$Qy)AwvoPXbF_xvgu3{7ar+FH*5gsmS}hY delta 228 zcmZoz!P2mTWkU`V>x7NXtdBPrGW}*|Rp^pe0W#V8=T4ruq;0a#>4eFds|_c=k>%U0 zx>SNwuz`^Q4*Egt$p_b`Oun_mcJupnf~=T&w&pTU-mspBk#+O@Z4nTrz-E>mmMr*8 z+OwH)^5#==n-A=}#EeDvk$FrI>0^hOCkvl`J30Tf?PS{}A)C%LaUt^;-LL@w-ML&D diff --git a/TimelineChart.js b/TimelineChart.js index c46fbcec0..8e9d27e6a 100644 --- a/TimelineChart.js +++ b/TimelineChart.js @@ -45,93 +45,197 @@ function initialize(exchange, market, pProductsPanel, callBackFunction) { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + try { - /* Remember the Products Panel */ + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - productsPanel = pProductsPanel; + /* Remember the Products Panel */ - /* Listen to the event of change of status */ + productsPanel = pProductsPanel; - productsPanel.container.eventHandler.listenToEvent("Product Card Status Changed", onProductCardStatusChanged); + /* Listen to the event of change of status */ - /* Legacy code to clean */ + productsPanel.container.eventHandler.listenToEvent("Product Card Status Changed", onProductCardStatusChanged); - marketId = market; - exchangeId = exchange; + /* Legacy code to clean */ - chartGrid = newChartGrid(); + marketId = market; + exchangeId = exchange; - recalculateScale(); - moveViewPortToCurrentDatetime(); + chartGrid = newChartGrid(); - /* Event Subscriptions - we need this events to be fired first here and then in active Plotters. */ + recalculateScale(); + moveViewPortToCurrentDatetime(); - viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + /* Event Subscriptions - we need this events to be fired first here and then in active Plotters. */ - initializeProductPlotters(); - initializeCompetitionPlotters(); + viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - callBackFunction(); + initializeCompetitionPlotters(onCompetitionPlottersInitialized); - initializationReady = true; + function onCompetitionPlottersInitialized(err) { + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onCompetitionPlottersInitialized -> Entering function."); } + + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onCompetitionPlottersInitialized -> Received OK Response."); } + break; + } + + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onCompetitionPlottersInitialized -> Received FAIL Response."); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + + default: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileCursorReady -> Received Unexpected Response."); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + } + + initializeProductPlotters(); + + initializationReady = true; + + callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE); + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } } - function initializeCompetitionPlotters() { + function initializeCompetitionPlotters(callBack) { - if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> Entering function."); } + try { - /* At this current version of the platform, we will support only one competition with only one plotter. */ + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> Entering function."); } - const COMPETITION_HOST = "AAArena"; - const COMPETITION = "First-Closed-Door"; + /* At this current version of the platform, we will support only one competition with only one plotter. */ - let objName = COMPETITION_HOST + "-" + COMPETITION; - let storage = newCompetitionStorage(objName); + const COMPETITION_HOST = "AAArena"; + const COMPETITION = "First-Closed-Door"; - let host = ecosystem.getHost(COMPETITION_HOST); - let competition = ecosystem.getCompetition(host, COMPETITION); + let objName = COMPETITION_HOST + "-" + COMPETITION; + let storage = newCompetitionStorage(objName); - storage.initialize(host, competition, DEFAULT_EXCHANGE, DEFAULT_MARKET, onCompetitionStorageInitialized); + let host = ecosystem.getHost(COMPETITION_HOST); + let competition = ecosystem.getCompetition(host, COMPETITION); - function onCompetitionStorageInitialized(err) { + storage.initialize(host, competition, DEFAULT_EXCHANGE, DEFAULT_MARKET, onCompetitionStorageInitialized); - if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> Entering function."); } + function onCompetitionStorageInitialized(err) { - /* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */ + try { - let plotter = getNewPlotter(competition.plotter.host, competition.plotter.codeName, competition.plotter.moduleName); + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> Entering function."); } - plotter.container.displacement.parentDisplacement = thisObject.container.displacement; - plotter.container.frame.parentFrame = thisObject.container.frame; + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { - plotter.container.parentContainer = thisObject.container; + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> Received OK Response."); } + break; + } - plotter.container.frame.width = thisObject.container.frame.width * 1; - plotter.container.frame.height = thisObject.container.frame.height * 1; + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { - plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2; - plotter.container.frame.position.y = thisObject.container.frame.height / 2 - plotter.container.frame.height / 2; + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> Received FAIL Response."); } + callBack(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } - plotter.initialize(competition, storage, datetime, timePeriod, onPlotterInizialized); + default: { - function onPlotterInizialized() { + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> Received Unexpected Response."); } + callBack(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + } - if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> Entering function."); } + /* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */ - let competitionPlotter = { - plotter: plotter, - storage: storage - }; + let plotter = getNewPlotter(competition.plotter.host, competition.plotter.codeName, competition.plotter.moduleName); - /* Add the new Active Protter to the Array */ + plotter.container.displacement.parentDisplacement = thisObject.container.displacement; + plotter.container.frame.parentFrame = thisObject.container.frame; - competitionPlotters.push(competitionPlotter); + plotter.container.parentContainer = thisObject.container; + plotter.container.frame.width = thisObject.container.frame.width * 1; + plotter.container.frame.height = thisObject.container.frame.height * 1; + + plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2; + plotter.container.frame.position.y = thisObject.container.frame.height / 2 - plotter.container.frame.height / 2; + + plotter.initialize(competition, storage, datetime, timePeriod, onPlotterInizialized); + + function onPlotterInizialized(err) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> Entering function."); } + + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> Received OK Response."); } + break; + } + + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> Received FAIL Response."); } + callBack(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + + default: { + + if (INFO_LOG === true) { logger.write("[INFO] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> Received Unexpected Response."); } + callBack(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + } + + let competitionPlotter = { + plotter: plotter, + storage: storage + }; + + /* Add the new Active Protter to the Array */ + + competitionPlotters.push(competitionPlotter); + + callBack(GLOBAL.DEFAULT_OK_RESPONSE); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> onPlotterInizialized -> err = " + err); } + callBack(GLOBAL.CUSTOM_FAIL_RESPONSE); + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initializeCompetitionPlotters -> onCompetitionStorageInitialized -> err = " + err); } + callBack(GLOBAL.CUSTOM_FAIL_RESPONSE); + } } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initializeCompetitionPlotters -> err = " + err); } + callBack(GLOBAL.CUSTOM_FAIL_RESPONSE); } }