コード例 #1
0
        public static async Task <bool> MoveFileToDataLakeWithRetry(string storageName, string folderPath, string fileName, Stream fileStream, Dictionary <string, string> keyValuePairs, int retryAttempts = 1)
        {
            string          fileSystemValue, tenantIDValue, applicationIdValue, authenticationKeyValue;
            OperationResult fileCreationResult = null;

            if (fileStream == null)
            {
                //SpendLoggerHelper.LogInfo("MoveFileToDataLakeWithRetrySSDL Method File Content/stream is null", "MoveFileToDataLake", partnerCode, partnerCode, "MoveFileToDataLake");
                throw new Exception("MoveFileToDataLakeWithRetrySSDL Method File Content/stream is null");
            }
            keyValuePairs.TryGetValue(OutputDataLakeSg2Path, out fileSystemValue);
            keyValuePairs.TryGetValue(TenantId, out tenantIDValue);
            keyValuePairs.TryGetValue(ApplicationId, out applicationIdValue);
            keyValuePairs.TryGetValue(AuthenticationKey, out authenticationKeyValue);

            if (string.IsNullOrEmpty(fileSystemValue) || string.IsNullOrEmpty(tenantIDValue) || string.IsNullOrEmpty(applicationIdValue) || string.IsNullOrEmpty(authenticationKeyValue))
            {
                //SpendLoggerHelper.LogInfo("MoveFileToDataLakeWithRetrySSDL Method Datalake Configuration missing", "MoveFileToDataLake", partnerCode, partnerCode, "MoveFileToDataLake");
                throw new Exception("MoveFileToDataLakeWithRetrySSDL Method Datalake Configuration missing");
            }

            try
            {
                DLStorageManagementClient.CreateClient(applicationIdValue, authenticationKeyValue, tenantIDValue, storageName);
                var datalakeStorageClient = new DLStorageManagementClient();

                for (int i = 0; i < retryAttempts; i++)
                {
                    fileCreationResult = await datalakeStorageClient.CreateFileAsync(fileSystemValue, folderPath, fileName, fileStream);

                    if (fileCreationResult.IsSuccessStatusCode)
                    {
                        return(fileCreationResult.IsSuccessStatusCode);
                    }
                }
                if (!fileCreationResult.IsSuccessStatusCode)
                {
                    //SpendLoggerHelper.LogInfo("MoveFileToDataLakeWithRetrySSDL Method Create file Failed as -" + fileCreationResult.StatusMessage, "MoveFileToDataLake", partnerCode, partnerCode, "MoveFileToDataLakeWithRetrySSDL");
                    throw new Exception("MoveFileToDataLakeWithRetrySSDL Method Create file Failed as -" + fileCreationResult.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                //SpendLoggerHelper.LogError(ex, "MoveFileToDataLakeWithRetrySSDL", partnerCode, partnerCode, "Common");
                throw;
            }
            return(fileCreationResult.IsSuccessStatusCode);
        }
コード例 #2
0
        public bool DeleteFileWithRetry(string storageName, string filePath, Dictionary <string, string> keyValuePairs, int retryAttempts = 1)
        {
            string          fileSystemValue, tenantIDValue, applicationIdValue, authenticationKeyValue;
            OperationResult fileCreationResult = null;

            keyValuePairs.TryGetValue(OutputDataLakeSg2Path, out fileSystemValue);
            keyValuePairs.TryGetValue(TenantId, out tenantIDValue);
            keyValuePairs.TryGetValue(ApplicationId, out applicationIdValue);
            keyValuePairs.TryGetValue(AuthenticationKey, out authenticationKeyValue);

            if (string.IsNullOrEmpty(fileSystemValue) || string.IsNullOrEmpty(tenantIDValue) || string.IsNullOrEmpty(applicationIdValue) || string.IsNullOrEmpty(authenticationKeyValue))
            {
                //SpendLoggerHelper.LogInfo("DeleteFileWithRetry Method Datalake Configuration missing", "DeleteFileWithRetry", partnerCode, contactCode, _applicationName);
                throw new Exception("DeleteFileWithRetry Method Datalake Configuration missing");
            }

            try
            {
                DLStorageManagementClient.CreateClient(applicationIdValue, authenticationKeyValue, tenantIDValue, storageName);
                var datalakeStorageClient = new DLStorageManagementClient();

                for (int i = 0; i < retryAttempts; i++)
                {
                    fileCreationResult = datalakeStorageClient.DeleteFileOrDirectory(fileSystemValue, filePath);

                    if (fileCreationResult.IsSuccessStatusCode)
                    {
                        return(fileCreationResult.IsSuccessStatusCode);
                    }
                }
                if (!fileCreationResult.IsSuccessStatusCode)
                {
                    //SpendLoggerHelper.LogInfo("DeleteFileWithRetry Method Create file Failed as -" + fileCreationResult.StatusMessage, "DeleteFileWithRetry", partnerCode, contactCode, _applicationName);
                    throw new Exception("DeleteFileWithRetry Method Create file Failed as -" + fileCreationResult.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                //SpendLoggerHelper.LogError(ex, "DeleteFileWithRetry", partnerCode, contactCode, _applicationName);
                throw;
            }
            return(fileCreationResult.IsSuccessStatusCode);
        }