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


C# BEncodedDictionary.Add方法代码示例

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


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

示例1: Encode

 public BEncodedDictionary Encode()
 {
     var dict = new BEncodedDictionary();
     dict.Add(VersionKey, (BEncodedNumber) 1);
     dict.Add(InfoHashKey, new BEncodedString(Infohash.Hash));
     dict.Add(BitfieldKey, new BEncodedString(Bitfield.ToByteArray()));
     dict.Add(BitfieldLengthKey, (BEncodedNumber) Bitfield.Length);
     return dict;
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:9,代码来源:FastResume.cs

示例2: Encode

 public BEncodedValue Encode()
 {
     BEncodedDictionary result = new BEncodedDictionary();
     result.Add(new BEncodedString("MaxDownloadSpeed"), new BEncodedNumber(MaxDownloadSpeed));
     result.Add(new BEncodedString("MaxUploadSpeed"), new BEncodedNumber(MaxUploadSpeed));
     result.Add(new BEncodedString("MaxConnections"), new BEncodedNumber(MaxConnections));
     result.Add(new BEncodedString("UploadSlots"), new BEncodedNumber(UploadSlots));
     result.Add(new BEncodedString("SavePath"), new BEncodedString(savePath));
     return result;
 }
开发者ID:AssassinUKG,项目名称:monotorrent,代码行数:10,代码来源:GuiTorrentSettings.cs

示例3: 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

示例4: Serialize

        public BEncodedDictionary Serialize()
        {
            BEncodedDictionary d = new BEncodedDictionary ();
            d.Add ("FastResume", FastResume.Encode ());
            d.Add ("SavePath", (BEncodedString) SavePath);
            d.Add ("TorrentPath", (BEncodedString) TorrentPath);

            StringBuilder sb = new System.Text.StringBuilder();
            XmlSerializer s = new XmlSerializer (typeof (TorrentSettings));
            using (System.IO.TextWriter writer = new System.IO.StringWriter (sb))
                s.Serialize (writer, Settings);

            d.Add ("Settings", (BEncodedString) sb.ToString ());

            return d;
        }
开发者ID:jackgao,项目名称:bitsharp-dbus,代码行数:16,代码来源:TorrentData.cs

示例5: LTMetadata

        public LTMetadata(byte extensionId, eMessageType type, int piece, byte[] metadata)
            : this()
        {
            ExtensionId = extensionId;
            MetadataMessageType = type;
            MetadataPiece = metadata;
            Piece = piece;

            dict = new BEncodedDictionary();
            dict.Add(MessageTypeKey, (BEncodedNumber) (int) MetadataMessageType);
            dict.Add(PieceKey, (BEncodedNumber) piece);

            if (MetadataMessageType == eMessageType.Data)
            {
                Check.Metadata(metadata);
                dict.Add(TotalSizeKey, (BEncodedNumber) metadata.Length);
            }
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:18,代码来源:LTMetadata.cs

示例6: CreateInfoDict

 private BEncodedDictionary CreateInfoDict()
 {
     BEncodedDictionary dict = new BEncodedDictionary();
     dict.Add("source", new BEncodedString("http://www.thisiswhohostedit.com"));
     dict.Add("sha1", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("this is a sha1 hash string"))));
     dict.Add("ed2k", new BEncodedString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes("ed2k isn't a sha, but who cares"))));
     dict.Add("publisher-url.utf-8", new BEncodedString("http://www.iamthepublisher.com"));
     dict.Add("publisher-url", new BEncodedString("http://www.iamthepublisher.com"));
     dict.Add("publisher.utf-8", new BEncodedString("MonoTorrent Inc."));
     dict.Add("publisher", new BEncodedString("MonoTorrent Inc."));
     dict.Add("files", CreateFiles());
     dict.Add("name.utf-8", new BEncodedString("MyBaseFolder"));
     dict.Add("name", new BEncodedString("MyBaseFolder"));
     dict.Add("piece length", new BEncodedNumber(512));
     dict.Add("private", new BEncodedString("1"));
     dict.Add("pieces", new BEncodedString(new byte[((26000 + 512) / 512) * 20])); // Total size is 26000, piecelength is 512
     return dict;
 }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:18,代码来源:TorrentTest.cs

示例7: StartUp

        public void StartUp()
        {
            DateTime current = new DateTime(2006, 7, 1, 5, 5, 5);
            DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0);
            TimeSpan span = current - epochStart;
            creationTime = (long)span.TotalSeconds;
            Console.WriteLine(creationTime.ToString() + "Creation seconds");

            BEncodedDictionary torrentInfo = new BEncodedDictionary();
            torrentInfo.Add("announce", new BEncodedString("http://myannouceurl/announce"));
            torrentInfo.Add("creation date", new BEncodedNumber(creationTime));
            torrentInfo.Add("nodes", new BEncodedList());                    //FIXME: What is this?
            torrentInfo.Add("comment.utf-8", new BEncodedString("my big long comment"));
            torrentInfo.Add("comment", new BEncodedString("my big long comment"));
            torrentInfo.Add("azureus_properties", new BEncodedDictionary()); //FIXME: What is this?
            torrentInfo.Add("created by", new BEncodedString("MonoTorrent/" + VersionInfo.ClientVersion));
            torrentInfo.Add("encoding", new BEncodedString("UTF-8"));
            torrentInfo.Add("info", CreateInfoDict());
            torrentInfo.Add("private", new BEncodedString("1"));
            torrent = Torrent.Load(torrentInfo);
        }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:21,代码来源:TorrentTest.cs

示例8: 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

示例9: 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

示例10: 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

示例11: LTMetadata

        public LTMetadata(byte extensionId, eMessageType type, int piece, byte[] metadata)
            : this()
        {
            ExtensionId = extensionId;
            _messageType = type;
            MetadataPiece = metadata;
            Piece = piece;

            _dict = new BEncodedDictionary
                        {
                            {MessageTypeKey, (BEncodedNumber) (int) _messageType},
                            {PieceKey, (BEncodedNumber) piece}
                        };

            if (_messageType != eMessageType.Data)
                return;

            Check.Metadata(metadata);
            _dict.Add(TotalSizeKey, (BEncodedNumber) metadata.Length);
        }
开发者ID:mrscylla,项目名称:octotorrent,代码行数:20,代码来源:LTMetadata.cs

示例12: AddCommonStuff

		///<summary>
		///this adds stuff common to single and multi file torrents
		///</summary>
		void AddCommonStuff(BEncodedDictionary torrent)
		{
			if (announces.Count > 0 && announces[0].Count > 0) torrent.Add("announce", new BEncodedString(announces[0][0]));

			// If there is more than one tier or the first tier has more than 1 tracker
			if (announces.Count > 1 || (announces.Count > 0 && announces[0].Count > 1))
			{
				var announceList = new BEncodedList();
				for (var i = 0; i < announces.Count; i++)
				{
					var tier = new BEncodedList();
					for (var j = 0; j < announces[i].Count; j++) tier.Add(new BEncodedString(announces[i][j]));

					announceList.Add(tier);
				}

				torrent.Add("announce-list", announceList);
			}

			var epocheStart = new DateTime(1970, 1, 1);
			var span = DateTime.Now - epocheStart;
			Logger.Log(null, "creation date: {0} - {1} = {2}:{3}", DateTime.Now, epocheStart, span, span.TotalSeconds);
			torrent.Add("creation date", new BEncodedNumber((long)span.TotalSeconds));
		}
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:27,代码来源:TorrentCreator.cs

示例13: AddMD5

		///<summary>calculate md5sum of a file</summary>
		///<param name="fileName">the file to sum with md5</param>
		void AddMD5(BEncodedDictionary dict, string fileName)
		{
			var hasher = MD5.Create();
			var sb = new StringBuilder();

			using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
			{
				var hash = hasher.ComputeHash(stream);

				foreach (var b in hash)
				{
					var hex = b.ToString("X");
					hex = hex.Length > 1 ? hex : "0" + hex;
					sb.Append(hex);
				}
				Logger.Log(null, "Sum for: '{0}' = {1}", fileName, sb.ToString());
			}
			dict.Add("md5sum", new BEncodedString(sb.ToString()));
		}
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:21,代码来源:TorrentCreator.cs

示例14: Create

 BEncodedDictionary Create(string key, string value)
 {
     var d = new BEncodedDictionary ();
     d.Add (key, (BEncodedString) value);
     return d;
 }
开发者ID:Eskat0n,项目名称:OctoTorrent,代码行数:6,代码来源:TorrentEditorTests.cs

示例15: TorrentCreator

		public TorrentCreator()
		{
			var info = new BEncodedDictionary();
			announces = new List<List<string>>();
			ignoreHiddenFiles = true;
			dict = new BEncodedDictionary();
			dict.Add("info", info);

			// Add in initial values for some of the torrent attributes
			PieceLength = 256*1024; // 256kB default piece size
			Encoding = "UTF-8";
		}
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:12,代码来源:TorrentCreator.cs


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