Exemple #1
0
        public async Task InvokeDispatchWriteRequest(DispatchRequest requestWrite)
        {
            FtpClientResponse response = new FtpClientResponse {
                ErrorMessage = "", Status = "", FileData = new List <FtpClientResponseFile>()
            };
            var cancellationToken = CancellationToken.None;

            var ftpWriterOption = Deserialize <FtpWriterOption>(requestWrite.RequestDataBinary);

            response = await FtpWriteAsync(ftpWriterOption.FtpConfig, ftpWriterOption.WriteData, ftpWriterOption.FileName, cancellationToken);

            Logger.LogInformation($"{CurrentActor} FtpWriteAsync finished with response code {response.Status}. Data file: {ftpWriterOption.WriteData}");

            if (requestWrite.ResponseActorInfo != null)
            {
                var returnActorId =
                    requestWrite.ResponseActorInfo?.ActorId ??
                    Guid.NewGuid().ToString();
                var returnActorServiceUri =
                    requestWrite.ResponseActorInfo?.ActorServiceUri;
                var returnActionName   = requestWrite.ResponseActorInfo?.ActionName;
                var newExecutableOrder = new ExecutableOrchestrationOrder()
                {
                    ActorId         = returnActorId,
                    ActorServiceUri = returnActorServiceUri
                };

                await ChainNextActorsAsync <IFtpResponseParserAction>(c => c.InvokeHandleFtpWriteResponse(), new ActorRequestContext(Id.ToString(), returnActionName,
                                                                                                                                     Guid.NewGuid().ToString(), CurrentFlowInstanceId), newExecutableOrder, cancellationToken);
            }
        }
        public async Task <FtpClientResponse> FtpReadAsync(FtpConfig config, CancellationToken cancellationToken)
        {
            Func <string, Task <string> > myFunc   = ConfigKeyVault.GetSecureSecret;
            FtpClientResponse             response = new FtpClientResponse {
                ErrorMessage = "", Status = "", FileData = new List <FtpClientResponseFile>()
            };

            try
            {
                if (!string.IsNullOrEmpty(config.AzureBlobStorage.StorageAccountName))
                {
                    Func <string, string, string, MemoryStream, string, string, bool> copyFileFunc = FtpStorage.CopyFile;
                    // Retry the following call according to the policy - X times.
                    response = await ActorFtpClient.ReadAsync(config, myFunc, copyFileFunc);
                }
                else
                {
                    Func <string, string, string, MemoryStream, bool> copyFileFunc = FtpStorage.CopyFile;
                    response = await ActorFtpClient.ReadAsync(config, myFunc, copyFileFunc);
                }
            }
            catch (Exception e)
            {
                await ActorFtpClient.Stop();

                Logger.LogError(e, $"[FtpReadAsync] Failed to create FTP Client: " + e.Message);
            }

            return(response);
        }
        public async Task <FtpClientResponse> FtpWriteAsync(FtpConfig config, string data, string fileName, CancellationToken cancellationToken)
        {
            Func <string, Task <string> > myFunc = ConfigKeyVault.GetSecureSecret;

            FtpClientResponse response = new FtpClientResponse {
                ErrorMessage = "", Status = "", FileData = new List <FtpClientResponseFile>()
            };

            try
            {
                response = await ActorFtpClient.WriteAsync(config, myFunc, Encoding.UTF8.GetBytes(data), fileName);
            }
            catch (Exception e)
            {
                await ActorFtpClient.Stop();

                Logger.LogError(e, $"[FtpWriteAsync] Failed to write file: " + e.Message);
            }

            return(response);
        }
Exemple #4
0
        public async Task InvokeDispatchReadRequest(DispatchRequest requestRead)
        {
            FtpClientResponse response = new FtpClientResponse {
                ErrorMessage = "", Status = "", FileData = new List <FtpClientResponseFile>()
            };
            var cancellationToken = CancellationToken.None;

            var ftpOption = (FtpOption)requestRead.DeserializeRequestData();

            response = await FtpReadAsync(ftpOption.FtpConfig, cancellationToken);

            foreach (var file in response.FileData)
            {
                BlobStorageFileInfo fileInfo = new BlobStorageFileInfo()
                {
                    Container      = ftpOption.FtpConfig.AzureBlobStorage.ContainerName,
                    FileName       = file.FileName,
                    SourceFilePath = ftpOption.FtpConfig.Ftp.Host + '/' + ftpOption.FtpConfig.Ftp.Path
                };

                if (requestRead.ResponseActorInfo != null)
                {
                    var returnActorId =
                        requestRead.ResponseActorInfo?.ActorId ??
                        Guid.NewGuid().ToString();
                    var returnActorServiceUri =
                        requestRead.ResponseActorInfo?.ActorServiceUri;
                    var returnActionName   = requestRead.ResponseActorInfo?.ActionName;
                    var newExecutableOrder = new ExecutableOrchestrationOrder()
                    {
                        ActorId         = returnActorId,
                        ActorServiceUri = returnActorServiceUri
                    };

                    await ChainNextActorsAsync <IFtpResponseParserAction>(c => c.InvokeHandleFtpReadResponse(fileInfo), new ActorRequestContext(Id.ToString(), returnActionName,
                                                                                                                                                Guid.NewGuid().ToString(), CurrentFlowInstanceId), newExecutableOrder, cancellationToken);
                }
            }
        }