BEncodeLib.TorrentFile.TorrentFile C# (CSharp) Метод

TorrentFile() публичный Метод

public TorrentFile ( object>.IDictionary bareDictionary, byte infoHash ) : System
bareDictionary object>.IDictionary
infoHash byte
Результат System
        public TorrentFile(IDictionary<object, object> bareDictionary, byte[] infoHash)
        {
            InfoHash = infoHash;

            IsMultiAnnounce = bareDictionary.ContainsKey(MultiAnnounceKey);

            if (!IsMultiAnnounce)
            {
                Announce = DefaultEncoding.GetString((byte[]) bareDictionary[AnnounceKey]);
            }
            else
            {
                AnnounceList = new List<IList<string>>();
                var announceList = bareDictionary[MultiAnnounceKey] as IList<object>;

                /*
                 * Functionality of query below:
                foreach (object t in announceList)
                {
                    var sourceList = t as IList<object>;
                    var resultList = new List<string>();

                    for(int j = 0; j < sourceList.Count; j++)
                    {
                        resultList.Add(DefaultEncoding.GetString(sourceList[j] as byte[]));
                    }

                    AnnounceList.Add(resultList);
                }
                 */
                foreach (var resultList in
                    announceList.Select(t => t as IList<object>)
                        .Select(
                            sourceList =>
                            sourceList.Select(
                                sourceListElement => DefaultEncoding.GetString(sourceListElement as byte[])).ToList()))
                {
                    AnnounceList.Add(resultList);
                }
            }

            HasCreationDate = bareDictionary.ContainsKey(CreationDateKey);

            if (HasCreationDate)
            {
                CreationDate = EpochDateTime.AddSeconds((long) bareDictionary[CreationDateKey]);
            }

            var info = bareDictionary["info"] as IDictionary<object, object>;

            PieceSize = (long) info[PieceLengthKey];
            Pieces = (byte[]) info[PiecesKey];
            IsPrivate = (info.ContainsKey(PrivateKey)) && ((long) info[PrivateKey] == 1);

            IsMultiFile = info.ContainsKey(FilesKey);

            if (IsMultiFile)
            {
                DirectoryName = DefaultEncoding.GetString(info[DirNameKey] as byte[]);

                Files = new List<TorrentFileFileEntry>();
                foreach (var objDic in (info[FilesKey] as IList<object>).Cast<IDictionary<object, object>>())
                {
                    var fileSize = (long) objDic[FileSizeKey];
                    List<string> pathList = (from pathObj in (objDic[FilePathKey] as IList<object>)
                                             select DefaultEncoding.GetString(pathObj as byte[])).ToList();

                    Files.Add(new TorrentFileFileEntry(fileSize, pathList));
                }
            }
            else
            {
                FileName = DefaultEncoding.GetString(info[FileNameKey] as byte[]);
                FileSize = (long) info[FileSizeKey];
            }

            HasComment = bareDictionary.ContainsKey(CommentKey);
            if (HasComment)
            {
                Comment = DefaultEncoding.GetString(bareDictionary[CommentKey] as byte[]);
            }

            HasCreatedBy = bareDictionary.ContainsKey(CreatedByKey);
            if (HasCreatedBy)
            {
                CreatedBy = DefaultEncoding.GetString(bareDictionary[CreatedByKey] as byte[]);
            }
        }