public static CommodInfo Deserialize(TextReader reader) { if (reader == null) { return(null); } XmlSerializer serializer = new XmlSerializer(typeof(CommodInfo)); CommodInfo info = new CommodInfo(); info = (CommodInfo)serializer.Deserialize(reader); info.commodMapsDict.Clear(); foreach (CommodMap c in info.CommodMaps) { if (!info.commodMapsDict.ContainsKey(c.Name)) { info.commodMapsDict.Add(c.Name, c); } } reader.Close(); return(info); }
public static CommodInfo Deserialize(string file) { Console.WriteLine(Directory.GetCurrentDirectory()); if (File.Exists(file) == false) { return(null); } TextReader reader = new StreamReader(file); CommodInfo info = Deserialize(reader); return(info); }
private void UpdateCommodNameToIndexMap(UploadServer server) { bool useLocalCommodMapFile = Convert.ToBoolean(ConfigurationSettings.AppSettings["UseLocalCommodMapFile"]); if (useLocalCommodMapFile) { commodInfo = CommodInfo.Deserialize("CommodInfo.xml"); return; } string url = server.HomeUrl + "/commodmap.php"; HttpWebRequest web = (HttpWebRequest)WebRequest.Create(url); web.KeepAlive = true; web.Credentials = System.Net.CredentialCache.DefaultCredentials; WebResponse webResponse = web.GetResponse(); Stream stream2 = webResponse.GetResponseStream(); StreamReader reader = new StreamReader(stream2); string findStart; while (!reader.EndOfStream) { findStart = reader.ReadLine(); if (findStart.Contains("<pre>")) { break; } } //string text = HttpUtility.HtmlDecode(reader.ReadToEnd()); string text = reader.ReadToEnd(); // text = text.Replace("<", "<"); // text = text.Replace(">", ">"); // text = text.Replace("< ", "<"); // text = text.Replace("> ", ">"); text = HttpUtility.HtmlDecode(text).Trim(); int index = text.IndexOf("</body>"); if (index >= 0) { text = text.Remove(index); } index = text.IndexOf("</pre>"); if (index >= 0) { text = text.Remove(index); } commodInfo = CommodInfo.Deserialize(new StringReader(text)); reader.Close(); }