using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Web; namespace FLocal.Importer { public class ShallerGateway { public static string getUserInfoAsString(string userName) { return ShallerConnector.getPageContent("showprofile.php?User=" + userName + "&What=login&showlite=l", new Dictionary(), new System.Net.CookieContainer()); } private static Dictionary regexInfoCache = new Dictionary(); private static Regex getInfoRegexByCaption(string caption) { if(!regexInfoCache.ContainsKey(caption)) { lock(caption) { if(!regexInfoCache.ContainsKey(caption)) { regexInfoCache[caption] = new Regex("]*>\\s*" + caption + "\\s*\\s*\\s*([^<>]*)\\s*", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline); } } } return regexInfoCache[caption]; } private static Dictionary userImportStructure { get { return new Dictionary() { { "regDate", "Дата\\s+регистрации" }, { "signature", "Подпись" }, { "title", "Титул" }, { "location", "Расположение" }, { "biography", "Биография" }, }; } } public static Dictionary getUserInfo(string userName) { string content = getUserInfoAsString(userName); return userImportStructure.ToDictionary, string, string>( kvp => kvp.Key, kvp => HttpUtility.HtmlDecode(getInfoRegexByCaption(kvp.Value).Match(content).Groups[1].Value).Trim() ); } public static IEnumerable getUserNames(int pageNum) { string content = ShallerConnector.getPageContent("showmembers.php?Cat=&sb=13&page=" + pageNum + "&showlite=l", new Dictionary(), new System.Net.CookieContainer()); Regex matcher = new Regex(";User=([^&]+)&", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase); MatchCollection matches = matcher.Matches(content); HashSet result = new HashSet(); foreach(Match match in matches) { result.Add(match.Groups[1].Value); } return result; } } }