private AdRec[] SetAdRecs(ArrayList adDicts) { if ((adDicts == null) || (adDicts.Count == 0)) { return(null); } AdRec[] recArray = new AdRec[adDicts.Count]; int index = 0; for (int i = 0; i < adDicts.Count; i++) { if (adDicts[i] != null) { recArray[index].Initialize((IDictionary)adDicts[i]); index++; } } return(recArray); }
private AdRec [] SetAdRecs(ArrayList adDicts) { if (adDicts == null || adDicts.Count == 0) { return(null); } // Create an array of AdRec structures from the dictionaries, removing blanks AdRec [] adRecs = new AdRec[adDicts.Count]; int iRec = 0; for (int i = 0; i < adDicts.Count; i++) { if (adDicts[i] != null) { adRecs[iRec].Initialize((IDictionary)adDicts[i]); iRec++; } } Debug.Assert(iRec == adDicts.Count, "Record count did not match non-null entries"); return(adRecs); }
private bool MatchingAd(AdRec adRec, string keywordFilter) { return(string.Equals(keywordFilter, adRec.keyword, StringComparison.OrdinalIgnoreCase)); }
/// <devdoc> /// Used to determine if the advertisement meets current criteria. Does a comparison with /// KeywordFilter if it is set. /// </devdoc> private bool MatchingAd(AdRec adRec, string keywordFilter) { Debug.Assert(keywordFilter != null && keywordFilter.Length > 0); return(String.Equals(keywordFilter, adRec.keyword, StringComparison.OrdinalIgnoreCase)); }
/// <include file='doc\AdRotator.uex' path='docs/doc[@for="AdRotator.MatchingAd"]/*' /> /// <devdoc> /// Used to determine if the advertisement meets current criteria. Does a comparison with /// KeywordFilter if it is set. /// </devdoc> private bool MatchingAd(AdRec ad) { // do a lower case comparison return(KeywordFilter == string.Empty || (KeywordFilter.ToLower(CultureInfo.InvariantCulture) == ad.keyword.ToLower(CultureInfo.InvariantCulture))); }
/// <include file='doc\AdRotator.uex' path='docs/doc[@for="AdRotator.LoadFile"]/*' /> /// <devdoc> /// Loads the give XML file into an array of AdRec structures /// </devdoc> private AdRec [] LoadFile(string fileName) { Stream stream = null; AdRec [] adRecs = null; try { stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); } catch (Exception e) { // We want to catch the error message, but not propage the inner exception. Otherwise we can throw up // logon prompts through IE; throw new HttpException(HttpRuntime.FormatResourceString(SR.AdRotator_cant_open_file, ID, e.Message)); } try { // Read the XML file into an array of dictionaries ArrayList adDicts = new ArrayList(); XmlReader reader = new XmlTextReader(stream); XmlDocument doc = new XmlDocument(); doc.Load(reader); if (doc.DocumentElement != null && doc.DocumentElement.LocalName == XmlDocumentTag) { XmlNode elem = doc.DocumentElement.FirstChild; while (elem != null) { IDictionary dict = null; if (elem.LocalName.Equals(XmlAdTag)) { XmlNode prop = elem.FirstChild; while (prop != null) { if (prop.NodeType == XmlNodeType.Element) { if (dict == null) { dict = new HybridDictionary(); } dict.Add(prop.LocalName, prop.InnerText); } prop = prop.NextSibling; } } if (dict != null) { adDicts.Add(dict); } elem = elem.NextSibling; } } if (adDicts.Count != 0) { // Create an array of AdRec structures from the dictionaries, removing blanks adRecs = new AdRec[adDicts.Count]; int iRec = 0; for (int i = 0; i < adDicts.Count; i++) { if (adDicts[i] != null) { adRecs[iRec].Initialize((IDictionary)adDicts[i]); iRec++; } } Diagnostics.Debug.Assert(iRec == adDicts.Count, "Record count did not match non-null entries"); } } catch (Exception e) { throw new HttpException( HttpRuntime.FormatResourceString(SR.AdRotator_parse_error, ID, e.Message), e); } finally { if (stream != null) { stream.Close(); } } if (adRecs == null) { throw new HttpException( HttpRuntime.FormatResourceString(SR.AdRotator_no_advertisements, ID, AdvertisementFile)); } return(adRecs); }
private AdRec[] SetAdRecs(ArrayList adDicts) { if ((adDicts == null) || (adDicts.Count == 0)) { return null; } AdRec[] recArray = new AdRec[adDicts.Count]; int index = 0; for (int i = 0; i < adDicts.Count; i++) { if (adDicts[i] != null) { recArray[index].Initialize((IDictionary) adDicts[i]); index++; } } return recArray; }
private bool MatchingAd(AdRec adRec, string keywordFilter) { return string.Equals(keywordFilter, adRec.keyword, StringComparison.OrdinalIgnoreCase); }
private AdRec [] SetAdRecs(ArrayList adDicts) { if (adDicts == null || adDicts.Count == 0) { return null; } // Create an array of AdRec structures from the dictionaries, removing blanks AdRec [] adRecs = new AdRec[adDicts.Count]; int iRec = 0; for (int i = 0; i < adDicts.Count; i++) { if (adDicts[i] != null) { adRecs[iRec].Initialize((IDictionary) adDicts[i]); iRec++; } } Debug.Assert(iRec == adDicts.Count, "Record count did not match non-null entries"); return adRecs; }