示例#1
0
        public LocalBinder(Connection connection, TObj obj)
            : base(connection)
        {
            lInvoker = new LocalInvoker <TObj>();
            Object   = obj;

            Connection.OnReceive += async d =>
            {
                var msg = Request.FromJson(d);
                if (msg.IsEmpty)
                {
                    return;
                }

                var result = await lInvoker.InvokeAsync(Object, msg);

                await Connection.SendAsync(result.ToJson());
            };

            Connection.OnClose += (s, d) =>
            {
                try { (Object as IDisposable)?.Dispose(); }
                catch (Exception ex) { Connection.InvokeOnError(ex); }

                return(Task.FromResult(true));
            };
        }
        public LocalBinder(Connection connection, TObj obj)
            : base(connection)
        {
            lInvoker = new LocalInvoker <TObj>();
            Object   = obj;

            Connection.AddLocalBinder(this);

            Connection.OnClose += (s, d) =>
            {
                try { (Object as IDisposable)?.Dispose(); }
                catch (Exception ex) { Connection.InvokeOnError(ex); }

                return(Task.FromResult(true));
            };
        }