public static string GetShowString(Torrent torrent) { string showString = ""; showString += "���ӵ�ַ:" + torrent.trackerUrl + "<br />"; showString += "������Ϣ:" + torrent.createdBy + "<br />"; foreach (TorrentIncludeFile includeFile in torrent.filesInfo) { showString += "�ļ��б�:" + includeFile.FileName + "<br />�ļ���С:" + includeFile.FileLenght.ToString() + "�ֽ�" + "<br />"; } return showString; }
public static Torrent Parse(string strFormat) { Torrent torrent = new Torrent(); try { string info = Regex.Match(strFormat, @"\d+(@.+?:[\d,]+)+sun").Value; MatchCollection mc = Regex.Matches(info, @"@(.*?):([\d,]+)"); string value = strFormat.Replace(info, ""); int start = 0; foreach (Match match in mc) { switch (match.Groups[1].Value) { case "trackerUrl": int lenght = int.Parse(match.Groups[2].Value); torrent.trackerUrl = value.Substring(start, lenght); start += lenght; break; case "createdBy": lenght = int.Parse(match.Groups[2].Value); torrent.createdBy = value.Substring(start, lenght); start += lenght; break; case "filesInfo": string[] lenghts = match.Groups[2].Value.Split(','); int lenght1 = int.Parse(lenghts[0]); int lenght2 = int.Parse(lenghts[1]); TorrentIncludeFile includeFile = new TorrentIncludeFile(); includeFile.FileName = value.Substring(start, lenght1); start += lenght1; includeFile.FileLenght = int.Parse(value.Substring(start, lenght2)); start += lenght2; torrent.filesInfo.Add(includeFile); break; } } } catch { return new Torrent(); } return torrent; }
static Torrent ConvertToEntity(string analyzerString) { Torrent torrent = new Torrent(); torrent.TrackerUrl = Regex.Match(analyzerString, "\"announce\"\"(.*?)\"").Groups[1].Value; torrent.CreateBy = Regex.Match(analyzerString, "\"created by\"\"(.*?)\"").Groups[1].Value; foreach (Match m in Regex.Matches(analyzerString, "\"length\"\"(.*?)\".*?\"path.utf-8\"[[{]*\"(.*?)\"")) { TorrentIncludeFile fileInfo = new TorrentIncludeFile(); fileInfo.FileLenght = Convert.ToInt32(m.Groups[1].Value); fileInfo.FileName = m.Groups[2].Value; torrent.FilesInfo.Add(fileInfo); } return torrent; }