Exemplo n.º 1
0
        public ServiceClient(IClientLogic logic, IPAddress hostIP, int port, int interfaceId, long ticket)
        {
            this.logic = logic;

            client = new DynamicClient(hostIP, port);
            tree   = new ProtocolTree();
            root   = new DummyHandler <DummyProtocol>();
            auth   = new LeafProtocolHandler <AuthenticationProtocol>();

            tree.Register(root);
            tree.Register(auth);
            tree.Entry(root);
            tree.ConnectToLeaf(root, auth);
            tree.Connect(root, logic.ProtocolTree);

            app = new ApplicationConnectionManager(client, tree, 3000, 6000);

            auth.NewData += data =>
            {
                switch (data.statusCode)
                {
                case AuthenticationProtocol.StatusCode.Request:
                    Logger.Log("receiving auth request", "ServiceClient");
                    auth.Send(new AuthenticationProtocol
                    {
                        interfaceId = interfaceId,
                        ticket      = ticket,
                        resumeToken = ResumeToken,
                        statusCode  = AuthenticationProtocol.StatusCode.Ack
                    });
                    break;

                case AuthenticationProtocol.StatusCode.Accept:
                    Logger.Log("auth accepted by the host", "ServiceClient");
                    ResumeToken = data.resumeToken;
                    ConnectionAccepted?.Invoke();
                    break;

                case AuthenticationProtocol.StatusCode.Reject:
                    Logger.Log($"auth rejected by the host, {data.reason}", "ServiceClient", Logger.LogType.WARNING);
                    rejected = true;
                    client.CloseConnection();
                    app.Dispose();
                    ConnectionRejected?.Invoke();
                    break;

                default:
                    Logger.Log("invalid auth msg from host", "ServiceClient", Logger.LogType.WARNING);
                    break;
                }
            };

            app.ConnectionLost += () =>
            {
                if (!rejected)
                {
                    ConnectionLost?.Invoke();
                }
            };
        }
        public void ProcessEvent(EventWrittenEventArgs e)
        {
            switch (_eventPairTimerConnections.TryGetDuration(e, out var duration1))
            {
            case DurationResult.Start:
                ConnectionStart?.Invoke(Events.ConnectionStartEvent.Instance);
                break;

            case DurationResult.FinalWithDuration:
                ConnectionStop?.InvokeManyTimes(_samplingRate.SampleEvery, Events.ConnectionStopEvent.GetFrom(duration1));
                break;

            default:
                break;
            }

            switch (_eventPairTimerRequests.TryGetDuration(e, out var duration2))
            {
            case DurationResult.Start:
                ConnectionStart?.Invoke(Events.ConnectionStartEvent.Instance);
                break;

            case DurationResult.FinalWithDuration:
                ConnectionStop?.InvokeManyTimes(_samplingRate.SampleEvery, Events.ConnectionStopEvent.GetFrom(duration2));
                break;

            default:
                break;
            }

            if (e.EventId == EventIdConnectionStart)
            {
                ConnectionStart?.Invoke(Events.ConnectionStartEvent.ParseFrom(e));
                return;
            }

            if (e.EventId == EventIdConnectionStop)
            {
                ConnectionStop?.Invoke(Events.ConnectionStopEvent.ParseFrom(e));
                return;
            }

            if (e.EventId == EventIdRequestStart)
            {
                RequestStart?.Invoke(Events.RequestStartEvent.ParseFrom(e));
                return;
            }

            if (e.EventId == EventIdRequestStop)
            {
                RequestStop?.Invoke(Events.RequestStopEvent.ParseFrom(e));
                return;
            }

            if (e.EventId == EventIdConnectionRejected)
            {
                ConnectionRejected?.Invoke(Events.ConnectionRejectedEvent.ParseFrom(e));
                return;
            }
        }
Exemplo n.º 3
0
        public void HandleConnectResponce(object sender, ShipMessage message)
        {
            LastConnectResponce = message as ConnectResponce;

            ConnectedShip = null;

            if (LastConnectResponce.Responce == ConnectResponce.ResponceTypes.Rejected)
            {
                ConnectionRejected?.Invoke(this, LastConnectResponce);
            }
            else
            {
                ConnectionAccepted?.Invoke(this, LastConnectResponce);
            }
        }
Exemplo n.º 4
0
 public void OnConnectionRejected(ConnectionRejected data)
 {
 }