本文整理汇总了C#中TorrentFile类的典型用法代码示例。如果您正苦于以下问题:C# TorrentFile类的具体用法?C# TorrentFile怎么用?C# TorrentFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TorrentFile类属于命名空间,在下文中一共展示了TorrentFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetStream
internal TorrentFileStream GetStream(TorrentFile file, FileAccess access)
{
TorrentFileStream s = FindStream(file.FullPath);
if (s != null)
{
// If we are requesting write access and the current stream does not have it
if (((access & FileAccess.Write) == FileAccess.Write) && !s.CanWrite)
{
Logger.Log (null, "Didn't have write permission - reopening");
CloseAndRemove(s);
s = null;
}
else
{
// Place the filestream at the end so we know it's been recently used
list.Remove(s);
list.Add(s);
}
}
if (s == null)
{
if (!File.Exists(file.FullPath))
{
Directory.CreateDirectory (Path.GetDirectoryName(file.FullPath));
SparseFile.CreateSparse (file.FullPath, file.Length);
}
s = new TorrentFileStream (file, FileMode.OpenOrCreate, access, FileShare.Read);
Add(s);
}
return s;
}
开发者ID:pilhlip,项目名称:bitsharp-0.90,代码行数:34,代码来源:FileStreamBuffer.cs
示例2: Exists
internal bool Exists(string path, TorrentFile[] files)
{
Check.Path(path);
Check.Files(files);
foreach (var file in files) if (Exists(path, file)) return true;
return false;
}
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:7,代码来源:PieceWriter.cs
示例3: Main
static void Main(string[] args)
{
TorrentFile torrent;
using (var stream = new FileStream("ubuntu-13.10-desktop-amd64.iso.torrent", FileMode.Open))
using (var decoded = new TorrentBDecoder(stream, Encoding.UTF8))
{
var torrentAsDictionary = decoded.Decode() as Dictionary<object, object>;
torrent = new TorrentFile(torrentAsDictionary, decoded.GetInfoHash());
}
if (torrent.IsMultiAnnounce)
{
// Trackers are grouped.
foreach (var trackerList in torrent.AnnounceList)
{
foreach(var tracker in trackerList)
Console.WriteLine("Tracker: " + tracker);
}
}
else
{
Console.WriteLine("Tracker: " + torrent.Announce);
}
}
开发者ID:jvandertil,项目名称:csharp-bencode,代码行数:26,代码来源:Program.cs
示例4: BufferedIO
internal BufferedIO(object manager, ArraySegment<byte> buffer, long offset, int count, int pieceLength, TorrentFile[] files, string path)
{
this.Path = path;
this.files = files;
this.pieceLength = pieceLength;
Initialise(buffer, offset, count);
}
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:7,代码来源:PieceData.cs
示例5: CreateQueryString
/// <summary>
/// Parses a TorrentFile collection changeset into regular KeyValuePair enumerable.
/// </summary>
/// <param name="files"></param>
/// <returns></returns>
private static IEnumerable<KeyValuePair<string,string >> CreateQueryString(TorrentFile[] files)
{
var changed = (from f in files
where f.PriorityChanged
group f by f.Hash
into g
select new
{
Hash = g.Key,
Values = g.Select(fl => new
{
Prior = fl.Priority,
Index = Array.IndexOf(files, fl)
})
});
var parameters = new List<KeyValuePair<string, string>>();
foreach (var ch in changed)
{
parameters.Add(new KeyValuePair<string, string>("hash",ch.Hash));
foreach (var value in ch.Values)
{
parameters.Add(
new KeyValuePair<string, string>("p",((int)value.Prior).ToString()));
parameters.Add(new KeyValuePair<string, string>("f",value.Index.ToString()));
}
}
return parameters;
}
开发者ID:Horusiath,项目名称:UTorri,代码行数:34,代码来源:PriorityQueryCommand.cs
示例6: Move
public override void Move(string oldPath, string newPath, TorrentFile file, bool ignoreExisting)
{
var oldFile = GenerateFilePath(oldPath, file);
var newFile = GenerateFilePath(newPath, file);
streamsBuffer.CloseStream(oldFile);
if (ignoreExisting) File.Delete(newFile);
File.Move(oldFile, newFile);
}
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:8,代码来源:DiskWriter.cs
示例7: GetStream
internal TorrentFileStream GetStream(TorrentFile file, FileAccessMode access)
{
var fullPath = file.FullPath;
var asyncTokens = GetAsyncTokens(fullPath);
try
{
asyncTokens.CancellationTokenSource.Token.ThrowIfCancellationRequested();
var s = FindStream(fullPath);
if (s != null)
{
// If we are requesting write access and the current stream does not have it
if (access == FileAccessMode.ReadWrite && !s.CanWrite)
{
Debug.WriteLine("Didn't have write permission - reopening");
CloseAndRemove(s);
}
else
{
lock (_locker)
{
// Place the filestream at the end so we know it's been recently used
_streams.Remove(s);
_streams.Add(s);
}
return s;
}
}
try
{
var result = OpenStreamAsync(file, access, asyncTokens).Result;
file.Exists = true;
s = new TorrentFileStream(file, result)
{
Size = (ulong) file.Length
};
Add(s);
}
catch (AggregateException ex)
{
if (ex.InnerException is OperationCanceledException ||
ex.InnerException is UnauthorizedAccessException)
throw ex.InnerException;
throw;
}
return s;
}
finally
{
if (asyncTokens != null)
{
asyncTokens.SemaphoreSlim.Release();
if (asyncTokens.CancellationTokenSource.IsCancellationRequested)
Clear(fullPath);
}
}
}
开发者ID:haroldma,项目名称:Universal.Torrent,代码行数:57,代码来源:FileStreamBuffer.cs
示例8: Initialise
public override void Initialise(BitField bitfield, TorrentFile[] files, IEnumerable<Piece> requests)
{
this.bitfield = bitfield;
endgameSelector = new BitField(bitfield.Length);
this.files = files;
inEndgame = false;
TryEnableEndgame();
ActivePicker.Initialise(bitfield, files, requests);
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:9,代码来源:EndGameSwitcher.cs
示例9: Write
public override void Write(TorrentFile file, long offset, byte[] buffer, int bufferOffset, int count)
{
Check.File(file);
Check.Buffer(buffer);
if (offset < 0L || offset + count > file.Length)
throw new ArgumentOutOfRangeException(nameof(offset));
var s = GetStream(file, FileAccessMode.ReadWrite);
s.Seek((ulong) offset);
s.WriteAsync(buffer.AsBuffer(bufferOffset, count)).AsTask().Wait();
}
开发者ID:haroldma,项目名称:Universal.Torrent,代码行数:10,代码来源:DiskWriter.cs
示例10: Initialise
public override void Initialise(BitField bitfield, TorrentFile[] files, IEnumerable<Piece> requests)
{
// 'Requests' should contain a list of all the pieces we need to complete
pieces = new List<Piece>(requests);
foreach (var piece in pieces)
{
for (var i = 0; i < piece.BlockCount; i++)
if (piece.Blocks[i].RequestedOff != null)
this.requests.Add(new Request(piece.Blocks[i].RequestedOff, piece.Blocks[i]));
}
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:11,代码来源:EndGamePicker.cs
示例11: FileManager
private string savePath; // The path where the base directory will be put
#endregion Fields
#region Constructors
/// <summary>
/// Creates a new FileManager with the supplied FileAccess
/// </summary>
/// <param name="files">The TorrentFiles you want to create/open on the disk</param>
/// <param name="baseDirectory">The name of the directory that the files are contained in</param>
/// <param name="savePath">The path to the directory that contains the baseDirectory</param>
/// <param name="pieceLength">The length of a "piece" for this file</param>
/// <param name="fileAccess">The access level for the files</param>
internal FileManager(TorrentManager manager, TorrentFile[] files, int pieceLength, string savePath, string baseDirectory)
{
this.hasher = SHA1.Create();
this.manager = manager;
this.savePath = Path.Combine(savePath, baseDirectory);
this.files = files;
this.pieceLength = pieceLength;
foreach (TorrentFile file in files)
fileSize += file.Length;
}
开发者ID:burris,项目名称:monotorrent,代码行数:25,代码来源:FileManager.cs
示例12: Write
public override void Write(TorrentFile file, long offset, byte[] buffer, int bufferOffset, int count)
{
Check.File(file);
Check.Buffer(buffer);
if (offset < 0 || offset + count > file.Length)
throw new ArgumentOutOfRangeException("offset");
TorrentFileStream stream = GetStream(file, FileAccess.ReadWrite);
stream.Seek(offset, SeekOrigin.Begin);
stream.Write(buffer, bufferOffset, count);
}
开发者ID:dontnod,项目名称:monotorrent,代码行数:12,代码来源:DiskWriter.cs
示例13: FixtureSetup
public void FixtureSetup()
{
pieceLength = Piece.BlockSize * 2;
singleFile = new TorrentFile("path", Piece.BlockSize * 5);
multiFile = new TorrentFile[] {
new TorrentFile ("first", Piece.BlockSize - 550),
new TorrentFile ("second", 100),
new TorrentFile ("third", Piece.BlockSize)
};
buffer = new byte[Piece.BlockSize];
torrentSize = Toolbox.Accumulate<TorrentFile>(multiFile, delegate(TorrentFile f) { return f.Length; });
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:12,代码来源:MemoryWriterTests.cs
示例14: Flush
public override void Flush(TorrentFile file)
{
for (int i = 0; i < cachedBlocks.Count; i++)
{
if (cachedBlocks[i].File == file)
{
CachedBlock b = cachedBlocks[i];
writer.Write(b.File, b.Offset, b.Buffer, 0, b.Count);
ClientEngine.BufferManager.FreeBuffer(ref b.Buffer);
}
}
cachedBlocks.RemoveAll(delegate(CachedBlock b) { return b.File == file; });
}
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:13,代码来源:MemoryWriter.cs
示例15: FixtureSetup
public void FixtureSetup()
{
_pieceLength = Piece.BlockSize*2;
_singleFile = new TorrentFile("path", Piece.BlockSize*5);
_multiFile = new[]
{
new TorrentFile("first", Piece.BlockSize - 550),
new TorrentFile("second", 100),
new TorrentFile("third", Piece.BlockSize)
};
_buffer = new byte[Piece.BlockSize];
_torrentSize = _multiFile.Sum(x => x.Length);
}
开发者ID:Eskat0n,项目名称:OctoTorrent,代码行数:13,代码来源:MemoryWriterTests.cs
示例16: Read
public override int Read(TorrentFile file, long offset, byte[] buffer, int bufferOffset, int count)
{
if (DoNotReadFrom.Contains(file))
return 0;
if (!Paths.Contains(file.FullPath))
Paths.Add(file.FullPath);
if (!DontWrite)
for (int i = 0; i < count; i++)
buffer[bufferOffset + i] = (byte)(bufferOffset + i);
return count;
}
开发者ID:pilhlip,项目名称:bitsharp-0.90,代码行数:13,代码来源:TestRig.cs
示例17: Read
public override int Read(TorrentFile file, long offset, byte[] buffer, int bufferOffset, int count)
{
Check.File(file);
Check.Buffer(buffer);
if (offset < 0 || offset + count > file.Length)
throw new ArgumentOutOfRangeException("offset");
Stream s = GetStream(file, FileAccess.Read);
if (s.Length < offset + count)
return 0;
s.Seek(offset, SeekOrigin.Begin);
return s.Read(buffer, bufferOffset, count);
}
开发者ID:dontnod,项目名称:monotorrent,代码行数:14,代码来源:DiskWriter.cs
示例18: Read
public override int Read(TorrentFile file, long offset, byte[] buffer, int bufferOffset, int count)
{
Check.File(file);
Check.Buffer(buffer);
if (offset < 0L || offset + count > file.Length)
throw new ArgumentOutOfRangeException(nameof(offset));
var s = GetStream(file, FileAccessMode.Read);
if (s == null || s.Size < (ulong) offset + (ulong) count)
return 0;
s.Seek((ulong) offset);
var buff = buffer.AsBuffer(bufferOffset, count);
s.ReadAsync(buff, (uint) count, InputStreamOptions.Partial).AsTask().Wait();
return count;
}
开发者ID:haroldma,项目名称:Universal.Torrent,代码行数:15,代码来源:DiskWriter.cs
示例19: MemoryWriterTests
public MemoryWriterTests()
{
pieceLength = Piece.BlockSize*2;
singleFile = new TorrentFile("path", Piece.BlockSize*5);
multiFile = new[]
{
new TorrentFile("first", Piece.BlockSize - 550),
new TorrentFile("second", 100),
new TorrentFile("third", Piece.BlockSize)
};
buffer = new byte[Piece.BlockSize];
torrentSize = Toolbox.Accumulate(multiFile, delegate(TorrentFile f) { return f.Length; });
Initialise(buffer, 1);
level2 = new MemoryWriter(new NullWriter(), Piece.BlockSize*3);
level1 = new MemoryWriter(level2, Piece.BlockSize*3);
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:17,代码来源:MemoryWriterTests.cs
示例20: Read
public override int Read(TorrentFile file, long offset, byte[] buffer, int bufferOffset, int count)
{
Check.File(file);
Check.Buffer(buffer);
for (var i = 0; i < cachedBlocks.Count; i++)
{
if (cachedBlocks[i].File != file)
continue;
if (cachedBlocks[i].Offset != offset || cachedBlocks[i].File != file || cachedBlocks[i].Count != count)
continue;
Buffer.BlockCopy(cachedBlocks[i].Buffer, 0, buffer, bufferOffset, count);
return count;
}
return writer.Read(file, offset, buffer, bufferOffset, count);
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:17,代码来源:MemoryWriter.cs
注:本文中的TorrentFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论