public static TaskDatabase GetDatabaseByUser(IUnityContainer container, MountUser user)
        {
            if (List.Any(v => v.Name == user.Username))
            {
                return(List.FirstOrDefault(v => v.Name == user.Username));
            }
            var db = new TaskDatabase(container, user);

            List.Add(db);
            return(db);
        }
 public TaskManager(IUnityContainer container, MountUser user) : base(container)
 {
     _user       = user;
     _dataFolder = Path.Combine(Common.UserDataSavePath, user.Username);
     if (!Directory.Exists(_dataFolder))
     {
         Directory.CreateDirectory(_dataFolder);
     }
     _database = TaskDatabase.GetDatabaseByUser(Container, user);
     _runing   = true;
     new Thread(async() =>
     {
         while (_runing)
         {
             Thread.Sleep(1000);
             if (_downloadingTasks.Count(v => v.DownloadState == DownloadStateEnum.Downloading) < Container.Resolve <ILocalConfigInfo>().ParallelTaskNumber)
             {
                 //如果正在下载的文件数量与已经请求的文件数量相同
                 if (_database.GetDownloadingTask().Length == _downloadingTasks.Count)
                 {
                     var result = await _database.Next();
                     if (result == null)
                     {
                         continue;
                     }
                     if (result.ErrorCode != 0)
                     {
                         if (result.ErrorCode == 209)
                         {
                             //没有新的任务了
                         }
                         //出现错误时的处理
                         continue;
                     }
                     //Created -> Waiting
                     EventAggregator.GetEvent <DownloadStateChangedEvent>().Publish(new DownloadStateChangedEventArgs(_database.GetFileIdByPath(result.Info.DownloadPath), DownloadStateEnum.Created, DownloadStateEnum.Waiting));
                     AddDownloadingTask(result.Info);
                     continue;
                 }
                 var data =
                     _database.GetDownloadingTask()
                     .FirstOrDefault(v => _downloadingTasks.All(v2 => v.DownloadPath != v2.DownloadPath));
                 if (data != null)
                 {
                     AddDownloadingTask(data.Info);
                 }
             }
         }
     })
     {
         IsBackground = true
     }.Start();
 }
 public static TaskManager GetTaskManagerByLocalDiskUser(IUnityContainer container, MountUser user)
 {
     if (!Manager.ContainsKey(user.Username))
     {
         //Manager.Add(user.Name, new TaskManager(user));
         Manager.Add(user.Username, new TaskManager(container, user));
     }
     return(Manager[user.Username]);
 }
 private TaskDatabase(IUnityContainer container, MountUser user) : base(container)
 {
     _user = user;
     Reload();
 }