/// <summary>
 /// Initializes a new instance of the <see cref="ApolloClientMessageReceivedLogEntry"/> class.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="message">The message.</param>
 public ApolloClientMessageReceivedLogEntry(ISubscriptionClientProxy client, ApolloMessage message)
     : base(ApolloLogEventIds.ClientMessageReceived)
 {
     this.ClientId    = client.Id;
     this.MessageType = message.Type.ToString();
     this.MessageId   = message.Id;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApolloClientSubscriptionCreatedLogEntry" /> class.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="subscription">The subscription that was created.</param>
 public ApolloClientSubscriptionCreatedLogEntry(ISubscriptionClientProxy client, ISubscription subscription)
     : base(ApolloLogEventIds.ClientSubscriptionStarted)
 {
     this.ClientId       = client.Id;
     this.SubscriptionId = subscription.Id;
     this.Route          = subscription.Route.Path;
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionClientDroppedLogEntry"/> class.
 /// </summary>
 /// <param name="client">The client.</param>
 public SubscriptionClientDroppedLogEntry(ISubscriptionClientProxy client)
     : base(SubscriptionLogEventIds.SubscriptionClientDropped)
 {
     _clientTypeShortName = client.GetType().FriendlyName();
     this.ClientTypeName  = client.GetType().FriendlyName(true);
     this.ClientId        = client.Id;
 }
 /// <summary>
 /// Recorded when a subscription client is no longer connected or otherwise dropped
 /// by ASP.NET. The server will process no more messages from the client.
 /// </summary>
 /// <param name="logger">The logger doing the logging.</param>
 /// <param name="client">The client that was dropped and is being cleaned up.</param>
 public static void SubscriptionClientDropped(
     this IGraphEventLogger logger,
     ISubscriptionClientProxy client)
 {
     logger.Log(
         LogLevel.Debug,
         () => new SubscriptionClientDroppedLogEntry(client));
 }
 /// <summary>
 /// Recorded when a new client is registered against a subscription server and
 /// the graphql server begins monitoring it for messages.
 /// </summary>
 /// <typeparam name="TSchema">The type of the schema the client was registered for.</typeparam>
 /// <param name="logger">The logger doing the logging.</param>
 /// <param name="server">The server which created the client.</param>
 /// <param name="client">The client that was created.</param>
 public static void SubscriptionClientRegistered <TSchema>(
     this IGraphEventLogger logger,
     ISubscriptionServer <TSchema> server,
     ISubscriptionClientProxy client)
     where TSchema : class, ISchema
 {
     logger.Log(
         LogLevel.Debug,
         () => new SubscriptionClientRegisteredLogEntry <TSchema>(server, client));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SubcriptionExecutionContext" /> class.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="request">The request to be processed through the query pipeline.</param>
 /// <param name="subscriptionId">The unique id to assign to the created subscription, when one is made.</param>
 /// <param name="metrics">The metrics package to profile this request, if any.</param>
 /// <param name="logger">The logger instance to record events related to this context.</param>
 /// <param name="items">A key/value pair collection for random access data.</param>
 public SubcriptionExecutionContext(
     ISubscriptionClientProxy client,
     IGraphOperationRequest request,
     string subscriptionId,
     IGraphQueryExecutionMetrics metrics = null,
     IGraphEventLogger logger            = null,
     MetaDataCollection items            = null)
     : base(request, client?.ServiceProvider, client?.User, metrics, logger, items)
 {
     this.Client         = Validation.ThrowIfNullOrReturn(client, nameof(client));
     this.SubscriptionId = Validation.ThrowIfNullWhiteSpaceOrReturn(subscriptionId, nameof(subscriptionId));
 }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionClientRegisteredLogEntry{TSchema}" /> class.
 /// </summary>
 /// <param name="server">The server which created teh client.</param>
 /// <param name="client">The client that was created.</param>
 public SubscriptionClientRegisteredLogEntry(
     ISubscriptionServer <TSchema> server,
     ISubscriptionClientProxy client)
     : base(SubscriptionLogEventIds.SubscriptionClientRegistered)
 {
     _clientTypeShortName = client.GetType().FriendlyName();
     _schemaTypeShortName = typeof(TSchema).FriendlyName();
     this.SchemaTypeName  = typeof(TSchema).FriendlyName(true);
     this.ClientTypeName  = client.GetType().FriendlyName(true);
     this.ServerTypeName  = server.GetType().FriendlyName(true);
     this.ClientId        = client.Id;
     this.ServerId        = server.Id;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriptionContextBuilder" /> class.
        /// </summary>
        /// <param name="client">The client.</param>
        public SubscriptionContextBuilder(ISubscriptionClientProxy client)
        {
            _client      = client;
            _mockRequest = new Mock <IGraphOperationRequest>();
            _sourceData  = new List <KeyValuePair <GraphFieldPath, object> >();

            _mockRequest.Setup(x => x.ToDataPackage()).Returns(
                new AspNet.GraphQueryData()
            {
                Query         = _mockRequest.Object.QueryText,
                Variables     = new InputVariableCollection(_mockRequest.Object.VariableData),
                OperationName = _mockRequest.Object.OperationName,
            });
        }
        private async Task ExecuteSubscriptionEvent(
            ISubscriptionClientProxy client,
            GraphFieldPath route,
            object data,
            CancellationToken cancelToken = default)
        {
            try
            {
                // execute the request through the runtime
                await _eventSendSemaphore.WaitAsync().ConfigureAwait(false);

                await client.ReceiveEvent(route, data, cancelToken).ConfigureAwait(false);
            }
            finally
            {
                _eventSendSemaphore.Release();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApolloClientConnectionKeepAliveMonitor"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="interval">The interval.</param>
 public ApolloClientConnectionKeepAliveMonitor(ISubscriptionClientProxy connection, TimeSpan interval)
 {
     _connection = Validation.ThrowIfNullOrReturn(connection, nameof(connection));
     _interval   = interval;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientSubscription{TSchema}" /> class.
        /// </summary>
        /// <param name="clientProxy">The client proxy that will own this subscription.</param>
        /// <param name="originalQuerydata">The original querydata that generated this subscription.</param>
        /// <param name="queryPlan">The query plan.</param>
        /// <param name="selectedOperation">The selected operation from the query plan
        /// from which to generate the subscription.</param>
        /// <param name="subscriptionid">A unique id to assign to this subscription. A guid id
        /// will be generated if this value is not supplied.</param>
        public ClientSubscription(
            ISubscriptionClientProxy clientProxy,
            GraphQueryData originalQuerydata,
            IGraphQueryPlan queryPlan,
            IGraphFieldExecutableOperation selectedOperation,
            string subscriptionid = null)
        {
            this.Client         = Validation.ThrowIfNullOrReturn(clientProxy, nameof(clientProxy));
            this.QueryData      = Validation.ThrowIfNullOrReturn(originalQuerydata, nameof(originalQuerydata));
            this.QueryOperation = Validation.ThrowIfNullOrReturn(selectedOperation, nameof(selectedOperation));
            this.QueryPlan      = Validation.ThrowIfNullOrReturn(queryPlan, nameof(queryPlan));
            this.Messages       = this.QueryPlan?.Messages ?? new GraphMessageCollection();

            this.Id = string.IsNullOrWhiteSpace(subscriptionid)
                ? Guid.NewGuid().ToString("N")
                : subscriptionid.Trim();

            this.IsValid = false;

            // parsing the query plan will garuntee that if the document contains
            // a subscription that it contains only one operation and
            // that a top level field will be a subscription-ready field.
            //
            // However, ensure that the operation that will be executed
            // does in fact represent a subscription being harnesssed
            if (this.QueryOperation.OperationType != GraphCollection.Subscription)
            {
                this.Messages.Critical(
                    $"The chosen operation is not a subscription operation.",
                    Constants.ErrorCodes.BAD_REQUEST);
                return;
            }

            var currentContext = this.QueryOperation.FieldContexts[0];

            // find the first non-virtual field referenced, it should be a controller
            // its garunteed to exist via the document generation rule engine
            // but it could be deep, walk down the subscirption tree to find it
            while (currentContext?.Field != null)
            {
                // when pointing at a subscription field we're done
                if (!currentContext.Field.IsVirtual)
                {
                    this.Field = currentContext.Field as ISubscriptionGraphField;
                    break;
                }

                currentContext = currentContext?.ChildContexts.Count == 1 ? currentContext.ChildContexts?[0] : null;
            }

            // just in case it wasn't found...
            // this is theoretically not possible but just in case
            // the user swaps out some DI components incorrectly or by mistake...
            if (this.Field == null)
            {
                this.Messages.Add(
                    GraphMessageSeverity.Critical,
                    "An eventable field could not found in the subscription operation. Ensure you include a field declared " +
                    "as a subscription field.",
                    Constants.ErrorCodes.BAD_REQUEST);
            }

            this.IsValid = this.Messages.IsSucessful && this.QueryOperation != null && this.Field != null;
        }