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 _, 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, 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, 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, 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 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); }
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); }