Example #1
0
        private void ValidateDescription(LocalizedProductDescription desc, ref ExporterValidationResults results, string fieldPrefix = null)
        {
            if (fieldPrefix == null)
            {
                fieldPrefix = "translatedDescriptions." + desc.googleLocale.ToString();
            }

            // Check for missing title
            if (string.IsNullOrEmpty(desc.Title))
            {
                results.fieldErrors[fieldPrefix + ".Title"] = "Title is required (" + desc.googleLocale.ToString() + ")";
            }
            else
            {
                if (desc.Title.Length > 55)                   // Titles can be up to 55 characters in length
                {
                    results.fieldErrors[fieldPrefix + ".Title"] = "Title must not be longer than 55 characters (" + desc.googleLocale.ToString() + ")";
                }
                else if (desc.Title.Length > 25)                     // Titles should be no longer than 25 characters
                {
                    results.warnings.Add("Title should not be longer than 25 characters (" + desc.googleLocale.ToString() + ")");
                }
            }

            // Check for missing description
            if (string.IsNullOrEmpty(desc.Description))
            {
                results.fieldErrors[fieldPrefix + ".Description"] = "Description is required (" + desc.googleLocale.ToString() + ")";
            }
            else
            {
                if (desc.Description.Length > 80)                   // Descriptions can be up to 80 characters in length
                {
                    results.fieldErrors[fieldPrefix + ".Description"] = "Description must not be longer than 80 characters (" + desc.googleLocale.ToString() + ")";
                }
            }
        }
        public string Export(ProductCatalog catalog)
        {
            // Get a list of all the locales that have a value for at least one
            // product, and are valid for Apple export. Order must be preserved
            // throughout this method, so this is converted to a list and then
            // wrapped in a ReadOnlyCollection to prevent mutation.
            var          localesToExport = new ReadOnlyCollection <TranslationLocale>(new List <TranslationLocale>(GetLocalesToExport(catalog)));
            XDeclaration declaration     = new XDeclaration("1.0", "utf-8", "yes");
            XDocument    document        = new XDocument();
            XNamespace   ns      = "http://apple.com/itunes/importer";
            XElement     package = new XElement(ns + "package",
                                                new XAttribute("version", "software5.7"));

            document.Add(package);
            package.Add(new XElement(ns + "provider", catalog.appleTeamID));
            package.Add(new XElement(ns + "team_id", catalog.appleTeamID));
            XElement software = new XElement(ns + "software");

            package.Add(software);
            software.Add(new XElement(ns + "vendor_id", catalog.appleSKU));
            XElement softwareMetadata = new XElement(ns + "software_metadata");

            software.Add(softwareMetadata);
            XElement inAppPurchases = new XElement(ns + "in_app_purchases");

            softwareMetadata.Add(inAppPurchases);

            foreach (var item in catalog.allProducts)
            {
                XElement inAppPurchase = new XElement(ns + "in_app_purchase",
                                                      new XElement(ns + "product_id", item.GetStoreID(AppleAppStore.Name) ?? item.id),
                                                      new XElement(ns + "reference_name", item.id),
                                                      new XElement(ns + "type", ProductTypeString(item)));
                XElement products = new XElement(ns + "products");
                inAppPurchase.Add(products);
                XElement product = new XElement(ns + "product",
                                                new XElement(ns + "cleared_for_sale", true),
                                                new XElement(ns + "wholesale_price_tier", item.applePriceTier));
                products.Add(product);

                XElement locales = new XElement(ns + "locales");
                inAppPurchase.Add(locales);
                // Variable number of localizations, not every product will specify a localization for every language
                // so some of the these descriptions may be missing, in which case we just skip it.
                foreach (var loc in localesToExport)
                {
                    LocalizedProductDescription desc = item.defaultDescription.googleLocale == loc ? item.defaultDescription : item.GetDescription(loc);
                    if (desc != null)
                    {
                        XElement locale = new XElement(ns + "locale",
                                                       new XAttribute("name", LocaleToAppleString(loc)),
                                                       new XElement(ns + "title", desc.Title),
                                                       new XElement(ns + "description", desc.Description));
                        locales.Add(locale);
                    }
                }

                XElement reviewScreenshot = new XElement(ns + "review_screenshot");
                inAppPurchase.Add(reviewScreenshot);
                reviewScreenshot.Add(new XElement(ns + "file_name", Path.GetFileName(item.screenshotPath)));
                FileInfo fileInfo = new FileInfo(item.screenshotPath);
                if (fileInfo.Exists)
                {
                    reviewScreenshot.Add(new XElement(ns + "size", fileInfo.Length));
                    reviewScreenshot.Add(new XElement(ns + "checksum", GetMD5Hash(fileInfo)));
                }

                inAppPurchases.Add(inAppPurchase);
            }
            // Split the declaration and the document because we want UTF-8, not UTF-16.
            return(declaration.ToString() + kNewLine + document.ToString());
        }