示例#1
0
        public ExporterValidationResults Validate(ProductCatalogItem item)
        {
            var results = new ExporterValidationResults();

            // Check for missing IDs
            if (string.IsNullOrEmpty(item.id))
            {
                results.errors.Add("ID is required");
            }

            // A product ID must start with a lowercase letter or a number and must be composed
            // of only lowercase letters (a-z), numbers (0-9), underscores (_), and periods (.)
            string actualID = item.GetStoreID(GooglePlay.Name) ?? item.id;
            string field    = (actualID == item.GetStoreID(GooglePlay.Name)) ? "storeID." + GooglePlay.Name : "id";

            if (Char.IsNumber(actualID[0]) || (Char.IsLower(actualID[0]) && Char.IsLetter(actualID[0])))
            {
                foreach (char c in actualID)
                {
                    if (c != '_' && c != '.' && !Char.IsNumber(c) && !(Char.IsLetter(c) && Char.IsLower(c)))
                    {
                        results.fieldErrors[field] = "Product ID \"" + actualID + "\" must contain only lowercase letters, numbers, underscores, and periods";
                    }
                }
            }
            else
            {
                results.fieldErrors[field] = "Product ID \"" + actualID + "\" must start with a lowercase letter or a number";
            }

            ValidateDescription(item.defaultDescription, ref results, "defaultDescription");
            foreach (var desc in item.translatedDescriptions)
            {
                ValidateDescription(desc, ref results);
            }

            // Check for missing price information
            if (string.IsNullOrEmpty(item.pricingTemplateID) && item.googlePrice.value == 0)
            {
                results.fieldErrors["googlePrice"] = "Items must have either a price or a pricing template ID";
            }

            return(results);
        }