private async void CreateTorrentInfo() { _unitOfWork.GetRepository <TorrentInfo>().Create(new TorrentInfo() { InfoHash = SelectedWrapper.Manager.InfoHash.ToString(), SavePath = SelectedWrapper.Manager.SavePath, LastState = TorrentsList.Last().Manager.State.ToString() }); await _unitOfWork.SaveChangesAsync(); }
//private void StoreTorrents() //{ // if (_torrentsHashDictianory.Count > 0) // { // var formatter = new BinaryFormatter(); // using (var fileStream = new FileStream(hashedTorrentsListPath, FileMode.Create)) // { // formatter.Serialize(fileStream, _torrentsHashDictianory); // } // } //} private async void RestoreTorrents() { var hashedTorrentsFileNames = Directory.GetFiles(hashedTorrentsFolderPath, "*.torrent"); foreach (var fileName in hashedTorrentsFileNames) { var torrent = Torrent.Load(fileName); var torrentHashString = torrent.InfoHash.ToString(); var torrenInfo = await _unitOfWork.GetRepository <TorrentInfo>() .GetSingleOrDefaultAsync(torrentInfoPredicate => torrentInfoPredicate.InfoHash == torrentHashString); RegisterTorrent(torrent, torrenInfo.SavePath); if (torrenInfo.LastState == "Downloading") { StartDownload(); } else if (torrenInfo.LastState == "Paused") { TorrentsList.Last().Manager.HashCheck(false); } } }