private void AddInvocation(JsRuntimeInvocation invocation)
 {
     if (!_invocations.ContainsKey(invocation.Identifier))
     {
         _invocations.Add(invocation.Identifier, new List <JsRuntimeInvocation>());
     }
     _invocations[invocation.Identifier].Add(invocation);
 }
            public ValueTask <TValue> InvokeAsync <TValue>(string identifier, CancellationToken cancellationToken, object[] args)
            {
                var invocation = new JsRuntimeInvocation(identifier, cancellationToken, args);

                _handlers.AddInvocation(invocation);

                return(TryHandlePlannedInvocation <TValue>(identifier, invocation)
                       ?? new ValueTask <TValue>(default(TValue) !));
            }
Пример #3
0
 /// <summary>
 /// Creates a new instance of the <see cref="UnplannedJsInvocationException"/>
 /// with the provided <see cref="Invocation"/> attached.
 /// </summary>
 /// <param name="invocation">The unplanned invocation.</param>
 public UnplannedJsInvocationException(JsRuntimeInvocation invocation)
     : base($"The invocation of '{invocation.Identifier} with arguments '[{PrintArguments(invocation.Arguments)}]")
 {
     Invocation = invocation;
 }
            private ValueTask <TValue>?TryHandlePlannedInvocation <TValue>(string identifier, JsRuntimeInvocation invocation)
            {
                ValueTask <TValue>?result = default;

                if (_handlers._plannedInvocations.TryGetValue(identifier, out var plannedInvocations))
                {
                    var planned = plannedInvocations.OfType <JsRuntimePlannedInvocation <TValue> >()
                                  .SingleOrDefault(x => x.Matches(invocation));

                    // TODO: Should we check the CancellationToken at this point and automatically call
                    // TrySetCanceled(CancellationToken) on the TaskCompletionSource? (https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskcompletionsource-1.trysetcanceled?view=netcore-3.0#System_Threading_Tasks_TaskCompletionSource_1_TrySetCanceled_System_Threading_CancellationToken_)
                    if (planned is { })
Пример #5
0
 internal bool Matches(JsRuntimeInvocation invocation)
 {
     return(Identifier.Equals(invocation.Identifier, StringComparison.Ordinal) &&
            InvocationMatcher(invocation.Arguments));
 }
Пример #6
0
 internal void AddInvocation(JsRuntimeInvocation invocation)
 {
     _invocations.Add(invocation);
 }