Beispiel #1
0
        private bool MessageHandler(Message message)
        {
            switch (message.Command)
            {
            case Commands.Login:
                _sslChannel.SendMessage(new Message(Authorization(message) ? Commands.Ok : Commands.Error, _name));
                break;

            case Commands.GetUserState:
                _sslChannel.SendMessage(new Message(Commands.Ok, GetUserState()));
                break;

            case Commands.Ok:
                break;

            case Commands.Error:
                Console.WriteLine("Клиент отключен. Логин: " + _login);
                return(false);

            case Commands.ChangePass:
                if (ChangePassword(message))
                {
                    SendResult(true);
                }
                else
                {
                    SendResult(false, "Не удалось сменить пароль. Пароль слишком слабый или короткий");
                }
                break;

            case Commands.SetShareStatus:
                bool setStatusResult = false;
                try
                {
                    setStatusResult = SetShareStatus(message);
                }
                catch (Exception ex)
                {
                    _sslChannel.SendMessage(new Message(setStatusResult ? Commands.Ok : Commands.Error, ex.Message));
                    break;
                }
                _sslChannel.SendMessage(new Message(setStatusResult ? Commands.Ok : Commands.Error, String.Empty));
                break;

            case Commands.PutCommonFile:
                ReciveCommonFile(message);
                break;

            case Commands.GetCommonFile:
                SendCommonFile(message);
                break;

            case Commands.PutPrivateFile:
                RecivePrivateFile(message);
                break;

            case Commands.GetPrivateFile:
                SendPrivateFile(message);
                break;

            case Commands.GetCommonFileList:
                SendCommonFileList();
                break;

            case Commands.GetPrivateFileList:
                SendPrivateFileList();
                break;

            case Commands.DeleteCommonFile:
                DeleteCommonFile(message);
                break;

            case Commands.DeletePrivateFile:
                DeletePrivateFile(message);
                break;

            case Commands.ChangeFileKey:
                ChangeFileKey(message);
                break;

            case Commands.CheckFile:
                CheckFile(message);
                break;

            case Commands.RecalcHash:
                RecalcHash(message);
                break;

            case Commands.SendFile:
                break;

            case Commands.CreateShareKey:
                SetNewRsaKeys(message);
                break;

            case Commands.GetNewFileList:
                SendNewFileList();
                break;

            case Commands.GetReportList:
                SendReportList();
                break;

            case Commands.ReciveNewFile:
                ReciveNewFile(message);
                break;

            case Commands.ShareFile:
                ShareFile(message);
                break;

            case Commands.DeleteNewFile:
                DeleteNewFile(message);
                break;

            case Commands.GetUserList:
                SendUserList();
                break;

            case Commands.Logout:
                Stop();
                Console.WriteLine("Клиент отключен. Логин: " + _login);
                return(false);

            case Commands.CreateUser:
                CreateUser(message);
                break;

            case Commands.MustChangeAllPass:
                MustChangeAllPass();
                break;

            case Commands.SetPassParams:
                SetPassPolicy(message);
                break;

            case Commands.GetPassParams:
                SendPassPolicy();
                break;

            default:
                Console.WriteLine("Получена неизвестная команда");
                return(false);
            }
            return(true);
        }
Beispiel #2
0
 public static void Authorization(string login, string pass)
 {
     lock (_sslChannel)
     {
         string command = login + "$" + pass;
         _sslChannel.SendMessage(new Message(Commands.Login, command));
         var recivedCommand = _sslChannel.ReciveMessage();
         Name         = recivedCommand.StringMessage;
         IsAuthorized = recivedCommand.Command == Commands.Ok;
     }
 }