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


C# TorrentFile类代码示例

本文整理汇总了C#中TorrentFile的典型用法代码示例。如果您正苦于以下问题:C# TorrentFile类的具体用法?C# TorrentFile怎么用?C# TorrentFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TorrentFile类属于命名空间,在下文中一共展示了TorrentFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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