コード例 #1
0
        public async Task OnTorrentLoaded(object sender, TorrentStateChangedEventArgs e)
        {
            _parser = new EbmlParser(_dataAccessor, ElementFactories);
            await GetDoc();

            PlayerStatus = MatroskaPlayerStatus.LoadingMovieDetails;
        }
コード例 #2
0
        public static void OnFinishLoading(TorrentManager manager, TorrentStateChangedEventArgs args)
        {
            var newState = Utils.GetManagerTorrentState(manager);

            Console.WriteLine(manager.Torrent.Name + " State chaged: " + newState);
            if (manager.State == TorrentState.Seeding && !manager.allowSeeding)
            {
                Console.WriteLine("Stopping 2");
                manager.Stop();
            }
            else if (manager.State == TorrentState.Downloading &&
                     !manager.allowSeeding)
            {
                long size       = 0;
                long downloaded = 0;

                if (manager.Torrent != null)
                {
                    foreach (var f in manager.Torrent.Files)
                    {
                        if (f.Priority != Priority.DoNotDownload)
                        {
                            size       += f.Length;
                            downloaded += f.BytesDownloaded;
                        }
                    }
                }

                if (downloaded >= size && manager.HasMetadata && manager.State != TorrentState.Hashing)
                {
                    Console.WriteLine("Stopping 3");
                    manager.Stop();
                }
            }
            else if (newState == TorrentState.Finished || newState == TorrentState.Seeding)
            {
                if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
                {
                    var content = new UNMutableNotificationContent();
                    content.Title = "Download finished";
                    content.Body  = manager.Torrent.Name + " finished downloading";
                    content.Sound = UNNotificationSound.Default;

                    var date       = DateTime.Now;
                    var trigger    = UNTimeIntervalNotificationTrigger.CreateTrigger(1, false);
                    var identifier = manager.Torrent.Name;
                    var request    = UNNotificationRequest.FromIdentifier(identifier, content, trigger);

                    UNUserNotificationCenter.Current.AddNotificationRequest(request, null);
                }

                Background.CheckToStopBackground();
            }
            foreach (var action in Manager.Singletone.managerStateChanged)
            {
                action?.Invoke();
            }
        }
コード例 #3
0
 public void ontorrentStateChanged(object sender, TorrentStateChangedEventArgs args)
 {
     if (args.NewState == TorrentState.Seeding && args.OldState == TorrentState.Downloading)
     {
         //torrent completed. send notification.
         Console.WriteLine(args.TorrentManager.Torrent.Name + "downloaded!");
         return;
     }
 }
コード例 #4
0
        private async void ManagerTorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            var ma = sender as TorrentManager;

            D($"Torrent manager state changed <{e.NewState}> , old: <{e.OldState}>");
            switch (e.NewState)
            {
            case TorrentState.Error:
                await ReportErrorAsync(ma.Error.Exception, false);

                break;

            case TorrentState.Seeding:
                cancellationTokenSource?.Cancel();
                cancellationTokenSource = null;
                if (downloadTask != null)
                {
                    await downloadTask;
                }
                downloadTask = null;
                await manager.StopAsync();

                break;

            case TorrentState.Stopped:
                if (((BaseMeasurableProgress)Progress).IsCompleted)
                {
                    try
                    {
                        D("Downloading completed, creating destination folder...");
                        var folder = await folderProvider.GetFolderFromTokenAsync(DownloadTask.DestinationFolderKey);

                        var targetFolder = await folder.CreateFolderAsync(
                            DownloadTask.DestinationFileName,
                            CreationCollisionOption.GenerateUniqueName);

                        D($"Destination folder created <{targetFolder.Path}>");
                        D("Coping files from cache folder to destination folder...");
                        await cacheFolder.CopyContentToAsync(targetFolder);

                        D("Deleting cache folder...");
                        await cacheFolder.DeleteAsync();

                        cacheFolder = null;
                        ReportCompleted(targetFolder);
                    }
                    catch (Exception ex)
                    {
                        await ReportErrorAsync(ex, true);
                    }
                }
                break;
            }
        }
コード例 #5
0
 private void checkIncomplete(object sender, TorrentStateChangedEventArgs e)
 {
     if ((e.OldState == TorrentState.Hashing) && (e.NewState == TorrentState.Downloading))
     {
         TorrentManager manager = (TorrentManager)sender;
         if (!manager.Complete)
         {
             this.parent.button4_dummy(this, new EventArgs());
         }
     }
 }
コード例 #6
0
        private void OnStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            if (e.OldState == TorrentState.Metadata && e.NewState != TorrentState.Error)
            {
                MetadataLoaded.Invoke(sender, e);
            }
            switch (e.NewState)
            {
            case TorrentState.Error:
                TorrentError.Invoke(sender, e);
                break;

            case TorrentState.Stopped:
                TorrentStopped.Invoke(sender, e);
                break;

            case TorrentState.Paused:
                TorrentPaused.Invoke(sender, e);
                break;

            case TorrentState.Starting:
                TorrentStarting.Invoke(sender, e);
                break;

            case TorrentState.Downloading:
                TorrentDownloading.Invoke(sender, e);
                break;

            case TorrentState.Seeding:
                TorrentSeeding.Invoke(sender, e);
                break;

            case TorrentState.Hashing:
                TorrentHashing.Invoke(sender, e);
                break;

            case TorrentState.HashingPaused:
                TorrentHashingPaused.Invoke(sender, e);
                break;

            case TorrentState.Stopping:
                TorrentStopping.Invoke(sender, e);
                break;

            case TorrentState.Metadata:
                TorrentMetadata.Invoke(sender, e);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #7
0
        static void torrentManager_TorrentStateChanged(object sender,
                                                       TorrentStateChangedEventArgs e)
        {
            Debug.WriteLine(string.Format("Torrent state changed {0} => {1}",
                                          e.OldState, e.NewState));

            if (e.NewState == TorrentState.Seeding)
            {
                if (e.OldState == TorrentState.Downloading)
                {
                    Debug.WriteLine("Entire torrent download completed");
                }
            }
        }
コード例 #8
0
        private void OnTorrentStateChanged(object sender, TorrentStateChangedEventArgs args)
        {
            TorrentManager manager = (TorrentManager)sender;

            Gtk.Application.Invoke(delegate {
                if (args.OldState == TorrentState.Downloading)
                {
                    logger.Debug("Removing " + manager.Torrent.Name + " from download label");
                    mainWindow.DownloadingLabel.RemoveTorrent(manager);
                }
                else if (args.OldState == TorrentState.Seeding)
                {
                    logger.Debug("Removing " + manager.Torrent.Name + " from upload label");
                    mainWindow.SeedingLabel.RemoveTorrent(manager);
                }

                if (args.NewState == TorrentState.Downloading)
                {
                    logger.Debug("Adding " + manager.Torrent.Name + " to download label");
                    mainWindow.DownloadingLabel.AddTorrent(manager);
                }
                else if (args.NewState == TorrentState.Seeding)
                {
                    logger.Debug("Adding " + manager.Torrent.Name + " to upload label");
                    mainWindow.SeedingLabel.AddTorrent(manager);
                }

                if (!prefSettings.EnableNotifications)
                {
                    return;
                }
                if (args.NewState != TorrentState.Seeding)
                {
                    return;
                }
                if (args.OldState != TorrentState.Downloading)
                {
                    return;
                }

                Notifications.Notification notify = new Notifications.Notification("Download Complete", manager.Torrent + " has finished downloading.");
                notify.AttachToWidget(mainWindow.TrayIcon);
                notify.Timeout = 5000;
                notify.Show();
            });
        }
コード例 #9
0
        private void ManagerOnTorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            State = (TorrentState)e.NewState;

            switch (State)
            {
            case TorrentState.Stopped:
                this.OnTorrentEvent(TorrentStopped);
                break;

            case TorrentState.Paused:
                this.OnTorrentEvent(TorrentPaused);
                break;

            case TorrentState.Downloading:
                this.OnTorrentEvent(TorrentResumed);
                break;

            case TorrentState.Seeding:
                var isComplete = e.TorrentManager.Complete && !e.TorrentManager.IsInitialSeeding;
                if (isComplete)
                {
                    this.OnTorrentEvent(TorrentCompleted);
                }
                break;

            case TorrentState.Hashing:
                break;

            case TorrentState.Stopping:
                this.OnTorrentEvent(TorrentPaused);
                break;

            case TorrentState.Error:
                this.OnTorrentEvent(TorrentError);
                break;

            case TorrentState.Metadata:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #10
0
        public static void HandleTorrentStateChanged(object sender,
                                                     TorrentStateChangedEventArgs e)
        {
            var torrentManager = e.TorrentManager;
            var clientEngine   = torrentManager.Engine;

            logger.DebugFormat("Torrent {0}: State changed from {1} to {2}", e.TorrentManager.Torrent.Name,
                               e.OldState.ToString(), e.NewState.ToString());

            switch (e.NewState)
            {
            case TorrentState.Downloading:
                logger.DebugFormat("Open connections: {0}", torrentManager.OpenConnections);
                if (e.OldState == TorrentState.Hashing)
                {
                    logger.Debug("Hashing Mode completed.");

                    logger.DebugFormat("{0} chunks out of {1} already available.",
                                       torrentManager.DedupManager.TotalChunksAvailable,
                                       torrentManager.DedupManager.TotalChunks);

                    logger.DebugFormat("{0} pieces ({2} percent) already available out of {1} in total.",
                                       torrentManager.Bitfield.TrueCount,
                                       torrentManager.Torrent.Pieces.Count, torrentManager.Bitfield.PercentComplete);
                }
                break;

            case TorrentState.Seeding:
                if (e.OldState == TorrentState.Downloading)
                {
                    logger.DebugFormat("Download completed.", torrentManager.Torrent.Name);

                    logger.Debug(GetStatsLog(torrentManager));
                    // Flush so that whoever is waiting for the download can
                    // read it immediately.
                    clientEngine.DiskManager.Flush(e.TorrentManager);
                }
                break;

            default:
                break;
            }
        }
コード例 #11
0
        private void waitForFinish(object sender, TorrentStateChangedEventArgs e)
        {
            foreach (TorrentManager manager in this.managers)
            {
                if (!manager.Complete)
                {
                    return;
                }
            }
            this.engineState = EngineState.Paused;
            foreach (TorrentManager manager in this.managers)
            {
                if (manager.State == TorrentState.Stopping)
                {
                    return;
                }
                else if (manager.State == TorrentState.Stopped)
                {
                    manager.TorrentStateChanged -= waitForFinish;
                }
                else
                {
                    manager.Stop();
                    return;
                }
            }
            TorrentStatusUpdateEventArgs args = new TorrentStatusUpdateEventArgs(0, 0, 0, 0, 100, "Update Completed", "Approximately 0 seconds remaining.");

            foreach (TorrentManager manager in this.managers)
            {
                this.engine.Unregister(manager);
            }
            this.managers.Clear();
            this.torrents.Clear();
            this.activeWebSeeds = 0;
            this.engineState    = EngineState.Paused;
            StopDht();
            if (parent.debugMode)
            {
                this.refreshDebugWindow();
            }
            UpdateFinished(args);
        }
コード例 #12
0
        private async Task OnMetadataLoaded(object sender, TorrentStateChangedEventArgs e)
        {
            Debug.Assert(_manager.HasMetadata, "Metadata was not found");
            Console.WriteLine("Metadata found, stopping to load fast resume");
            await _manager.StopAsync();

            await ChangePicker();
            await LoadFastResumeData();

            _dataAccessor.SetTorrentFile(_manager.Torrent.Files.First());
            await _matroskaPlayer.OnTorrentLoaded(sender, e);

            if (_onMetadataLoadedListener != null)
            {
                MetadataLoaded           -= _onMetadataLoadedListener;
                _onMetadataLoadedListener = null;
            }

            await _manager.StartAsync();
        }
コード例 #13
0
        public void OnTorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            if (e.TorrentManager.Progress == 100.0 && e.NewState == TorrentState.Seeding)
            {
                bool lastFile = !torrents.Exists(delegate(TorrentManager m) { return(m.Progress != 100); });
                if (lastFile)
                {
                    if (installer != null)
                    {
                        installer.Status = "Installing..";
                    }
                    if (updater != null)
                    {
                        updater.Status = DayZeroLauncherUpdater.STATUS_UPTODATE;
                    }
                }

                foreach (string f in Directory.GetFiles(Path.Combine(downloadsPath, e.TorrentManager.Torrent.Name), "*.*", SearchOption.AllDirectories))
                {
                    if (e.TorrentManager.Torrent.Files.None(t => t.FullPath.ToLower() == f.ToLower()))
                    {
                        if (!f.Contains("ra_chat_off.pbo"))
                        {
                            File.Delete(f);
                        }
                    }
                }
                if (lastFile)
                {
                    if (installer != null)
                    {
                        installer.Status = "Ready to Play";
                    }
                    StopTorrents();

                    CalculatedGameSettings.Current.Update();
                }
            }
        }
コード例 #14
0
        void manager_TorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            if (e.NewState == TorrentState.Stopped)
            {
                TorrentManager manager = (TorrentManager)sender;
                this.engine.Unregister(manager);
                manager.TorrentStateChanged -= manager_TorrentStateChanged;
                if (this.managers.Contains(manager))
                {
                    this.managers.Remove(manager);
                }
                if (this.torrents.Contains(manager.Torrent))
                {
                    this.torrents.Remove(manager.Torrent);
                }
            }

            if ((this.StoppedSeeding != null) && (this.managers.Count == 0))
            {
                this.StoppedSeeding(this, new EventArgs());
            }
        }
コード例 #15
0
ファイル: MediaDownloader.cs プロジェクト: xtfrost/Traktor
        private void TorrentManager_TorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            //if (e.OldState == TorrentState.Metadata && e.TorrentManager.Torrent != null)
            //{
            //    e.TorrentManager.MoveFilesAsync(Path.Combine(this.Settings.DownloadPath, e.TorrentManager.Torrent.Name), true);
            //}

            if (e.NewState == TorrentState.Seeding)
            {
                e.TorrentManager.StopAsync().Wait();
            }

            if (e.NewState == TorrentState.Stopped) // e.NewState == TorrentState.Downloading ||
            {
                ManageActiveDownloads();
            }

            //Console.WriteLine($"TSC: OldState={e.OldState}, NewState={e.NewState}, Torrent={e.TorrentManager}");
            if (e.NewState.Is(TorrentState.Downloading, TorrentState.Error, TorrentState.Stopped, TorrentState.Paused, TorrentState.Metadata))
            {
                var keyValuePair = this.Torrents.FirstOrDefault(x => x.Value == e.TorrentManager);
                this.OnChange?.Invoke(new DownloadInfo(keyValuePair.Key, keyValuePair.Value, keyValuePair.Value.Priority, e.NewState));
            }
        }
コード例 #16
0
 public void RaiseStateChanged(TorrentStateChangedEventArgs e)
 {
     StateChanged?.Invoke(this, e);
 }
コード例 #17
0
        private void manager_TorrentStateChanged(object sender, TorrentStateChangedEventArgs args)
        {
            try
            {
                Core.LoggingService.LogDebug("State: {0}", args.NewState);
                Core.LoggingService.LogDebug("Progress: {0:0.00}", this.manager.Progress);

                if (args.NewState == TorrentState.Downloading || (args.NewState == TorrentState.Seeding && args.OldState != TorrentState.Downloading))
                {
                    // XXX: Only have the requesting end connect for now,
                    // so we dont end up with redundant conncetions in each direction.
                    // We need a solution for this that can handle reverse connections.
                    if (!(File is LocalFile))
                    {
                        Core.LoggingService.LogDebug("Torrent is ready! connecting to peers!");

                        lock (this.peers)
                        {
                            if (!this.peers.OfType <BitTorrentFileTransferPeer>().Any(ConnectToPeer))
                            {
                                StatusDetail = "Unable to connect to any peers";
                                Cancel();
                            }
                        }
                    }
                    else
                    {
                        Core.LoggingService.LogDebug("Torrent is ready! Waiting for connections from peers!");
                    }
                }

                if (args.NewState == TorrentState.Seeding && this.manager.Progress.Equals(100))
                {
                    if (Direction == FileTransferDirection.Download)
                    {
                        if (Core.Settings.IncompleteDownloadDir != Core.Settings.CompletedDownloadDir)
                        {
                            // Ensure torrent is stopped before attempting to move file, to avoid access violation.
                            this.manager.Stop();

                            //TODO: Move this out, yeah?!
                            IO.File.Move(IO.Path.Combine(Core.Settings.IncompleteDownloadDir, File.Name),
                                         IO.Path.Combine(Core.Settings.CompletedDownloadDir, File.Name));
                        }
                    }

                    if (this.peers.OfType <BitTorrentFileTransferPeer>().Any(p => p == null || !p.Peer.IsSeeder))
                    {
                        return;
                    }

                    if (this.manager == null || !this.manager.Progress.Equals(100))
                    {
                        // If we got here, then everyone is a seeder.
                        // No need to keep the transfer active.
                        Cancel();
                    }
                    else
                    {
                        // Success! Ensure torrent is stopped.
                        this.manager.Stop();
                    }
                }
            }
            catch (Exception ex)
            {
                Core.LoggingService.LogError("Error in manager_TorrentStateChanged.", ex);
                Cancel();
                RaiseError(ex);
            }
        }
コード例 #18
0
 private void OnError(object sender, TorrentStateChangedEventArgs e)
 {
     Console.WriteLine(_manager.Error.Exception);
     Console.WriteLine(_manager.Error.Exception.Source);
     Console.WriteLine(_manager.Error.Reason);
 }
コード例 #19
0
ファイル: Mytorrent.cs プロジェクト: codenumb/ytsmovies
 public static void onStateChanged(object o, TorrentStateChangedEventArgs e)
 {
     //publish event
     Console.WriteLine("event trigger:" + e.TorrentManager.Torrent.Name);
 }
コード例 #20
0
ファイル: Mytorrent.cs プロジェクト: codenumb/ytsmovies
 public virtual void myTorrentStateChanged(object o, TorrentStateChangedEventArgs e)
 {
     TorrentStateChanged(o, e);
 }
コード例 #21
0
        private void manager_TorrentStateChanged(object sender, TorrentStateChangedEventArgs args)
        {
            try {
                LoggingService.LogDebug("State: {0}", args.NewState);
                LoggingService.LogDebug("Progress: {0:0.00}", manager.Progress);

                if (args.NewState == TorrentState.Downloading || (args.NewState == TorrentState.Seeding && args.OldState != TorrentState.Downloading))
                {
                    // XXX: Only have the requesting end connect for now,
                    // so we dont end up with redundant conncetions in each direction.
                    // We need a solution for this that can handle reverse connections.
                    if (!(File is LocalFile))
                    {
                        LoggingService.LogDebug("Torrent is ready! connecting to peers!");
                        lock (peers) {
                            var didConnect = false;
                            foreach (var p in peers)
                            {
                                var peer = (BitTorrentFileTransferPeer)p;
                                if (ConnectToPeer(peer))
                                {
                                    didConnect = true;
                                }
                            }
                            if (!didConnect)
                            {
                                statusDetail = "Unable to connect to any peers";
                                Cancel();
                            }
                        }
                    }
                    else
                    {
                        LoggingService.LogDebug("Torrent is ready! Waiting for connections from peers!");
                    }
                }

                if (args.NewState == TorrentState.Seeding && manager.Progress == 100)
                {
                    if (Direction == FileTransferDirection.Download)
                    {
                        if (core.Settings.IncompleteDownloadDir != core.Settings.CompletedDownloadDir)
                        {
                            // Ensure torrent is stopped before attempting to move file, to avoid access violation.
                            manager.Stop();

                            System.IO.File.Move(Path.Combine(core.Settings.IncompleteDownloadDir, file.Name),
                                                Path.Combine(core.Settings.CompletedDownloadDir, file.Name));
                        }
                    }


                    foreach (BitTorrentFileTransferPeer peer in peers)
                    {
                        if (peer.Peer == null || !peer.Peer.IsSeeder)
                        {
                            return;
                        }
                    }

                    if (manager == null || manager.Progress != 100)
                    {
                        // If we got here, then everyone is a seeder.
                        // No need to keep the transfer active.
                        Cancel();
                    }
                    else
                    {
                        // Success! Ensure torrent is stopped.
                        manager.Stop();
                    }
                }
            } catch (Exception ex) {
                LoggingService.LogError("Error in manager_TorrentStateChanged.", ex);
                Cancel();
            }
        }