protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { //Get the properties which are configured in UiPath custom activity string strSourceFullFilePath = sourceFullFilePath.Get(context); string strAccountName = accountName.Get(context); string strAccountKey = accountKey.Get(context); string strDestinationFileName = fileName.Get(context); string strShareName = shareName.Get(context); string strAwsRegionName = awsRegionName.Get(context); string strCloudProviderName = cloudProviderName.Get(context); string strActionType = actionType.Get(context);//download or upload action //end Get the properties which are configured in UiPath custom activity if (strCloudProviderName.ToLower().Equals("aws")) { //Using AWSHelper - AWS S3 if (strActionType.ToLower().Equals("download")) { asyncS3FileDownloadFunc fileDownloadFromS3Func = new asyncS3FileDownloadFunc(downloadFileFromS3); context.UserState = fileDownloadFromS3Func; return(fileDownloadFromS3Func.BeginInvoke(strDestinationFileName, strShareName, strSourceFullFilePath, strAccountName, strAccountKey, strAwsRegionName, callback, state)); } else if (strActionType.ToLower().Equals("upload")) { asyncS3FileUploadFunc fileUploadToS3Func = new asyncS3FileUploadFunc(uploadFileToS3); context.UserState = fileUploadToS3Func; return(fileUploadToS3Func.BeginInvoke(strShareName, strDestinationFileName, strSourceFullFilePath, strAccountName, strAccountKey, strAwsRegionName, callback, state)); } }//end if AWS if (strCloudProviderName.ToLower().Equals("azure")) { //using AzureHelper - Azure if (strActionType.ToLower().Equals("download")) { asyncAzureFileDownloadFunc fileDownloadFunc = new asyncAzureFileDownloadFunc(downloadFileFromAzure); context.UserState = fileDownloadFunc; return(fileDownloadFunc.BeginInvoke(strSourceFullFilePath, strDestinationFileName, strAccountName, strAccountKey, strShareName, callback, state)); } else if (strActionType.ToLower().Equals("upload")) { asyncAzureFileUploadFunc fileUploadFunc = new asyncAzureFileUploadFunc(uploadFileToAzure); context.UserState = fileUploadFunc; return(fileUploadFunc.BeginInvoke(strSourceFullFilePath, strDestinationFileName, strAccountName, strAccountKey, strShareName, callback, state)); } }//end if Azure //default: do nothing if specify not AWS or Azure as cloud provider in the UIPath customer activity. T return(Task.Run(() => DoNothing())); }
protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result) { //Get the properties which are configured in UiPath custom activity string strSourceFullFilePath = sourceFullFilePath.Get(context); string strAccountName = accountName.Get(context); string strAccountKey = accountKey.Get(context); string strDestinationFileName = fileName.Get(context); string strShareName = shareName.Get(context); string strAwsRegionName = awsRegionName.Get(context); string strCloudProviderName = cloudProviderName.Get(context); string strActionType = actionType.Get(context);//download or upload action //end Get the properties which are configured in UiPath custom activity if (strCloudProviderName.ToLower().Equals("azure")) { //Azure: get the delegate from the UserState and call EndInvoke if (strActionType.ToLower().Equals("download")) { asyncAzureFileDownloadFunc fileDownloadFunc = (asyncAzureFileDownloadFunc)context.UserState; fileDownloadFunc.EndInvoke(result); } else if (strActionType.ToLower().Equals("upload")) { asyncAzureFileUploadFunc fileUploadFunc = (asyncAzureFileUploadFunc)context.UserState; fileUploadFunc.EndInvoke(result); } }//end if Azure //AWS S3: if (strCloudProviderName.ToLower().Equals("aws")) { if (strActionType.ToLower().Equals("download")) { asyncS3FileDownloadFunc fileDownloadFunc = (asyncS3FileDownloadFunc)context.UserState; fileDownloadFunc.EndInvoke(result); } else if (strActionType.ToLower().Equals("upload")) { asyncS3FileUploadFunc fileUploadFunc = (asyncS3FileUploadFunc)context.UserState; fileUploadFunc.EndInvoke(result); } } //end if AWS } //end EndExecute