protected sealed override async Task Act(IFlowContext context, ObjectConnection <NuxeoConfig> connection, T?arguments) { var config = connection.Object; using var client = new Client(config.Url, new(config.Username, config.Password)); await Act(context, arguments, client); }
public FlowException(string message, IFlowContext context, Exception innerException) : base(message, innerException) { Flow = context.Flow; Context = context.AsObject().GetAwaiter().GetResult(); FlowStackTrace = context.GetStackTrace(); }
protected override IObservable <object> GetEvents(IFlowContext context, UnitConnection _, PeriodicArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } if (arguments.Action is null) { throw new ArgumentNullException(nameof(arguments)); } return(Observable.Create <object>(async(observer, cancellationToken) => { while (!cancellationToken.IsCancellationRequested) { await context.Actor.Act(new[] { arguments.Action }, context); var path = string.IsNullOrEmpty(arguments.Path) ? arguments.Action.Type : arguments.Path; var hasData = await context.ExistsData(path); if (hasData) { var data = await context.GetData(path); observer.OnNext(data ?? Unit.Default); } await Task.Delay(arguments.Interval, cancellationToken); } observer.OnCompleted(); })); }
protected override async Task Act(IFlowContext context, UnitConnection _, ForEachArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } if (!arguments.Async) { foreach (var item in arguments.Collection) { await context.SetData(item); using (context.ScopeStack($"{{{item}}}")) await context.Actor.Act(arguments.Actions, context); } } else { var tasks = arguments.Collection.Select(async item => { var subContext = context.Clone(); await subContext.SetData(item); using (subContext.ScopeStack($"{{{item}}}")) await subContext.Actor.Act(arguments.Actions, subContext); }); await Task.WhenAll(tasks); } }
protected override async Task Act(IFlowContext context, UnitConnection _, Unit arguments) { var contextObj = await context.AsObject(); var str = GetString(() => contextObj, new HashSet <object>()); global::System.Diagnostics.Debug.WriteLine(str); logger.LogDebug(str); }
protected sealed override async Task Act(IFlowContext context, ObjectConnection <ImapConfiguration> connection, TArguments?arguments) { var config = connection.Object; using var client = new ImapClient(); await client.ConnectAsync(config.Host, config.Port); await client.AuthenticateAsync(config.Username, config.Password); await Act(context, client, arguments ?? new TArguments()); }
protected override IObservable <object> GetEvents(IFlowContext context, UnitConnection _, DistinctArguments?arguments) { if (arguments is null || arguments.Base is null) { throw new ArgumentNullException(nameof(arguments)); } var observable = context.Actor.GetTrigger(arguments.Base, context); return(observable.DistinctUntilChanged()); }
protected override async Task Act(IFlowContext context, UnitConnection _, WhileArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } while (await arguments.Condition.Resolve(context)) { await context.Actor.Act(arguments.Actions, context); } }
public FlowTest() { var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var configBuilder = new ConfigurationBuilder() .AddJsonFile($"appsettings.json", true, true) .AddJsonFile($"appsettings.{environmentName}.json", true, true); this.Configuration = configBuilder.Build(); this.Context = new FlowContext(); }
protected override async Task Act(IFlowContext context, ObjectConnection <Client> connection, ParameterizedNewTorrent?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } var newTorrent = await arguments.Resolve(context); var torrentInfo = await connection.Object.TorrentAddAsync(newTorrent).ConfigureAwait(false); await context.SetData(torrentInfo); }
protected override async Task Act(IFlowContext context, ObjectConnection <Client> connection, RemoveArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } var ids = await arguments.Ids.Resolve(context); var deleteData = await arguments.DeleteData.Resolve(context); connection.Object.TorrentRemoveAsync(ids, deleteData); }
public async Task Act(IReadOnlyList <BlockConfig> actions, IFlowContext context) { var currentType = context.CurrentType; using (new ActionDisposable(() => context.CurrentType = currentType)) { for (int i = 0; i < actions.Count; i++) { var action = actions[i]; using (context.ScopeStack($"[{i + 1}] {action.Type}")) await Act(action, context); } } }
protected override async Task Act(IFlowContext context, BatchArguments arguments, Batch batch, int?fileIndex) { if (fileIndex.HasValue) { var info = await batch.Info(fileIndex.Value); await context.SetData(info); } else { var info = await batch.Info(); await context.SetData(info); } }
protected override async Task Act(IFlowContext context, UnitConnection _, WriteArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } var level = await arguments.Level.Resolve(context); var message = await arguments.Message.Resolve(context); var tag = await arguments.Tag.Resolve(context); logger.Log(level, $"[{tag}] {message}"); }
protected override async Task Act(IFlowContext context, TelegramConnection connection, SendArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } var chatId = await arguments.ChatId.Resolve(context); var text = await arguments.Text.Resolve(context); var message = await connection.TelegramBotClient.SendTextMessageAsync(chatId, text); await context.SetData(message); }
protected override async Task Act(IFlowContext context, ObjectConnection <Client> connection, GetArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } var fields = await arguments.Fields.Resolve(context); var ids = await arguments.Ids.Resolve(context); var torrents = await connection.Object.TorrentGetAsync(fields, ids); await context.SetData(torrents); }
protected override async Task Act(IFlowContext context, UnitConnection _, ClearArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } var path = await arguments.Path.Resolve(context); if (path is null) { throw new ArgumentNullException(nameof(arguments.Path)); } await context.ClearData(path); }
protected override async Task Act(IFlowContext context, RequestArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } var url = await arguments.Url.Resolve(context); var method = await arguments.Method.Resolve(context); var body = await arguments.Body.Resolve(context); if (url is null) { throw new ArgumentNullException(nameof(arguments.Url)); } if (method is null) { throw new ArgumentNullException(nameof(arguments.Method)); } var request = WebRequest.CreateHttp(url); request.Method = method; if (!string.IsNullOrEmpty(body)) { using var requestStream = await request.GetRequestStreamAsync(); using var requestWriter = new StreamWriter(requestStream, defaultEncoding); await requestWriter.WriteAsync(body); await requestWriter.FlushAsync(); } var response = await request.GetResponseAsync(); var httpResponse = await HttpResponse.FromResponse((HttpWebResponse)response); await context.SetData(httpResponse); response.Close(); }
protected override IObservable <object> GetEvents(IFlowContext context, UnitConnection _, WhenAnyArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } return(Observable.Defer(() => { var observables = arguments.Triggers .Select(trigger => context.Actor.GetTrigger(trigger, context) .Select(o => new { Source = trigger.Type, Data = o, })); return observables.Merge(); })); }
protected override async Task Act(IFlowContext context, UnitConnection _, IfArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } var condition = await arguments.If.Resolve(context); if (condition) { using (context.ScopeStack("IF")) await context.Actor.Act(arguments.Then, context); } else { using (context.ScopeStack("ELSE")) await context.Actor.Act(arguments.Else, context); } }
private static async Task <JToken> Resolve(JToken token, IFlowContext context) { if (token is JObject jobj) { return(new JObject(await Task.WhenAll(jobj.Properties().Select(ResolveProperty)))); } return(token); async Task <JProperty> ResolveProperty(JProperty property) { if (property.Value.TryToObject <IParameter>(out var parameter)) { var resolvedValue = await parameter.Resolve(context); return(new JProperty(property.Name, resolvedValue)); } return(property); } }
protected override async Task Act(IFlowContext context, UnitConnection _, SwitchArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } var value = await arguments.Value.Resolve(context); foreach (var(@case, actions) in arguments.Cases) { if (Equals(value, @case)) { using (context.ScopeStack($"CASE {{{@case}}}")) await context.Actor.Act(actions, context); return; } } using (context.ScopeStack("DEFAULT")) await context.Actor.Act(arguments.Default, context); }
private async Task Act(BlockConfig action, IFlowContext context) { try { var(connector, connection, name) = GetConnection(action, context); var flowAction = connector.GetAction(name); if (flowAction is null) { throw new FlowException($"Unable to acquire action \"{action.Type}\".", context); } var flowActionConfiguration = await Resolve(action.Arguments, flowAction.ArgumentsType, context); context.CurrentType = action.Type; await flowAction.Act(context, connection, flowActionConfiguration); } catch (Exception e) when(e is not FlowException) { throw new FlowException($"Error while executing \"{action.Type}\".", context, e); } }
protected override async Task Act(IFlowContext context, UnitConnection _, SetArguments?arguments) { if (arguments is null) { throw new ArgumentNullException(nameof(arguments)); } var path = await arguments.Path.Resolve(context); var value = await arguments.Value.Resolve(context); if (path is null) { throw new ArgumentNullException(nameof(arguments.Path)); } if (value is null) { throw new ArgumentNullException(nameof(arguments.Value)); } await context.SetData(path, value); }
public IObservable <object> GetTrigger(BlockConfig trigger, IFlowContext context) { try { var(connector, connection, name) = GetConnection(trigger, context); var flowTrigger = connector.GetTrigger(name); if (flowTrigger is null) { throw new FlowException($"Unable to acquire trigger \"{trigger.Type}\".", context); } return(Observable.DeferAsync(async _ => { var flowTriggerConfiguration = await Resolve(trigger.Arguments, flowTrigger.ArgumentsType, context); return flowTrigger.GetEvents(context, connection, flowTriggerConfiguration); })); } catch (Exception e) when(e is not FlowException) { throw new FlowException($"Error while getting trigger \"{trigger.Type}\".", context, e); } }
public ValueContext(IFlowContext flowContext, TValue value) { this.Value = value; this.FlowContext = flowContext; }
public ValueContext(IFlowContext flowContext, TValue value, string destination) : this(flowContext, value) { this.Destination = destination; }
protected override async Task Act(IFlowContext context, Unit _, Client client) { var batch = await client.Batch(); await context.SetData(batch); }
protected override async Task Act(IFlowContext context, BatchArguments arguments, Batch batch, int?fileIndex) { var info = await batch.Drop(); await context.SetData(info); }
public async Task <object?> Resolve(IFlowContext context) { var value = await Base.Resolve(context); return(value.Map(targetType)); }