Ejemplo n.º 1
0
 /// <summary>
 /// Adds a given warning to the list of warnings
 /// </summary>
 /// <param name="warning"></param>
 public void AddWarning(Warning warning)
 {
     warningList.Add(warning);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Detects warning messages for a given XML document based on some rules
        /// </summary>
        /// <param name="postalAddress"></param>
        /// <param name="result"></param>
        private void DetectWarnings(PostalAddress postalAddress, PostalAddressResult result)
        {
            var countryList = ConfigurationManager.AppSettings.Get("CountryList") ?? DefaultCountryList;
            var permittedCountries = countryList.Split(new[] { ',' });
            foreach (var address in postalAddress.PostalAddresses)
            {
                string tag = null;
                Warning warning = null;
                if (string.IsNullOrEmpty(address.City))
                {
                    tag = "<city/>";
                    warning = new Warning() { Message = string.Format("The {0} tag is empty", tag), Tag = tag };

                }
                else if(!permittedCountries.Contains(address.Country))
                {
                    tag = "<country/>";
                    warning = new Warning()
                    {
                        Message = string.Format("{0} isn't within permitted set of countries",
                        address.Country.Trim()),
                        Tag = tag
                    };
                }
                if (warning != null)
                {
                    result.AddWarning(warning);
                }
            }
        }