public static async Task TransferFileAsync(AzureFileTransferInfo transferInfo, ISystemConfiguratorProxy systemConfiguratorProxy) { // // C++ Azure Blob SDK not supported for ARM, so use Service to copy file to/from // App's LocalData and then use C# Azure Blob SDK to transfer // var appLocalDataFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(transferInfo.BlobName, CreationCollisionOption.ReplaceExisting); transferInfo.AppLocalDataPath = appLocalDataFile.Path; if (!transferInfo.Upload) { transferInfo.AppLocalDataPath = await DownloadFile(transferInfo, appLocalDataFile); } // use C++ service to copy file to/from App LocalData var request = new AzureFileTransferRequest(transferInfo); var result = await systemConfiguratorProxy.SendCommandAsync(request); if (transferInfo.Upload) { await UploadFile(transferInfo, appLocalDataFile); } await appLocalDataFile.DeleteAsync(); }
private async Task <string> UploadDMFile(string jsonParamString) { Logger.Log("Uploading DM file...", LoggingLevel.Information); try { object paramsObject = JsonConvert.DeserializeObject(jsonParamString); if (paramsObject == null || !(paramsObject is JObject)) { throw new Error(ErrorCodes.INVALID_PARAMS, "Invalid enumDMFiles parameters."); } JObject jsonParamsObject = (JObject)paramsObject; string folderName = GetParameter(jsonParamsObject, JsonFolder, ErrorCodes.INVALID_FOLDER_PARAM, "Invalid or missing folder parameter."); string fileName = GetParameter(jsonParamsObject, JsonFile, ErrorCodes.INVALID_FILE_PARAM, "Invalid or missing folder parameter."); var info = new AzureFileTransferInfo(); info.ConnectionString = GetParameter(jsonParamsObject, JsonConnectionString, ErrorCodes.INVALID_CONNECTION_STRING_PARAM, "Invalid or missing connection string parameter."); info.ContainerName = GetParameter(jsonParamsObject, JsonContainer, ErrorCodes.INVALID_CONTAINER_PARAM, "Invalid or missing container parameter."); info.BlobName = fileName; info.Upload = true; info.RelativeLocalPath = folderName + "\\" + fileName; info.AppLocalDataPath = ApplicationData.Current.TemporaryFolder.Path + "\\" + fileName; AzureFileTransferRequest request = new AzureFileTransferRequest(info); var response = _systemConfiguratorProxy.SendCommand(request); if (response.Status != ResponseStatus.Success) { throw new Error(ErrorCodes.ERROR_MOVING_FILE, "SystemConfigurator failed to move file."); } Logger.Log("File copied to UWP application temporary folder...", LoggingLevel.Information); var appLocalDataFile = await ApplicationData.Current.TemporaryFolder.GetFileAsync(fileName); Logger.Log("Uploading file...", LoggingLevel.Information); await IoTDMClient.AzureBlobFileTransfer.UploadFile(info, appLocalDataFile); Logger.Log("Upload done. Deleting local temporary file...", LoggingLevel.Information); await appLocalDataFile.DeleteAsync(); Logger.Log("Temporary file deleted..", LoggingLevel.Information); return(BuildMethodJsonResponseString("" /*payload*/, SuccessCode, "" /*error message*/)); } catch (Exception err) { return(BuildMethodJsonResponseString("", err.HResult, err.Message)); } }