Beispiel #1
0
        /// <summary>
        /// Hook up a <see cref="HeadDisconnected"/> delegate that gets called when a client.
        /// on the given <see cref="ServerCallContext"/> disconnects.
        /// </summary>
        /// <param name="serverCallContext">The <see cref="ServerCallContext"/>.</param>
        /// <param name="disconnected">The <see cref="HeadDisconnected"/> callback.</param>
        public static void OnDisconnected(this ServerCallContext serverCallContext, HeadDisconnected disconnected)
        {
            var clientIdEntry = serverCallContext.RequestHeaders.SingleOrDefault(_ => _.Key.Equals("clientid", StringComparison.InvariantCultureIgnoreCase));

            if (clientIdEntry != null)
            {
                var clientId = (HeadId)Guid.Parse(clientIdEntry.Value);
                var client   = ConnectedHeads.GetById(clientId);
                if (client != null)
                {
                    client.Disconnected += disconnected;
                }
            }
        }
        /// <summary>
        /// Hook up a <see cref="HeadDisconnected"/> delegate that gets called when a client.
        /// on the given <see cref="ServerCallContext"/> disconnects.
        /// </summary>
        /// <param name="serverCallContext">The <see cref="ServerCallContext"/>.</param>
        /// <param name="disconnected">The <see cref="HeadDisconnected"/> callback.</param>
        public static void OnDisconnected(this ServerCallContext serverCallContext, HeadDisconnected disconnected)
        {
            var headIdEntry = serverCallContext.RequestHeaders.SingleOrDefault(_ => _.Key.Equals($"headid{Metadata.BinaryHeaderSuffix}", StringComparison.InvariantCultureIgnoreCase));

            if (headIdEntry != null)
            {
                var headId = Guid.Parse(headIdEntry.Value);
                var head   = ConnectedHeads.GetById(headId);
                if (head != null)
                {
                    head.Disconnected += disconnected;
                }
            }
        }