当前位置: 首页>>代码示例>>C#>>正文


C# Tracker.Remove方法代码示例

本文整理汇总了C#中Tracker.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Tracker.Remove方法的具体用法?C# Tracker.Remove怎么用?C# Tracker.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tracker的用法示例。


在下文中一共展示了Tracker.Remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SimpleTracker

        public SimpleTracker(string announcementEndpoint, string torrentsDirectoryPath)
        {
            // Make the listner.
            var listener = new HttpListener(announcementEndpoint);

            // Make the tracker.
            Tracker = new Tracker ();
            Tracker.AnnounceInterval = new TimeSpan (0, 1, 0);
            Tracker.AllowUnregisteredTorrents = true;
            Tracker.RegisterListener (listener);

            // Make mappings.
            Mappings = new ConcurrentDictionary<string, InfoHashTrackable> ();

            // Make watcher.
            Watcher = new TorrentFolderWatcher (torrentsDirectoryPath, "*.torrent");
            Watcher.TorrentFound += (sender, e) =>
            {
                try
                {
                    // Wait for file to finish copying.
                    System.Threading.Thread.Sleep (500);

                    // Make InfoHashTrackable from torrent.
                    var torrent = Torrent.Load (e.TorrentPath);
                    var trackable = new InfoHashTrackable (torrent);

                    // Add to tracker.
                    lock (Tracker)
                        Tracker.Add (trackable);

                    // Save to mappings.
                    Mappings[e.TorrentPath] = trackable;

                    // Log.
                    Console.WriteLine("Added {0}", e.TorrentPath);
                }
                catch (Exception exception)
                {
                    Debug.WriteLine ("Error loading torrent from disk: {0}", exception.Message);
                    Debug.WriteLine ("Stacktrace: {0}", exception.ToString ());
                }
            };
            Watcher.TorrentLost += (sender, e) =>
            {
                try
                {
                    // Get from mappings.
                    var trackable = Mappings[e.TorrentPath];

                    // Remove from tracker.
                    lock(Tracker)
                        Tracker.Remove(trackable);

                    // Remove from mappings.
                    Mappings.TryRemove(e.TorrentPath, out trackable);

                    // Log.
                    Console.WriteLine("Removed {0}", e.TorrentPath);
                }
                catch(Exception exception)
                {
                    Debug.WriteLine ("Error uploading torrent from disk: {0}", exception.Message);
                    Debug.WriteLine ("Stacktrace: {0}", exception.ToString ());
                }
            };

            // Register close events.
            AppDomain.CurrentDomain.ProcessExit += (sender, e) => Tracker.Dispose ();

            // Run.
            listener.Start();
            Watcher.Start();
            Watcher.ForceScan();
        }
开发者ID:kl4w,项目名称:SimpleTracker,代码行数:75,代码来源:SimpleTracker.cs


注:本文中的Tracker.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。