コード例 #1
0
        public static async Task HandleAttributeInitialization(this INetDaemonAppBase netDaemonApp, INetDaemon daemon)
        {
            _ = daemon ??
                throw new NetDaemonArgumentNullException(nameof(daemon));
            _ = netDaemonApp ??
                throw new NetDaemonArgumentNullException(nameof(netDaemonApp));

            var netDaemonAppType = netDaemonApp.GetType();

            foreach (var method in netDaemonAppType.GetMethods())
            {
                foreach (var attr in method.GetCustomAttributes(false))
                {
                    if (netDaemonApp is NetDaemonRxApp daemonRxApp)
                    {
                        switch (attr)
                        {
                        case HomeAssistantServiceCallAttribute:
                            await HandleServiceCallAttribute(daemon, daemonRxApp, method, false).ConfigureAwait(false);

                            break;
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static async Task HandleAttributeInitialization(this INetDaemonAppBase netDaemonApp, INetDaemon _daemon)
        {
            var netDaemonAppType = netDaemonApp.GetType();

            foreach (var method in netDaemonAppType.GetMethods())
            {
                foreach (var attr in method.GetCustomAttributes(false))
                {
                    if (netDaemonApp is NetDaemonApp daemonApp)
                    {
                        switch (attr)
                        {
                        case HomeAssistantServiceCallAttribute hasstServiceCallAttribute:
                            await HandleServiceCallAttribute(_daemon, daemonApp, method, true).ConfigureAwait(false);

                            break;

                        case HomeAssistantStateChangedAttribute hassStateChangedAttribute:
                            HandleStateChangedAttribute(_daemon, hassStateChangedAttribute, daemonApp, method);
                            break;
                        }
                    }
                    else if (netDaemonApp is NetDaemonRxApp daemonRxApp)
                    {
                        switch (attr)
                        {
                        case HomeAssistantServiceCallAttribute hasstServiceCallAttribute:
                            await HandleServiceCallAttribute(_daemon, daemonRxApp, method, false).ConfigureAwait(false);

                            break;
                        }
                    }
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Constructor from an already instantiated app (used for unit testing)
 /// </summary>
 /// <param name="appInstance"></param>
 /// <param name="serviceProvider"></param>
 public AppBaseApplicationContext(INetDaemonAppBase appInstance, IServiceProvider serviceProvider)
     : base(appInstance.GetType(), appInstance.Id !, serviceProvider)