Exemplo n.º 1
0
 public void UnregisterChannel(GrpcChannelx channel)
 {
     lock (_channels)
     {
         _channels.Remove(channel);
     }
 }
Exemplo n.º 2
0
 private void RegisterChannel(GrpcChannelx channel)
 {
     lock (_channels)
     {
         _channels.Add(channel);
     }
 }
Exemplo n.º 3
0
        private async Task InitializeClientAsync()
        {
            // Initialize the Hub
            // NOTE: If you want to use SSL/TLS connection, see InitialSettings.OnRuntimeInitialize method.
            this.channel = GrpcChannelx.ForAddress("http://localhost:5000");

            while (!shutdownCancellation.IsCancellationRequested)
            {
                try
                {
                    Debug.Log($"Connecting to the server...");
                    this.streamingClient = await StreamingHubClient.ConnectAsync <IChatHub, IChatHubReceiver>(this.channel, this, cancellationToken : shutdownCancellation.Token);

                    this.RegisterDisconnectEvent(streamingClient);
                    Debug.Log($"Connection is established.");
                    break;
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }

                Debug.Log($"Failed to connect to the server. Retry after 5 seconds...");
                await Task.Delay(5 * 1000);
            }

            this.client = MagicOnionClient.Create <IChatService>(this.channel);
        }
Exemplo n.º 4
0
        private void DrawChart(GrpcChannelx channel, DataRatePoints history)
        {
            // Draw Chart
            var prevHandlesColor = Handles.color;

            {
                var rect = EditorGUI.IndentedRect(GUILayoutUtility.GetRect(GUILayoutUtility.GetLastRect().width, 100));
                Handles.DrawSolidRectangleWithOutline(rect, Color.black, Color.gray);

                var drawableRect = new Rect(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4);
                var maxCount     = 60;
                var maxY         = DataUnit.GetScaleMaxValue(Math.Max(history.ReceivedValues.DefaultIfEmpty().Max(), history.SentValues.DefaultIfEmpty().Max()));
                var dx           = drawableRect.width / (float)(maxCount - 1);
                var dy           = drawableRect.height / (float)maxY;

                // Grid (9 lines)
                Handles.color = new Color(0.05f, 0.25f, 0.05f);
                for (var i = 1; i < 10; i++)
                {
                    var yTop = drawableRect.y + (drawableRect.height / 10) * i;
                    Handles.DrawLine(new Vector3(drawableRect.x, yTop), new Vector3(drawableRect.xMax, yTop));
                }

                // Label
                Handles.Label(new Vector3(drawableRect.x, drawableRect.y), DataUnit.Humanize(maxY) + " bytes/sec");

                // Values
                Span <int> buffer = stackalloc int[60];
                var        points = new List <Vector3>();
                {
                    var values = history.ReceivedValues.ToSpan(buffer);
                    for (var i = 0; i < Math.Min(maxCount, values.Length); i++)
                    {
                        var p = new Vector3(drawableRect.x + (drawableRect.width - (dx * i)), drawableRect.yMax - (dy * values[values.Length - i - 1]));
                        points.Add(p);
                    }

                    Handles.color = new Color(0.33f, 0.55f, 0.33f);
                    Handles.DrawAAPolyLine(4f, points.ToArray());
                }
                points.Clear();
                {
                    var values = history.SentValues.ToSpan(buffer);
                    for (var i = 0; i < Math.Min(maxCount, values.Length); i++)
                    {
                        var p = new Vector3(drawableRect.x + (drawableRect.width - (dx * i)), drawableRect.yMax - (dy * values[values.Length - i - 1]));
                        points.Add(p);
                    }

                    Handles.color = new Color(0.2f, 0.33f, 0.2f);
                    Handles.DrawAAPolyLine(2f, points.ToArray());
                }
            }
            Handles.color = prevHandlesColor;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a channel to the target and register the channel under the management of the provider.
        /// </summary>
        protected override GrpcChannelx CreateChannelCore(int id, CreateGrpcChannelContext context)
        {
            var channelOptions = context.ChannelOptions.Get <GrpcCCoreChannelOptions>() ?? _defaultChannelOptions;
            var channel        = new Channel(context.Target.Host, context.Target.Port, context.Target.IsInsecure ? ChannelCredentials.Insecure : channelOptions.ChannelCredentials, channelOptions.ChannelOptions);
            var channelHolder  = new GrpcChannelx(
                id,
                context.Provider.UnregisterChannel /* Root provider may be wrapped outside this provider class. */,
                channel,
                new Uri((context.Target.IsInsecure ? "http" : "https") + $"://{context.Target.Host}:{context.Target.Port}"),
                new GrpcChannelOptionsBag(channelOptions)
                );

            return(channelHolder);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a channel to the target and register the channel under the management of the provider.
        /// </summary>
        public GrpcChannelx CreateChannel(CreateGrpcChannelContext context)
        {
            var channelOptions = CreateGrpcChannelOptions(context.ChannelOptions);
            var id             = Interlocked.Increment(ref _seq);
            var channel        = new Channel(context.Target.Host, context.Target.Port, context.Target.ChannelCredentials, channelOptions);
            var channelHolder  = new GrpcChannelx(
                id,
                context.Provider.UnregisterChannel /* Root provider may be wrapped outside this provider class. */,
                channel,
                new Uri((context.Target.ChannelCredentials == ChannelCredentials.Insecure ? "http" : "https") + $"://{context.Target.Host}:{context.Target.Port}"),
                channelOptions
                );

            lock (_channels)
            {
                _channels.Add(channelHolder);
            }

            return(channelHolder);
        }
Exemplo n.º 7
0
 public void UnregisterChannel(GrpcChannelx channel)
 {
     _baseProvider.UnregisterChannel(channel);
     Debug.Log($"Channel Unregistered: {channel.TargetUri.Host}:{channel.TargetUri.Port} [{channel.Id}]");
 }