private void GenerateProperties(UmbracoDbContext context, int[] definitionIds,
                                        IEnumerable <UCommerceProductCatalog> catalogs,
                                        string[] languageCodes)
        {
            Console.Write($"Generating properties for {Count:N0} catalogs...");
            using (var p = new ProgressBar())
            {
                var  mediaIds         = _cmsContent.GetAllMediaIds(context);
                var  contentIds       = _cmsContent.GetAllContentIds(context);
                var  definitionFields = LookupDefinitionFields(context, definitionIds);
                uint batchSize        = 100_000;
                uint numberOfBatches  = definitionFields.Any()
                    ? (uint)Math.Ceiling(
                    1.0 * batchSize / definitionFields.Average(x => x.Count()) / catalogs.Count())
                    : 1;

                var propertiyBatches = catalogs
                                       .Where(catalog => catalog.DefinitionId.HasValue)
                                       // ReSharper disable once PossibleInvalidOperationException
                                       .SelectMany(category => definitionFields[category.DefinitionId.Value].SelectMany(field =>
                                                                                                                        AddEntityProperty(category.Guid, field.Field, languageCodes, mediaIds,
                                                                                                                                          contentIds, field.Editor, field.Enums)))
                                       .Batch(batchSize);

                propertiyBatches.EachWithIndex((properties, index) =>
                {
                    context.BulkInsert(properties.ToList(), options => options.SetOutputIdentity = false);
                    p.Report(1.0 * index / numberOfBatches);
                });
            }
        }
        private void GenerateProperties(DataContext context, int[] definitionIds,
                                        IEnumerable <UCommerceProductCatalogGroup> stores)
        {
            Console.Write($"Generating properties for {Count:N0} stores. ");
            using (var p = new ProgressBar())
            {
                var mediaIds         = _cmsContent.GetAllMediaIds(context);
                var contentIds       = _cmsContent.GetAllContentIds(context);
                var languageCodes    = _cmsContent.GetLanguageIsoCodes(context);
                var definitionFields = LookupDefinitionFields(context, definitionIds);

                uint batchSize       = 100_000;
                uint numberOfBatches = definitionFields.Any()
                    ?  (uint)Math.Ceiling(1.0 * stores.Count() * (uint)definitionFields.Average(x => x.Count()) /
                                          batchSize)
                    : 1;

                var propertyBatches = stores
                                      .Where(store => store.DefinitionId.HasValue)
                                      .SelectMany(store => definitionFields[store.DefinitionId.Value].SelectMany(field =>
                                                                                                                 AddEntityProperty(store.Guid, field.Field, languageCodes, mediaIds,
                                                                                                                                   contentIds, field.Editor, field.Enums)))
                                      .Batch(batchSize);

                propertyBatches.EachWithIndex((properties, index) =>
                {
                    context.Ucommerce.BulkInsert(properties.ToList(), options => options.SetOutputIdentity = false);
                    p.Report(1.0 * index / numberOfBatches);
                });
            }
        }
        private void GenerateProperties(DataContext context, int[] definitionIds,
                                        IEnumerable <UCommerceCategory> categories,
                                        string[] languageCodes, string[] mediaIds)
        {
            var  definitionFields       = LookupDefinitionFields(context, definitionIds);
            uint estimatedPropertyCount = definitionFields.Any()
                ? (uint)definitionFields.Average(x => x.Count()) * (uint)categories.Count()
                : 1;
            uint batchSize       = 1_000_000;
            uint numberOfBatches = (uint)Math.Ceiling(1.0 * estimatedPropertyCount / batchSize);

            Console.Write(
                $"Generating ~{estimatedPropertyCount:N0} properties for {categories.Count():N0} categories. ");
            using (var p = new ProgressBar())
            {
                var contentIds = _cmsContent.GetAllContentIds(context);

                var propertyBatches = categories.SelectMany(category =>
                                                            definitionFields[category.DefinitionId].SelectMany(field =>
                                                                                                               AddCategoryProperty(category.CategoryId, field.Field, languageCodes,
                                                                                                                                   mediaIds, contentIds, field.Editor, field.Enums)))
                                      .Batch(batchSize);

                propertyBatches.EachWithIndex((properties, index) =>
                {
                    context.Ucommerce.BulkInsert(properties.ToList(), options => options.SetOutputIdentity = false);
                    p.Report(1.0 * index / numberOfBatches);
                });
            }
        }
        private void GenerateProperties(DataContext context, IEnumerable <UCommerceDataType> dataTypes,
                                        ILookup <int, DefinitionFieldEditorAndEnum> definitionFields)
        {
            Console.Write($"Generating properties for {Count:N0} data types.");
            using (var p = new ProgressBar())
            {
                var languageCodes = _cmsContent.GetLanguageIsoCodes(context);
                var mediaIds      = _cmsContent.GetAllMediaIds(context);
                var contentIds    = _cmsContent.GetAllContentIds(context);

                UCommerceEntityProperty[] properties = dataTypes
                                                       .Where(dataType => dataType.DefinitionId.HasValue)
                                                       .SelectMany(dataType => definitionFields[dataType.DefinitionId.Value].SelectMany(field =>
                                                                                                                                        AddEntityProperty(dataType.Guid, field.Field, languageCodes, mediaIds,
                                                                                                                                                          contentIds, field.Editor, field.Enums)))
                                                       .ToArray();

                p.Report(0.5);
                context.Ucommerce.BulkInsert(properties, options => options.SetOutputIdentity = false);
            }
        }