public async Task <ILocalDiskUser> SignInAsync(string userName, string password)
        {
            var dataServer = Server.DefaultServer;
            var json       = JObject.Parse(await dataServer.SendPacketAsync(new LoginPacket()
            {
                Name     = userName,
                Password = password,
            }));

            switch ((int)json["error"])
            {
            default:
                var result = new LocalDiskUser()
                {
                    Token        = (string)json["token"],
                    BoundAccount = (bool)json["cookies"],
                    DataServer   = dataServer,
                    Name         = userName,
                    Password     = password
                };
                _netDiskUserList.Add(result);
                return(result);

            case 1:
                throw new LoginException("用户不存在", ClientLoginStateEnum.NonUser);

            case 2:
                throw new LoginException("密码错误", ClientLoginStateEnum.PasswordError);

            case 3:
                throw new LoginException("异地登录", ClientLoginStateEnum.OtherError);

            case 4:
                throw new LoginException("服务端出现未知错误", ClientLoginStateEnum.OtherError);

            case 5:
                throw new LoginException("账号被封禁", ClientLoginStateEnum.Baned);
            }
        }
        public async Task <ILocalDiskUser> SignInAsync(string userName, string password)
        {
            var dataServer = Server.DefaultServer;
            var json       = JObject.Parse(await dataServer.SendPacketAsync(new LoginPacket()
            {
                Name     = userName,
                Password = password,
            }));

            switch ((int)json["error"])
            {
            default:
                var result = new LocalDiskUser(Container)
                {
                    Token        = (string)json["token"],
                    BoundAccount = (bool)json["cookies"],
                    DataServer   = dataServer,
                    Name         = userName,
                    Password     = password
                };
                if (!Directory.Exists(Path.Combine(_userDataSavePath, userName)))
                {
                    Directory.CreateDirectory(Path.Combine(_userDataSavePath, userName));
                }
                try
                {
                    TaskManager.GetTaskManagerByLocalDiskUser(Container, result);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }
                _netDiskUserList.Add(result);
                var userPath = Path.Combine(_userDataSavePath, userName);
                if (Directory.Exists(userPath))
                {
                    try
                    {
                        var info = JObject.Parse(File.ReadAllText(Path.Combine(userPath, "Account.json")));
                        result.DownloadDirectory    = (string)info["DownloadDirectory"];
                        result.ParallelTaskNumber   = (int)info["ParallelTaskNumber"];
                        result.DownloadThreadNumber = ((int)info["DwonloadTheradNumber"]) > 32
                                ? 32
                                : (int)info["DwonloadTheradNumber"];
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }
                }
                return(result);

            case 1:
                throw new LoginException("用户不存在", ClientLoginStateEnum.NonUser);

            case 2:
                throw new LoginException("密码错误", ClientLoginStateEnum.PasswordError);

            case 3:
                throw new LoginException("异地登录", ClientLoginStateEnum.OtherError);

            case 4:
                throw new LoginException("服务端出现未知错误", ClientLoginStateEnum.OtherError);

            case 5:
                throw new LoginException("账号被封禁", ClientLoginStateEnum.Baned);
            }
        }
예제 #3
0
 public NetDiskUser(LocalDiskUser account)
 {
     _account = account;
     RootFile = new NetDiskFile(this);
 }