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


C# BEncodedList.Add方法代码示例

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


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

示例1: ErrorMessage

 public ErrorMessage(ErrorCode error, string message)
     : base(ErrorType)
 {
     var l = new BEncodedList();
     l.Add(new BEncodedNumber((int) error));
     l.Add(new BEncodedString(message));
     properties.Add(ErrorListKey, l);
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:8,代码来源:ErrorMessage.cs

示例2: benDictionaryEncodingBuffered

 public void benDictionaryEncodingBuffered()
 {
     var data = Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");
     var dict = new BEncodedDictionary();
     var list = new BEncodedList();
     list.Add(new BEncodedString("a"));
     list.Add(new BEncodedString("b"));
     dict.Add("spam", list);
     var result = new byte[dict.LengthInBytes()];
     dict.Encode(result, 0);
     Assert.True(Toolbox.ByteMatch(data, result));
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:12,代码来源:BEncodeTest.cs

示例3: benDictionaryEncoding

        public void benDictionaryEncoding()
        {
            byte[] data = System.Text.Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");

            BEncodedDictionary dict = new BEncodedDictionary();
            BEncodedList list = new BEncodedList();
            list.Add(new BEncodedString("a"));
            list.Add(new BEncodedString("b"));
            dict.Add("spam", list);
            Assert.AreEqual(System.Text.Encoding.UTF8.GetString(data), System.Text.Encoding.UTF8.GetString(dict.Encode()));
            Assert.IsTrue(Toolbox.ByteMatch(data, dict.Encode()));
        }
开发者ID:burris,项目名称:monotorrent,代码行数:12,代码来源:BEncodingTest.cs

示例4: benDictionaryEncoding

        public void benDictionaryEncoding()
        {
            var data = Encoding.UTF8.GetBytes("d4:spaml1:a1:bee");

            var dict = new BEncodedDictionary();
            var list = new BEncodedList();
            list.Add(new BEncodedString("a"));
            list.Add(new BEncodedString("b"));
            dict.Add("spam", list);
            Assert.Equal(Encoding.UTF8.GetString(data), Encoding.UTF8.GetString(dict.Encode()));
            Assert.True(Toolbox.ByteMatch(data, dict.Encode()));
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:12,代码来源:BEncodeTest.cs

示例5: CorruptList

        public void CorruptList()
        {
            var list = new BEncodedList();
            for (var i = 0; i < peers.Count; i++)
                list.Add((BEncodedString) peers[i].CompactPeer());

            list.Insert(2, new BEncodedNumber(5));
            VerifyDecodedPeers(Peer.Decode(list));

            list.Clear();
            list.Add(new BEncodedString(new byte[3]));
            IList<Peer> decoded = Peer.Decode(list);
            Assert.Equal(0, decoded.Count);
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:14,代码来源:PeerTests.cs

示例6: CorruptDictionary

 public void CorruptDictionary()
 {
     BEncodedList l = new BEncodedList();
     BEncodedDictionary d = new BEncodedDictionary();
     l.Add(d);
     IList<Peer> decoded = Peer.Decode(l);
     Assert.AreEqual(0, decoded.Count, "#1");
 }
开发者ID:JacklEventreur,项目名称:monotorrent,代码行数:8,代码来源:PeerTests.cs

示例7: CorruptDictionary

 public void CorruptDictionary()
 {
     var l = new BEncodedList();
     var d = new BEncodedDictionary();
     l.Add(d);
     IList<Peer> decoded = Peer.Decode(l);
     Assert.Equal(0, decoded.Count);
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:8,代码来源:PeerTests.cs

示例8: CorruptDictionary

        public void CorruptDictionary()
        {
            var list = new BEncodedList();
            var dictionary = new BEncodedDictionary();

            list.Add(dictionary);
            IList<Peer> decoded = Peer.Decode(list);
            Assert.AreEqual(0, decoded.Count, "#1");
        }
开发者ID:Eskat0n,项目名称:OctoTorrent,代码行数:9,代码来源:PeerTests.cs

示例9: CreateTorrent

        private static BEncodedDictionary CreateTorrent(int pieceLength)
        {
            var infoDict = new BEncodedDictionary();
            infoDict[new BEncodedString("piece length")] = new BEncodedNumber(pieceLength);
            infoDict[new BEncodedString("pieces")] = new BEncodedString(new byte[20*15]);
            infoDict[new BEncodedString("length")] = new BEncodedNumber(15*256*1024 - 1);
            infoDict[new BEncodedString("name")] = new BEncodedString("test.files");

            var dict = new BEncodedDictionary();
            dict[new BEncodedString("info")] = infoDict;

            var announceTier = new BEncodedList();
            announceTier.Add(new BEncodedString("custom://transfers1/announce"));
            announceTier.Add(new BEncodedString("custom://transfers2/announce"));
            announceTier.Add(new BEncodedString("http://transfers3/announce"));
            var announceList = new BEncodedList();
            announceList.Add(announceTier);
            dict[new BEncodedString("announce-list")] = announceList;
            return dict;
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:20,代码来源:EngineTestRig.cs

示例10: Handle

		public override void Handle(DhtEngine engine, Node node)
		{
			base.Handle(engine, node);

			BEncodedString token = engine.TokenManager.GenerateToken(node);
			var response = new GetPeersResponse(engine.RoutingTable.LocalNode.Id, TransactionId, token);
			if (engine.Torrents.ContainsKey(InfoHash))
			{
				var list = new BEncodedList();
				foreach (Node n in engine.Torrents[InfoHash])
					list.Add(n.CompactPort());
				response.Values = list;
			}
			else
			{
				// Is this right?
				response.Nodes = Node.CompactNode(engine.RoutingTable.GetClosest(InfoHash));
			}

			engine.MessageLoop.EnqueueSend(response, node.EndPoint);
		}
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:21,代码来源:GetPeers.cs

示例11: SaveNodes

        public byte[] SaveNodes()
        {
            var details = new BEncodedList();

            MainLoop.QueueWait(() =>
                                   {
                                       foreach (var bucket in RoutingTable.Buckets)
                                       {
                                           foreach (var node in bucket.Nodes)
                                               if (node.State != NodeState.Bad)
                                                   details.Add(node.CompactNode());

                                           if (bucket.Replacement != null)
                                               if (bucket.Replacement.State != NodeState.Bad)
                                                   details.Add(bucket.Replacement.CompactNode());
                                       }
                                   });

            return details.Encode();
        }
开发者ID:Eskat0n,项目名称:OctoTorrent,代码行数:20,代码来源:DhtEngine.cs

示例12: DecodeList

        public void DecodeList()
        {
            // List of String
            var list = new BEncodedList();
            foreach (var p in peers)
                list.Add((BEncodedString) p.CompactPeer());

            VerifyDecodedPeers(Peer.Decode(list));
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:9,代码来源:PeerTests.cs

示例13: DecodeDictionary

        public void DecodeDictionary()
        {
            var list = new BEncodedList();
            foreach (var p in peers)
            {
                var dict = new BEncodedDictionary();
                dict.Add("ip", (BEncodedString) p.ConnectionUri.Host);
                dict.Add("port", (BEncodedNumber) p.ConnectionUri.Port);
                dict.Add("peer id", (BEncodedString) p.PeerId);
                list.Add(dict);
            }

            VerifyDecodedPeers(Peer.Decode(list));
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:14,代码来源:PeerTests.cs

示例14: CreateFiles

        private BEncodedList CreateFiles()
        {
            BEncodedList files = new BEncodedList();
            BEncodedDictionary file;
            BEncodedList path;

            path = new BEncodedList();
            path.Add(new BEncodedString("file1.txt"));

            file = new BEncodedDictionary();
            file.Add("sha1", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash1"))));
            file.Add("ed2k", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash2"))));
            file.Add("length", new BEncodedNumber(50000));
            file.Add("md5sum", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash3"))));
            file.Add("path.utf-8", path);
            file.Add("path", path);

            files.Add(file);


            path = new BEncodedList();
            path.Add(new BEncodedString("subfolder1"));
            path.Add(new BEncodedString("file2.txt"));

            file = new BEncodedDictionary();
            file.Add("sha1", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash1"))));
            file.Add("ed2k", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash2"))));
            file.Add("length", new BEncodedNumber(60000));
            file.Add("md5sum", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash3"))));
            file.Add("path.utf-8", path);
            file.Add("path", path);

            files.Add(file);


            path = new BEncodedList();
            path.Add(new BEncodedString("subfolder1"));
            path.Add(new BEncodedString("subfolder2"));
            path.Add(new BEncodedString("file3.txt"));

            file = new BEncodedDictionary();
            file.Add("sha1", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash1"))));
            file.Add("ed2k", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash2"))));
            file.Add("length", new BEncodedNumber(70000));
            file.Add("md5sum", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash3"))));
            file.Add("path.utf-8", path);
            file.Add("path", path);

            files.Add(file);


            path = new BEncodedList();
            path.Add(new BEncodedString("subfolder1"));
            path.Add(new BEncodedString("subfolder2"));
            path.Add(new BEncodedString("file4.txt"));

            file = new BEncodedDictionary();
            file.Add("sha1", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash1"))));
            file.Add("ed2k", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash2"))));
            file.Add("length", new BEncodedNumber(80000));
            file.Add("md5sum", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("file1 hash3"))));
            file.Add("path.utf-8", path);
            file.Add("path", path);

            files.Add(file);

            return files;
        }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:68,代码来源:TorrentTest.cs

示例15: SaveFastResume

        public void SaveFastResume()
        {
            if (string.IsNullOrWhiteSpace(settings.FastResumePath))
                return;

            var encodedList = new BEncodedList();
            var fastResumeData = torrentsReadonly
                .Where(x => x.HashChecked)
                .Select(tm => tm.SaveFastResume().Encode());
            foreach (var data in fastResumeData)
                encodedList.Add(data);

            File.WriteAllBytes(settings.FastResumePath, encodedList.Encode());
        }
开发者ID:mrscylla,项目名称:octotorrent,代码行数:14,代码来源:ClientEngine.cs


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