コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TorrentInfo" /> class.
        /// </summary>
        /// <param name="dictionary">The dictionary.</param>
        /// <param name="infoHash">The hash.</param>
        /// <param name="pieceLength">Length of the piece.</param>
        /// <param name="piecesHashValues">The pieces.</param>
        /// <param name="isPrivate">if set to <c>true</c> this torrent is private.</param>
        /// <param name="announceList">The announce list.</param>
        /// <param name="creationDate">The creation date.</param>
        /// <param name="comment">The comment.</param>
        /// <param name="createdBy">The created by.</param>
        /// <param name="encoding">The encoding.</param>
        /// <param name="files">The files.</param>
        private TorrentInfo(BEncodedDictionary dictionary, string infoHash, long pieceLength, IEnumerable <string> piecesHashValues, bool isPrivate, IEnumerable <Uri> announceList, DateTime?creationDate, string comment, string createdBy, Encoding encoding, IEnumerable <TorrentFileInfo> files)
        {
            dictionary.CannotBeNull();
            infoHash.CannotBeNullOrEmpty();
            infoHash.Length.MustBeEqualTo(40);
            pieceLength.MustBeGreaterThan(0);
            piecesHashValues.CannotBeNullOrEmpty();
            announceList.CannotBeNullOrEmpty();
            encoding.CannotBeNull();
            files.CannotBeNullOrEmpty();

            this.dictionary   = dictionary;
            this.InfoHash     = infoHash;
            this.PieceLength  = pieceLength;
            this.PieceHashes  = piecesHashValues;
            this.IsPrivate    = isPrivate;
            this.AnnounceList = announceList;
            this.CreationDate = creationDate;
            this.Comment      = comment;
            this.CreatedBy    = createdBy;
            this.Encoding     = encoding;
            this.Files        = files;
            this.Length       = files.Sum(x => x.Length);
            this.PiecesCount  = piecesHashValues.Count();
            this.BlockLength  = PieceMessage.DefaultBlockLength;
            this.BlocksCount  = (int)(pieceLength / PieceMessage.DefaultBlockLength);
        }