internal override void InvokeEvent(ServerType type, IConnection conn, IMessage msg)
        {
            switch (type)
            {
            case ServerType.Started:
                OnStarted?.Invoke(conn, msg);
                break;

            case ServerType.Accepted:
                OnAccepted?.Invoke(conn, msg);
                break;

            case ServerType.Sended:
                OnSended?.Invoke(conn, msg);
                break;

            case ServerType.Received:
                OnRecieved?.Invoke(conn, msg);
                break;

            case ServerType.Disconnected:
                OnDisconnected?.Invoke(conn, msg);
                break;

            case ServerType.Stopped:
                OnStopped?.Invoke(conn, msg);
                break;
            }
        }
        internal override void InvokeEvent(ClientType type, IConnection conn, IMessage msg)
        {
            switch (type)
            {
            case ClientType.Connected:
                OnConnected?.Invoke(conn, msg);
                break;

            case ClientType.Sended:
                OnSended?.Invoke(conn, msg);
                break;

            case ClientType.Received:
                OnReceived?.Invoke(conn, msg);
                break;

            case ClientType.Disconnected:
                OnDisconnected?.Invoke(conn, msg);
                break;
            }
        }
Beispiel #3
0
        public void SendFile(string fileName, Action <bool> complete)
        {
            if (File.Exists(fileName))
            {
                var fName = fileName.Substring(fileName.LastIndexOf("\\") + 1);

                var data = SerializeHelper.ByteSerialize(new FileMessage()
                {
                    FileName = fName, Length = new FileInfo(fileName).Length
                });

                _sender.SendInfo(data, (d) =>
                {
                    if (d)
                    {
                        _beginSend = true;
                        _sender.SendFile(fileName);
                        _beginSend = false;
                        OnSended?.Invoke();
                    }
                    complete?.Invoke(d);
                });
            }
        }