本文整理汇总了C#中BEncodedDictionary类的典型用法代码示例。如果您正苦于以下问题:C# BEncodedDictionary类的具体用法?C# BEncodedDictionary怎么用?C# BEncodedDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BEncodedDictionary类属于命名空间,在下文中一共展示了BEncodedDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: shutdown
private static void shutdown()
{
BEncodedDictionary fastResume = new BEncodedDictionary();
for (int i = 0; i < torrents.Count; i++)
{
WaitHandle handle = torrents[i].Stop(); ;
while (!handle.WaitOne(10, true))
Console.WriteLine(handle.ToString());
Console.WriteLine(handle.ToString());
fastResume.Add(torrents[i].Torrent.InfoHash, torrents[i].SaveFastResume().Encode());
}
File.WriteAllBytes(dhtNodeFile, engine.DhtEngine.SaveNodes());
File.WriteAllBytes(fastResumeFile, fastResume.Encode());
engine.Dispose();
foreach (TraceListener lst in Debug.Listeners)
{
lst.Flush();
lst.Close();
}
System.Threading.Thread.Sleep(2000);
}
示例2: shutdown
private static void shutdown()
{
#if !DISABLE_DHT
File.WriteAllBytes(dhtNodeFile, engine.DhtEngine.SaveNodes());
#endif
BEncodedDictionary fastResume = new BEncodedDictionary();
for (int i = 0; i < torrents.Count; i++)
{
torrents[i].Stop(); ;
while (torrents[i].State != TorrentState.Stopped)
{
Console.WriteLine("{0} is {1}", torrents[i].Torrent.Name, torrents[i].State);
Thread.Sleep(250);
}
fastResume.Add(torrents[i].Torrent.InfoHash.ToHex (), torrents[i].SaveFastResume().Encode());
}
File.WriteAllBytes(fastResumeFile, fastResume.Encode());
engine.Dispose();
foreach (TraceListener lst in Debug.Listeners)
{
lst.Flush();
lst.Close();
}
System.Threading.Thread.Sleep(2000);
}
示例3: Shutdown
private static void Shutdown()
{
var fastResume = new BEncodedDictionary();
foreach (var torrentManager in torrents)
{
torrentManager.Stop();
while (torrentManager.State != TorrentState.Stopped)
{
Console.WriteLine("{0} is {1}", torrentManager.Torrent.Name, torrentManager.State);
Thread.Sleep(250);
}
fastResume.Add(torrentManager.Torrent.InfoHash.ToHex (), torrentManager.SaveFastResume().Encode());
}
#if !DISABLE_DHT
File.WriteAllBytes(_dhtNodeFile, _engine.DhtEngine.SaveNodes());
#endif
File.WriteAllBytes(_fastResumeFile, fastResume.Encode());
_engine.Dispose();
foreach (TraceListener lst in Debug.Listeners)
{
lst.Flush();
lst.Close();
}
Thread.Sleep(2000);
}
示例4: BitTorrentManager
public BitTorrentManager(BitTorrentCache bittorrentCache, string selfNameSpace,
DictionaryServiceProxy dhtProxy, DictionaryServiceTracker dhtTracker, ClientEngine clientEngine,
TorrentSettings torrentDefaults, TorrentHelper torrentHelper,
bool startSeedingAtStartup)
{
_bittorrentCache = bittorrentCache;
SelfNameSpace = selfNameSpace;
_dictProxy = dhtProxy;
_dictTracker = dhtTracker;
_torrentDefaults = torrentDefaults;
_startSeedingAtStartup = startSeedingAtStartup;
RegisterClientEngineEventHandlers(clientEngine);
_clientEngine = clientEngine;
_torrentHelper = torrentHelper;
try {
_fastResumeData = BEncodedValue.Decode<BEncodedDictionary>(
File.ReadAllBytes(_bittorrentCache.FastResumeFilePath));
} catch {
_fastResumeData = new BEncodedDictionary();
}
// CacheRegistry is created here because the default cache registry file path is
// defined here.
CacheRegistry = new CacheRegistry(_bittorrentCache.CacheRegistryFilePath, selfNameSpace);
CacheRegistry.LoadCacheDir(_bittorrentCache.DownloadsDirPath);
}
示例5: 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");
}
示例6: LoadSupports
private void LoadSupports(BEncodedDictionary supports)
{
var list = new ExtensionSupports();
foreach (var k in supports)
list.Add(new ExtensionSupport(k.Key.Text, (byte) ((BEncodedNumber) k.Value).Number));
Supports = list;
}
示例7: CheckContent
private void CheckContent(BEncodedDictionary dict, BEncodedString key, BEncodedNumber value)
{
CheckContent(dict, key);
if (!dict[key].Equals(value))
throw new TorrentException(
string.Format("Invalid FastResume data. The value of '{0}' was '{1}' instead of '{2}'", key,
dict[key], value));
}
示例8: 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);
}
示例9: 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;
}
示例10: QueryMessage
protected QueryMessage(NodeId id, BEncodedString queryName, BEncodedDictionary queryArguments, ResponseCreator responseCreator)
: base(QueryType)
{
Properties.Add(QueryNameKey, queryName);
Properties.Add(QueryArgumentsKey, queryArguments);
Parameters.Add(IdKey, id.BencodedString());
ResponseCreator = responseCreator;
}
示例11: 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");
}
示例12: 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)"");
}
示例13: 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;
}
示例14: DecodeMessage
public static Message DecodeMessage(BEncodedDictionary dictionary)
{
Message message;
string error;
if (!TryDecodeMessage(dictionary, out message, out error))
throw new MessageException(ErrorCode.GenericError, error);
return message;
}
示例15: Encode
public BEncodedDictionary Encode()
{
var dict = new BEncodedDictionary
{
{VersionKey, (BEncodedNumber) 1},
{InfoHashKey, new BEncodedString(Infohash.Hash)},
{BitfieldKey, new BEncodedString(Bitfield.ToByteArray())},
{BitfieldLengthKey, (BEncodedNumber) Bitfield.Length}
};
return dict;
}