Пример #1
0
        /// <inheritdoc />
        public void Invoke(WidgetContext context)
        {
            var method = WidgetMethodSelector.FindSyncMethod(context, context.WidgetDescriptor.Type.GetTypeInfo());

            if (method == null)
            {
                throw new InvalidOperationException("Cannot find an appropriate method.");
            }

            var result = InvokeSyncCore(method, context);

            result.Execute(context);
        }
Пример #2
0
        /// <inheritdoc />
        public async Task InvokeAsync(WidgetContext context)
        {
            IWidgetResult result;
            var           asyncMethod = WidgetMethodSelector.FindAsyncMethod(context, context.WidgetDescriptor.Type.GetTypeInfo());

            if (asyncMethod == null)
            {
                var syncMethod = WidgetMethodSelector.FindSyncMethod(context, context.WidgetDescriptor.Type.GetTypeInfo());

                if (syncMethod == null)
                {
                    throw new InvalidOperationException("Cannot find an appropriate method.");
                }

                result = InvokeSyncCore(syncMethod, context);
            }
            else
            {
                result = await InvokeAsyncCore(asyncMethod, context);
            }

            await result.ExecuteAsync(context);
        }