private static void HandleServiceCallAttribute(INetDaemon _daemon, INetDaemonApp netDaemonApp, MethodInfo method) { var(signatureOk, err) = CheckIfServiceCallSignatureIsOk(method); if (!signatureOk) { _daemon.Logger.LogWarning(err); return; } dynamic serviceData = new FluentExpandoObject(); serviceData.method = method.Name; serviceData.@class = netDaemonApp.GetType().Name; _daemon.CallService("netdaemon", "register_service", serviceData); _daemon.ListenServiceCall("netdaemon", $"{serviceData.@class}_{serviceData.method}", async(data) => { try { var expObject = data as ExpandoObject; await method.InvokeAsync(netDaemonApp, expObject !).ConfigureAwait(false); } catch (Exception e) { _daemon.Logger.LogError(e, "Failed to invoke the ServiceCall function"); } }); }
/// <inheritdoc/> public Task ExecuteAsync() { List <Task> tasks = new List <Task>(); foreach (var entityId in _entityIds) { dynamic data = new FluentExpandoObject(); data.entity_id = entityId; data.option = _option; tasks.Add(_daemon.CallService("input_select", "select_option", data)); } return(Task.WhenAll(tasks)); }
/// <inheritdoc/> protected async Task CallServiceOnAllEntities(string service, dynamic?serviceData = null) { var taskList = new List <Task>(); foreach (var entityId in EntityIds) { var domain = GetDomainFromEntity(entityId); serviceData ??= new FluentExpandoObject(); serviceData.entity_id = entityId; var task = Daemon.CallService(domain, service, serviceData); taskList.Add(task); } if (taskList.Count > 0) { await Task.WhenAny(Task.WhenAll(taskList.ToArray()), Task.Delay(5000)).ConfigureAwait(false); } }