From c96db5ab50bb3d43b24be118e7a44830266d0f74 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 7 Mar 2018 18:46:20 +0100 Subject: [PATCH] Azure File storage fully upgraded --- .vs/AACloudPlatform/v15/.suo | Bin 74240 -> 74240 bytes Azure File Storage.js | 119 ++++++++++++++++++++++------------- 2 files changed, 76 insertions(+), 43 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 498bf5021333e0661ebe9737f5e9212acc17ca55..acc18ee2299fde1d25a29a027ddd0b3b81a13d21 100644 GIT binary patch delta 486 zcmZoT!qRYrWrGhBBglM9(HPj+G7Gl@kZfuDhaK>>)_fLIKO|3iT? zkS!0yfj}$@#A-kclj8%jC6V~5P_{ad{tHxO3gvSG>B$W&BBFvoh6)g;KqZoZH23C} zEQ=W@`!Ff6F3A3`ZZo-%?J@_*WIZ6Byx@ewWCJFi%@ypYIVL*`8g4ET@Mq)%yMPxV z&oTLnpg$)g$ap3s(aj}7A&e}j>V&UsJ|ShnxJZL#lDNWV1rZG<7Gy1xOT^A|GJ-tF zj$)8(57QzQrbS9jn~W5gHY=z-U|(dyw8=n$WwV0S1I9&WEQ=hN7TK^&5_5()4pp~I z5921M#k0iz0?mX04n|1exh$KUxTkQk%oe`MJ2$#dPM9SFWT$NYe|L$77#mOx49Ec4 Q(LfG%_1pimGcrm603N@c5dZ)H delta 464 zcmZoT!qRYrWrGjXWFIyKR)M!t!lsi8nJ#niGB7ac0rBJoCln?dF!4;TU|x|R2oz8N zVoo4t1LFTspbTV70&yS^a{;j$5X0p7fNW7Dz6_MD4y09q*c8hD3)C>Vfki}A3@D%i z#3@jTBp}Vdc_qtYMn?9@icIpX8& initialize function not executed or failed. Can not process this request. Sorry."); + logger.write("[ERROR] createTextFile -> initialize function not executed or failed. Can not process this request. Sorry."); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -146,9 +146,9 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { logger.write("[INFO] createTextFile -> onFileCreated -> secondTry -> Retrying to create the file."); - fileService.createFileFromText(shareName, pFolderPath, pFileName, pFileContent, onFileCreatedSecondTry); + fileService.createFileFromText(shareName, pFolderPath, pFileName, pFileContent, onSecondTry); - function onFileCreatedSecondTry(err) { + function onSecondTry(err) { if (err) { logger.write("[ERROR] createTextFile -> onFileCreated -> secondTry -> File not created. Giving Up."); @@ -171,57 +171,86 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { } } catch (err) { - logger.write("[ERROR] 'createTextFile' - ERROR : " + JSON.stringify(err)); + logger.write("[ERROR] 'createTextFile' -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } - function getTextFile(pFolderPath, pFileName, callBackFunction, ignoreNotFound) { + function getTextFile(pFolderPath, pFileName, callBackFunction) { if (fileService === undefined) { - const logText = "[ERROR] initialize function not executed or failed. Can not process this request. Sorry."; - logger.write(logText); + logger.write("[ERROR] getTextFile -> initialize function not executed or failed. Can not process this request. Sorry."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } try { + if (FULL_LOG === true) { + logger.write("[INFO] getTextFile -> About to get a text file."); + logger.write("[INFO] getTextFile -> shareName = " + shareName); + logger.write("[INFO] getTextFile -> pFolderPath = " + pFolderPath); + logger.write("[INFO] getTextFile -> pFileName = " + pFileName); + } + fileService.getFileToText(shareName, pFolderPath, pFileName, undefined, onFileReceived); function onFileReceived(err, text, response) { - if (err) { - - if (ignoreNotFound === undefined) { - - const logText = "[ERROR] getTextFile - onFileReceived ' ERROR = " + err.message + " SHARE NAME = " + shareName + " FOLDER PATH = " + pFolderPath + " FILE NAME = " + pFileName; - console.log(logText); - logger.write(logText); - - } - - text = undefined; - + if (FULL_LOG === true) { + logger.write("[INFO] getTextFile -> onFileReceived -> Response from Azure received."); + logger.write("[INFO] getTextFile -> onFileReceived -> err = " + JSON.stringify(err)); + logger.write("[INFO] getTextFile -> onFileReceived -> text = " + text); + logger.write("[INFO] getTextFile -> onFileReceived -> response = " + JSON.stringify(response)); } - callBackFunction(text); - } + if (err) { + + if (err.message.indexOf("The server is busy") > 0) { + setTimeout(secondTry, 1000); + + function secondTry() { + + logger.write("[INFO] getTextFile -> onFileReceived -> secondTry -> Retrying to get the file."); + + fileService.getFileToText(shareName, pFolderPath, pFileName, undefined, onSecondTry); + + function onSecondTry(err) { + + if (err) { + logger.write("[ERROR] getTextFile -> onFileReceived -> secondTry -> File not retrieved. Giving Up."); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); + } else { + logger.write("[INFO] getTextFile -> onFileReceived -> secondTry -> File succesfully retrieved on second try."); + callBackFunction(global.DEFAULT_OK_RESPONSE); + } + } + } + } + + logger.write("[ERROR] getTextFile -> onFileReceived -> Dont know what to do here. Cancelling operation. "); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + + } else { + if (LOG_INFO === true) { logger.write("[INFO] getTextFile -> onFileReceived -> File retrieved."); } + callBackFunction(global.DEFAULT_OK_RESPONSE, text); + } + } } catch (err) { - const logText = "[ERROR] 'getTextFile' - ERROR : " + err.message; - logger.write(logText); + logger.write("[ERROR] 'getTextFile' -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } - } function listFilesAndFolders(pFolderPath, callBackFunction) { if (fileService === undefined) { - const logText = "[ERROR] initialize function not executed or failed. Can not process this request. Sorry."; - logger.write(logText); + logger.write("[ERROR] listFilesAndFolders -> initialize function not executed or failed. Can not process this request. Sorry."); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -233,6 +262,8 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { }; /* + * AZURE HELP: + * * @param { object } [options] The request options. * @param { int } [options.maxResults] Specifies the maximum number of folders to return per call to Azure ServiceClient. * This does NOT affect list size returned by this function. (maximum: 5000) @@ -250,44 +281,46 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { maxResults: 500 }; + if (FULL_LOG === true) { + logger.write("[INFO] listFilesAndFolders -> About to get the list of files and folders."); + logger.write("[INFO] listFilesAndFolders -> shareName = " + shareName); + logger.write("[INFO] listFilesAndFolders -> pFolderPath = " + pFolderPath); + } + fileService.listFilesAndDirectoriesSegmented(shareName, pFolderPath, null, options, onFilesAndFoldersReceived); - - function onFilesAndFoldersReceived(error, result) { + function onFilesAndFoldersReceived(err, result) { try { + if (FULL_LOG === true) { + logger.write("[INFO] listFilesAndFolders -> onFileReceived -> Response from Azure received."); + logger.write("[INFO] listFilesAndFolders -> onFileReceived -> shareName = " + shareName); + logger.write("[INFO] listFilesAndFolders -> onFileReceived -> pFolderPath = " + pFolderPath); + } - if (error) { + if (err) { - const logText = "[ERROR] 'listFilesAndFolders - onFilesAndFoldersReceived' - ERROR RECEIVED : " + error; - logger.write(logText); - - callBackFunction(items); + logger.write("[ERROR] 'listFilesAndFolders' -> onFilesAndFoldersReceived -> err = " + err); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + return; } else { items.files.push.apply(items.files, result.entries.files); items.folders.push.apply(items.folders, result.entries.directories); - callBackFunction(items); - + callBackFunction(global.DEFAULT_OK_RESPONSE, items); } - } - - catch (err) { const logText = "[ERROR] 'listFilesAndFolders - onFilesAndFoldersReceived' - ERROR : " + err.message; logger.write(logText); } - } - } catch (err) { - const logText = "[ERROR] 'listFilesAndFolders' - ERROR : " + err.message; - logger.write(logText); + logger.write("[ERROR] 'listFilesAndFolders' -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } - }; \ No newline at end of file