コード例 #1
0
        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");
                }
            });
        }
コード例 #2
0
 /// <inheritdoc/>
 public void ListenServiceCall(string domain, string service, Func <dynamic?, Task> action) =>
 _daemon?.ListenServiceCall(domain, service, action);