private static LocationLangStore loadTags(string inTagFile) { LocationLangStore result = new LocationLangStore(); try { XmlSerializer serializer = new XmlSerializer(typeof(LocationLangStore)); /* If the XML document has been altered with unknown * nodes or attributes, handle them with the * UnknownNode and UnknownAttribute events.*/ serializer.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode); serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute); using (StreamReader fs = Eviroment.getR_fromAsset(inTagFile)) { // Declare an object variable of the type to be deserialized. /* Use the Deserialize method to restore the object's state with * data from the XML document. */ // Read the order date. result = (LocationLangStore)serializer.Deserialize(fs); } } catch (Exception ex) { log.Debug(ex.StackTrace); GlobalRuntimeMsgsInfoSrv.infoMsg("Error loading language TAGS, loaded defaulf tags"); log.Debug("Init result to empty location store"); result = new LocationLangStore(); } return(result); }
private MatchSiteResult searchFirstOcurrence(string inText, Site[] inSites) { log.Debug(">>"); MatchSiteResult result = new MatchSiteResult(); try { foreach (var site in inSites) { using (WebClient web = new WebClient()) { var fullUrl = string.Format(site.Url + "{0}", inText); var htmlSite = ""; // if there is poor signal, try again int webTryCounter = 3; while (webTryCounter > 0) { try { htmlSite = web.DownloadString(fullUrl); webTryCounter = 0; } catch (Exception ex) { log.Debug(ex.StackTrace); log.Debug("Poor signal, try again"); Macros.userMsg(Constants.WEAK_NETWORK_SIGNAL); webTryCounter--; htmlSite = ""; } } Macros.userMsg(Constants.SEARCHING_SITE, fullUrl); foreach (var pattern in site.ParternList) { if (pattern.SearchTextFound) { // search text found in result var regexSearchText = new Regex(@pattern.TextFoundPatter, RegexOptions.IgnoreCase); var matchesSearchText = regexSearchText.Matches(htmlSite); if (matchesSearchText.Count > 0) { var matches = matchesSearchText[0].Groups; if (matches.Count >= 2) { result.TextFound = Regex.Replace(matches[1].Value, pattern.TextFoundNormPatter, pattern.TextFoundNormReplace, RegexOptions.IgnoreCase); } } } var regexPr = new Regex(@pattern.RegularEx, RegexOptions.IgnoreCase); var matchesResult = regexPr.Matches(htmlSite); if (matchesResult.Count > 0) { result.Site = site; result.Pattern = pattern; result.Matches = matchesResult; result.IsMatch = true; return(result); } } } } } catch (Exception ex) { log.Debug(ex.StackTrace); log.Debug("Creating empty dictionary config"); string info = LocationLangSrv.getTagValue(Constants.WEB_DICT_FAIL) + ":" + ex.Message + Constants.BRLINE; GlobalRuntimeMsgsInfoSrv.infoMsg(info); Macros.userMsg(Constants.WEB_DICT_FAIL, ex.Message); result = new MatchSiteResult(); } log.Debug("<<"); return(result); }
public static void userMsg(string inTag, string inMsg) { GlobalRuntimeMsgsInfoSrv.infoMsg(LocationLangSrv.getTagValue(inTag) + ":" + inMsg + Constants.BRLINE); }