public async Task InvokeGenerateWriteRequest(object content) { if (content is ICsvContent csvContent) { var csvData = csvContent.ToCsv(); var ftpOption = (await GetFtpConfigsAsync()).ToList().First(); var ftpWriterOption = new FtpWriterOption(ftpOption.FtpConfig, csvData.Item1, csvData.Item2); var ftpDispatchRequest = new DispatchRequest(ftpWriterOption, typeof(FtpWriterOption), null, ReponseParserActor, null); // for dispatcher if need to send events //await GenerateRequestAsync(ftpDispatchEvent); // testing only var newExecutableOrder = new ExecutableOrchestrationOrder() { ActorId = GenerateActorId(), ActorServiceUri = (FtpDispatcherActorService != null) ? $"{ApplicationName}/{FtpDispatcherActorService}" : ServiceUri.ToString() }; await ChainNextActorsAsync <IDefaultFtpDispatchAction>(c => c.InvokeDispatchWriteRequest(ftpDispatchRequest), new ActorRequestContext(Id.ToString(), "FTP_WRITE_DISPATCH_ACTION_NAME", Guid.NewGuid().ToString(), CurrentFlowInstanceId), newExecutableOrder, CancellationToken.None); } else { throw new NotImplementedException($"{CurrentActor} failed to generate content to write to ftp. Interface {nameof(ICsvContent)} or {nameof(IXmlContent)} not implemented on the entity. "); } }
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 InvokeGenerateReadRequest(FtpOption ftpOption) { var ftpDispatchRequest = new DispatchRequest(ftpOption, typeof(FtpOption), ftpOption?.Domain, ReponseParserActor, null); //if using sb //await GenerateRequestAsync(ftpDispatchEvent); // testing only var newExecutableOrder = new ExecutableOrchestrationOrder() { ActorId = GenerateActorId(), ActorServiceUri = (FtpDispatcherActorService != null) ? $"{ApplicationName}/{FtpDispatcherActorService}" : ServiceUri.ToString() }; await ChainNextActorsAsync <IDefaultFtpDispatchAction>( c => c.InvokeDispatchReadRequest(ftpDispatchRequest), new ActorRequestContext(Id.ToString(), "FTP_READ_DISPATCH_ACTION_NAME", Guid.NewGuid().ToString(), CurrentFlowInstanceId), newExecutableOrder, CancellationToken.None); }
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); } } }
public static Task Invoke(string methodName, ActorRequestContext actorRequestContext, ExecutableOrchestrationOrder executableOrchestrationOrder, params object[] arguments) { actorRequestContext.TargetActor = new ActorIdentity(executableOrchestrationOrder.ActorId, executableOrchestrationOrder.ActorServiceUri); return(Invoke(methodName, actorRequestContext, arguments)); }
public static Task Invoke <TIActionInterface>(Expression <Func <TIActionInterface, object> > expression, ActorRequestContext actorRequestContext, ExecutableOrchestrationOrder executableOrchestrationOrder, CancellationToken cancellationToken) where TIActionInterface : IRemotableAction => ActionInvoker <TIActionInterface> .Invoke(expression, actorRequestContext, executableOrchestrationOrder, cancellationToken);
/// <summary> /// Main method to chain an order take in an executable order /// Allow actors to directly make call to next actor via an executable order object /// </summary> /// <typeparam name="T"></typeparam> /// <param name="nextActorRequestContext"></param> /// <param name="payload"></param> /// <param name="excutableOrder"></param> /// <param name="cancellationToken"></param> /// <returns></returns> protected virtual async Task ChainNextActorsAsync(ActorRequestContext nextActorRequestContext, object payload, Type typeOfPayload, ExecutableOrchestrationOrder excutableOrder, CancellationToken cancellationToken) { //try to complete the step await CompleteStepAsync(payload); try { await ActorClient.ChainNextActorAsync(nextActorRequestContext, payload, typeOfPayload, new ActorIdentity(excutableOrder.ActorId, excutableOrder.ActorServiceUri), cancellationToken); } catch (Exception ex) { Logger.LogError(ex, $"{CurrentActor} failed to chain next actor {excutableOrder?.ActorServiceUri} with actor id {excutableOrder?.ActorId}. Message: {ex.Message}"); } }
/// <summary> /// Main method to chain an order take in an executable order /// Allow actors to directly make call to next actor via an executable order object /// </summary> /// <typeparam name="T"></typeparam> /// <param name="nextActorRequestContext"></param> /// <param name="payload"></param> /// <param name="excutableOrder"></param> /// <param name="cancellationToken"></param> /// <returns></returns> protected virtual async Task ChainNextActorsAsync <T>(ActorRequestContext nextActorRequestContext, T payload, ExecutableOrchestrationOrder excutableOrder, CancellationToken cancellationToken) { await ChainNextActorsAsync(nextActorRequestContext, payload, typeof(T), excutableOrder, cancellationToken); }
public Task ChainNextActorsAsync(ActorRequestContext actorRequestContext, object payload, Type typeOfPayload, ExecutableOrchestrationOrder executableOrchestrationOrder, CancellationToken cancellationToken) => Actor.ChainNextActorsAsync(actorRequestContext, payload, typeOfPayload, executableOrchestrationOrder, cancellationToken);
public Task ChainNextActorsAsync <TIActionInterface>(Expression <Func <TIActionInterface, object> > expression, ActorRequestContext actorRequestContext, ExecutableOrchestrationOrder executableOrchestrationOrder, CancellationToken cancellationToken) where TIActionInterface : IRemotableAction => Actor.ChainNextActorsAsync(expression, actorRequestContext, executableOrchestrationOrder, cancellationToken);
protected async Task ChainNextActorAsync(ActorRequestContext nextActorRequestContext, string startedPayload, object nextPayload, Type typeOfPayload, ExecutableOrchestrationOrder order, CancellationToken cancellationToken) { var flowInstanceId = nextActorRequestContext.FlowInstanceId; // var startedFlowInstanceId = new FlowInstanceId(Activity.Current.Id, (this.GetType().Name)); var applicationName = Context.CodePackageActivationContext.ApplicationName; await TryCreateFlow(applicationName, flowInstanceId, startedPayload); var uri = new Uri(order.ActorServiceUri); //var startedFlowInstanceId = new FlowInstanceId(Activity.Current.Id, (this.GetType().Name)); var proxy = ActorProxy.Create <IBaseMessagingActor>(order.ActorId == null ? ActorId.CreateRandom() : new ActorId(order.ActorId), uri); var payload = BinaryMessageSerializer.SerializePayload(nextPayload); await proxy.ChainProcessMessageAsync(nextActorRequestContext, payload, cancellationToken); }