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


C# BEncodedDictionary.ContainsKey方法代码示例

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


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

示例1: Decode

 public override void Decode(byte[] buffer, int offset, int length)
 {
     peerDict = BEncodedValue.Decode<BEncodedDictionary>(buffer, offset, length, false);
     if (!peerDict.ContainsKey(AddedKey))
         peerDict.Add(AddedKey, (BEncodedString)"");
     if (!peerDict.ContainsKey(AddedDotFKey))
         peerDict.Add(AddedDotFKey, (BEncodedString)"");
     if (!peerDict.ContainsKey(DroppedKey))
         peerDict.Add(DroppedKey, (BEncodedString)"");
 }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:10,代码来源:PeerExchangeMessage.cs

示例2: FastResume

        public FastResume(BEncodedDictionary dict)
        {
            CheckContent(dict, VersionKey, (BEncodedNumber)1);
            CheckContent(dict, InfoHashKey);
            CheckContent(dict, BitfieldKey);
            CheckContent(dict, BitfieldLengthKey);

            infoHash = new InfoHash(((BEncodedString)dict[InfoHashKey]).TextBytes);
            bitfield = new BitField((int)((BEncodedNumber)dict[BitfieldLengthKey]).Number);
            byte[] data = ((BEncodedString)dict[BitfieldKey]).TextBytes;
            bitfield.FromArray(data, 0, data.Length);

            if (dict.ContainsKey(PrioritiesKey))
            {
                var list = (BEncodedList)dict[PrioritiesKey];
                priorities = list.Select(v => (Priority)((BEncodedNumber)v).Number).ToArray();
            }
        }
开发者ID:silvermcd123,项目名称:WoWPrivateServerLauncher,代码行数:18,代码来源:FastResume.cs

示例3: StartEngine

        private static void StartEngine()
        {
            int port;
            Torrent torrent = null;
            // Ask the user what port they want to use for incoming connections
            //Console.Write(Environment.NewLine + "Choose a listen port: ");
            //while (!Int32.TryParse(Console.ReadLine(), out port)) { }
            port = 4545;

            // Create the settings which the engine will use
            // downloadsPath - this is the path where we will save all the files to
            // port - this is the port we listen for connections on
            EngineSettings engineSettings = new EngineSettings(downloadsPath, port);
            engineSettings.PreferEncryption = false;
            engineSettings.AllowedEncryption = EncryptionTypes.All;

            //engineSettings.GlobalMaxUploadSpeed = 30 * 1024;
            //engineSettings.GlobalMaxDownloadSpeed = 100 * 1024;
            //engineSettings.MaxReadRate = 1 * 1024 * 1024;

            // Create the default settings which a torrent will have.
            // 4 Upload slots - a good ratio is one slot per 5kB of upload speed
            // 50 open connections - should never really need to be changed
            // Unlimited download speed - valid range from 0 -> int.Max
            // Unlimited upload speed - valid range from 0 -> int.Max
            TorrentSettings torrentDefaults = new TorrentSettings(4, 150, 0, 0);

            // Create an instance of the engine.
            engine = new ClientEngine(engineSettings);
            engine.ChangeListenEndpoint(new IPEndPoint(IPAddress.Any, port));
            byte[] nodes = null;
            try
            {
                nodes = File.ReadAllBytes(dhtNodeFile);
            }
            catch
            {
                Console.WriteLine("No existing dht nodes could be loaded");
            }

            DhtListener dhtListner = new DhtListener (new IPEndPoint (IPAddress.Any, port));
            DhtEngine dht = new DhtEngine (dhtListner);
            engine.RegisterDht(dht);
            dhtListner.Start();
            engine.DhtEngine.Start(nodes);

            // If the SavePath does not exist, we want to create it.
            if (!Directory.Exists(engine.Settings.SavePath))
                Directory.CreateDirectory(engine.Settings.SavePath);

            // If the torrentsPath does not exist, we want to create it
            if (!Directory.Exists(torrentsPath))
                Directory.CreateDirectory(torrentsPath);

            BEncodedDictionary fastResume;
            try
            {
                fastResume = BEncodedValue.Decode<BEncodedDictionary>(File.ReadAllBytes(fastResumeFile));
            }
            catch
            {
                fastResume = new BEncodedDictionary();
            }

            // For each file in the torrents path that is a .torrent file, load it into the engine.
            foreach (string file in Directory.GetFiles(torrentsPath))
            {
                if (file.EndsWith(".torrent"))
                {
                    try
                    {
                        // Load the .torrent from the file into a Torrent instance
                        // You can use this to do preprocessing should you need to
                        torrent = Torrent.Load(file);
                        Console.WriteLine(torrent.InfoHash.ToString());
                    }
                    catch (Exception e)
                    {
                        Console.Write("Couldn't decode {0}: ", file);
                        Console.WriteLine(e.Message);
                        continue;
                    }
                    // When any preprocessing has been completed, you create a TorrentManager
                    // which you then register with the engine.
                    TorrentManager manager = new TorrentManager(torrent, downloadsPath, torrentDefaults);
                    if (fastResume.ContainsKey(torrent.InfoHash.ToHex ()))
                        manager.LoadFastResume(new FastResume ((BEncodedDictionary)fastResume[torrent.InfoHash.ToHex ()]));
                    engine.Register(manager);

                    // Store the torrent manager in our list so we can access it later
                    torrents.Add(manager);
                    manager.PeersFound += new EventHandler<PeersAddedEventArgs>(manager_PeersFound);
                }
            }

            // If we loaded no torrents, just exist. The user can put files in the torrents directory and start
            // the client again
            if (torrents.Count == 0)
            {
                Console.WriteLine("No torrents found in the Torrents directory");
//.........这里部分代码省略.........
开发者ID:pdg6868,项目名称:monotorrent,代码行数:101,代码来源:main.cs

示例4: Set

		static void Set(BEncodedDictionary dictionary, BEncodedString key, BEncodedValue value)
		{
			if (dictionary.ContainsKey(key)) dictionary[key] = value;
			else dictionary.Add(key, value);
		}
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:5,代码来源:TorrentCreator.cs

示例5: Get

		static BEncodedValue Get(BEncodedDictionary dictionary, BEncodedString key)
		{
			return dictionary.ContainsKey(key) ? dictionary[key] : null;
		}
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:4,代码来源:TorrentCreator.cs

示例6: CheckContent

 private void CheckContent(BEncodedDictionary dict, BEncodedString key)
 {
     if (dict == null) throw new ArgumentNullException(nameof(dict));
     if (!dict.ContainsKey(key))
         throw new TorrentException(string.Format("Invalid FastResume data. Key '{0}' was not present", key));
 }
开发者ID:haroldma,项目名称:Universal.Torrent,代码行数:6,代码来源:FastResume.cs

示例7: DecodeFromDict

        private static Peer DecodeFromDict(BEncodedDictionary dict)
        {
            string peerId;

            if (dict.ContainsKey("peer id"))
                peerId = dict["peer id"].ToString();
            else if (dict.ContainsKey("peer_id"))       // HACK: Some trackers return "peer_id" instead of "peer id"
                peerId = dict["peer_id"].ToString();
            else
                peerId = string.Empty;

            Uri connectionUri = new Uri("tcp://" + dict["ip"].ToString() + ":" + dict["port"].ToString());
            return new Peer(peerId, connectionUri, EncryptionTypes.All);
        }
开发者ID:proff,项目名称:ProffTorrent,代码行数:14,代码来源:Peer.cs

示例8: InitializeTorrent

        public void InitializeTorrent(string torrentDir)
        {
            BEncodedDictionary fastResume;
            try
            {
                fastResume = BEncodedValue.Decode<BEncodedDictionary>(File.ReadAllBytes(this.fastResumeFile));
            }
            catch
            {
                fastResume = new BEncodedDictionary();
            }

            Torrent torrent = null;

            // Load the file into the engine if it ends with .torrent.

            if (torrentDir.EndsWith(".torrent"))
            {
                try
                {
                    // Load the .torrent file from the file into a Torrent instance
                    // You can use this to do preprocessing should you need to.
                    torrent = Torrent.Load(torrentDir);
                    Console.WriteLine(torrent.InfoHash.ToString());
                }
                catch (Exception e)
                {
                    Console.Write("Could not decode {0}: {1}", torrentDir, e.Message);
                    return;
                }

                // When any preprocessing has been completed, you create a TorrentManager which you then register with the engine.
                TorrentManager postProcessManager = new TorrentManager(torrent, this.downloadDir, torrentDefaults);
                if (fastResume.ContainsKey(torrent.InfoHash.ToHex()))
                {
                    postProcessManager.LoadFastResume(new FastResume((BEncodedDictionary)fastResume[torrent.InfoHash.ToHex()]));
                }

                this.clientEngine.Register(postProcessManager);

                // Store the torrent manager in our list so we can access it later.
                this.torrentManagers.Add(postProcessManager);

                postProcessManager.PeersFound += new EventHandler<PeersAddedEventArgs>(this.manager_PeersFound);
            }

            // For each torrent manager we loaded and stored in our list, hook into the events in the torrent manager and start the engine.
            foreach (TorrentManager torrentManager in this.torrentManagers)
            {
                // Every time a piece is hashed, this is fired.
                torrentManager.PieceHashed += delegate(object o, PieceHashedEventArgs e)
                {
                    lock (this.topTrackers)
                    {
                        topTrackers.WriteLine(string.Format("Piece hashed: {0} - {1} ", e.PieceIndex, e.HashPassed ? "passed" : "failed"));
                    }
                };

                // Everytime the state changes (stopped -> seeding -> downloading -> hashing), this is fired.
                foreach (TrackerTier tier in torrentManager.TrackerManager)
                {
                    List<Tracker> trackers = tier.GetTrackers();
                    foreach (Tracker tracker in trackers)
                    {
                        tracker.AnnounceComplete += delegate(object sender, AnnounceResponseEventArgs e)
                        {
                            this.topTrackers.WriteLine(string.Format("{0}: {1}", e.Successful, e.Tracker.ToString()));
                        };
                    }
                }

                // Start the torrentManager. The file will then hash (if required) and begin loading.
                torrentManager.Start();
            }

            Thread.Sleep(500);
        }
开发者ID:ballance,项目名称:MetroTorrent,代码行数:77,代码来源:TorrentsData.cs

示例9: CheckContent

 private static void CheckContent(BEncodedDictionary dict, BEncodedString key)
 {
     if (dict.ContainsKey(key) == false)
         throw new TorrentException(string.Format("Invalid FastResume data. Key '{0}' was not present", key));
 }
开发者ID:Eskat0n,项目名称:OctoTorrent,代码行数:5,代码来源:FastResume.cs

示例10: Initiate

        /// <summary>
        /// Fully starts the torrent engine and dht engine and listener
        /// Loads in any torrents from the directory and resumes them automaticallhy
        /// </summary>
        public void Initiate()
        {
            torrentEngine = new ClientEngine(engineSettings);
            torrentEngine.ChangeListenEndpoint(new IPEndPoint(IPAddress.Any, Port));

            //Load DHT nodes from a saved file
            //if not there  or any errors then continue
            byte[] nodes = null;
            try
            {
                nodes = File.ReadAllBytes(dhtNodeFile);
            }
            catch
            {
                //keep it null, what we use it for will instead create its own and then save them
                nodes = null;
            }

            //construct our listener for our dht engine and then create the dht engine
            //register it and then start it based on the nodes we attempted to load
            //construct our listener for our dht engine and then create the dht engine
            //register it and then start it based on the nodes we attempted to load
            dhtListener = new DhtListener(new IPEndPoint(IPAddress.Any, Port));
            dhtEngine = new DhtEngine(dhtListener);
            torrentEngine.RegisterDht(dhtEngine);
            torrentEngine.DhtEngine.Start(nodes);
            //same as with the dht nodes try to load but if any errors then continue
            try
            {
                fastResume = BEncodedValue.Decode<BEncodedDictionary>(File.ReadAllBytes(resumeFile));
            }
            catch
            {
                fastResume = new BEncodedDictionary();
            }

            //This is where we go into our save directory and look for any torrents
            //user may of left off on a download and we can possibly resume it
            //also a backend way to force a download from another  provider source to download
            foreach (string file in Directory.GetFiles(saveDirectory))
            {

                if (file.EndsWith(".torrent"))
                {
                    try
                    {
                        Torrent torrent = null;
                        torrent = Torrent.Load(file);
                        TorrentManager manager = new TorrentManager(torrent, saveDirectory, torrentSettings);
                        if (fastResume.ContainsKey(torrent.InfoHash.ToHex()))
                            manager.LoadFastResume(new FastResume((BEncodedDictionary)fastResume[torrent.InfoHash.ToHex()]));
                        torrentEngine.Register(manager);
                    }
                    catch { }

                }
            }
        }
开发者ID:GabrieleNunez,项目名称:JRCinemas,代码行数:62,代码来源:TorrentClient.cs


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