示例#1
0
        internal void Parse(TorrentsList TorrentsToParse, bool IsFresh)
        {
            List <string> ListOfHashes = new List <string>();

            foreach (string[] TorrentArray in TorrentsToParse)
            {
                if (TorrentArray.Length == 0)
                {
                    throw new FormatException("The array of torrent data was not in the expected format, it contains 0 elements.");
                }
                ListOfHashes.Add(TorrentArray[0]);
                Torrent NewTorrent = GetByHashCode(TorrentArray[0]);
                if (NewTorrent == null)
                {
                    NewTorrent = new Torrent(TorrentArray, this);
                    _torrentCollectionInternal.Add(NewTorrent);
                    if (!IsFresh)
                    {
                        ParentClient.CallEvent(UTorrentWebClient.EventType.Added, NewTorrent);
                    }
                    CallCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, NewTorrent));
                }
                else
                {
                    NewTorrent.UpdateValuesFromStringArray(TorrentArray);
                }
            }
            IEnumerable <Torrent> RemovedTorrents = RemoveWhereHashCodeIsNotInList(ListOfHashes);

            foreach (Torrent RemovedTorrent in RemovedTorrents)
            {
                CallCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, RemovedTorrent));
            }
        }
示例#2
0
        private void RegisterTorrent(Torrent torrent, string downloadFolderPath)
        {
            var wrapper = new TorrentWrapper(downloadFolderPath, torrent);

            TorrentsList.Add(wrapper);
            SelectedWrapper = wrapper;
            _engine.Register(SelectedWrapper.Manager);
        }
示例#3
0
        private void GetTorrentsAndLabelsUpdate(TorrentsList TorrentsToProcess)
        {
            TorrentsAndLabels CurrentTorrents = ServiceClient.GetAllTorrentsAndLabels(_token);

            _torrents.Parse(CurrentTorrents.Torrents, false);
            _labels.Parse(CurrentTorrents.Labels);
            SetCache(CurrentTorrents.CacheID);
        }
示例#4
0
 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();
 }
示例#5
0
 internal void Parse(TorrentsList TorrentsToParse, RemovedTorrentsList RemovedTorrentsToParse, ChangedTorrentsList ChangedTorrentsToParse)
 {
     if (RemovedTorrentsToParse == null || ChangedTorrentsToParse == null)
     {
         if (TorrentsToParse != null)
         {
             Parse(TorrentsToParse, false);
         }
     }
     else
     {
         List <Torrent> RemovedTorrents = new List <Torrent>();
         foreach (string[] TorrentArray in RemovedTorrentsToParse)
         {
             if (TorrentArray.Length == 0)
             {
                 throw new FormatException("The array of torrent data was not in the expected format, it contains 0 elements.");
             }
             RemovedTorrents.Clear();
             RemovedTorrents.AddRange(RemoveByHashCode(TorrentArray[0]));
             foreach (Torrent RemovedTorrent in RemovedTorrents)
             {
                 CallCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, RemovedTorrent));
             }
         }
         foreach (string[] TorrentArray in ChangedTorrentsToParse)
         {
             if (TorrentArray.Length == 0)
             {
                 throw new FormatException("The array of torrent data was not in the expected format, it contains 0 elements.");
             }
             Torrent NewTorrent = GetByHashCode(TorrentArray[0]);
             if (NewTorrent == null)
             {
                 NewTorrent = new Torrent(TorrentArray, this);
                 _torrentCollectionInternal.Add(NewTorrent);
                 ParentClient.CallEvent(UTorrentWebClient.EventType.Added, NewTorrent);
                 CallCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, NewTorrent));
             }
             else
             {
                 NewTorrent.UpdateValuesFromStringArray(TorrentArray);
             }
         }
     }
 }
示例#6
0
        private void GetTorrentsAndLabelsUpdate(TorrentsList TorrentsToProcess)
        {
            if (_token == null)
            {
                return;
            }

            try
            {
                TorrentsAndLabels CurrentTorrents = ServiceClient.GetAllTorrentsAndLabels(_token);

                _torrents.Parse(CurrentTorrents.Torrents, false);
                _labels.Parse(CurrentTorrents.Labels);
                SetCache(CurrentTorrents.CacheID);
            }
            catch (System.ServiceModel.ProtocolException e)
            {
                // Token possibly expired, get new token.
                Trace.TraceError(e.Message + e.StackTrace);
                GetToken();
            }
        }
示例#7
0
        private void DeleteTorrent(object arg)
        {
            if (SelectedWrapper != null)
            {
                var deleteAction = new Action(async() =>
                {
                    _engine.Unregister(SelectedWrapper.Manager);
                    var torrentHashString = SelectedWrapper.Manager.InfoHash.ToString();
                    var searchResult      = await _unitOfWork.GetRepository <TorrentInfo>().GetSingleOrDefaultAsync(torrentInfo =>
                                                                                                                    torrentInfo.InfoHash == torrentHashString);
                    _unitOfWork.GetRepository <TorrentInfo>().Delete(searchResult);
                    await _unitOfWork.SaveChangesAsync();
                    SelectedWrapper.Manager.Dispose();
                    SelectedWrapper.DeleteFastResume();
                    File.Delete(SelectedWrapper.Torrent.TorrentPath);
                    TorrentsList.Remove(SelectedWrapper);
                });


                SelectedWrapper.PretendToDelete = true;

                if (SelectedWrapper.State == TorrentState.Stopped)
                {
                    _dispatcher.Invoke(deleteAction);
                }
                else
                {
                    StopCommand.Execute(null);
                    SelectedWrapper.Manager.TorrentStateChanged +=
                        delegate(object sender, TorrentStateChangedEventArgs args)
                    {
                        if (args.NewState == TorrentState.Stopped && SelectedWrapper.PretendToDelete)
                        {
                            _dispatcher.Invoke(deleteAction);
                        }
                    };
                }
            }
        }
示例#8
0
        //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);
                }
            }
        }
        private void GetTorrentsAndLabelsUpdate(TorrentsList TorrentsToProcess)
        {
            TorrentsAndLabels CurrentTorrents = ServiceClient.GetAllTorrentsAndLabels(_token);

            _torrents.Parse(CurrentTorrents.Torrents, false);
            _labels.Parse(CurrentTorrents.Labels);
            SetCache(CurrentTorrents.CacheID);
        }
        private void GetTorrentsAndLabelsUpdate(TorrentsList TorrentsToProcess)
        {
            if(_token == null)
                return;

            try
            {
                TorrentsAndLabels CurrentTorrents = ServiceClient.GetAllTorrentsAndLabels(_token);

                _torrents.Parse(CurrentTorrents.Torrents, false);
                _labels.Parse(CurrentTorrents.Labels);
                SetCache(CurrentTorrents.CacheID);
            }
            catch(System.ServiceModel.ProtocolException e)
            {
                // Token possibly expired, get new token.
                Trace.TraceError(e.Message + e.StackTrace);
                GetToken();
            }
        }