예제 #1
0
        public static void Clear(this ContentsModel model, string[] languages)
        {
            if (languages?.Length > 0 && model.Contents?.Count > 0)
            {
                var allowedLanguages = languages.ToHashSet();

                var toClear = new List <string>();

                foreach (var content in model.Contents)
                {
                    foreach (var field in content.Data.Values)
                    {
                        foreach (var language in field.Children <JProperty>().Select(x => x.Name))
                        {
                            if (language != "iv" && !allowedLanguages.Contains(language))
                            {
                                toClear.Add(language);
                            }
                        }

                        if (toClear.Count > 0)
                        {
                            foreach (var language in toClear)
                            {
                                field.Remove(language);
                            }

                            toClear.Clear();
                        }
                    }
                }
            }
        }
        public async Task GenerateSchemaAsync(DirectoryInfo directoryInfo, JsonHelper jsonHelper)
        {
            await jsonHelper.WriteJsonSchemaAsync <ContentsModel>(directoryInfo, "contents.json");

            var sample = new ContentsModel
            {
                Contents = new List <ContentModel>
                {
                    new ContentModel
                    {
                        Schema = "my-schema",
                        Filter = JObject.FromObject(new
                        {
                            Path  = "data.id.iv",
                            Op    = "eq",
                            Value = 1
                        }),
                        Data = new Dictionary <string, Dictionary <string, JToken> >
                        {
                            ["id"] = new Dictionary <string, JToken>
                            {
                                ["iv"] = 1
                            },
                            ["text"] = new Dictionary <string, JToken>
                            {
                                ["iv"] = "Hello Squidex"
                            }
                        }
                    }
                }
            };

            await jsonHelper.WriteWithSchema(directoryInfo, "contents/__contents.json", sample, "../__json/contents");
        }
예제 #3
0
        public async Task GenerateSchemaAsync(ISyncService sync)
        {
            await sync.WriteJsonSchemaAsync <ContentsModel>(new FilePath("contents.json"));

            var sample = new ContentsModel
            {
                Contents = new List <ContentModel>
                {
                    new ContentModel
                    {
                        Schema = "my-schema",
                        Data   = new DynamicData
                        {
                            ["id"] = new JObject
                            {
                                ["iv"] = 1
                            },
                            ["text"] = new JObject
                            {
                                ["iv"] = "Hello Squidex"
                            }
                        },
                        Status = "Published"
                    }
                }
            };

            await sync.WriteWithSchema(new FilePath("contents", "__contents.json"), sample, Ref);
        }
예제 #4
0
        public async Task GenerateSchemaAsync(DirectoryInfo directoryInfo, JsonHelper jsonHelper)
        {
            await jsonHelper.WriteJsonSchemaAsync <ContentsModel>(directoryInfo, "contents.json");

            var sample = new ContentsModel
            {
                Contents = new List <ContentModel>
                {
                    new ContentModel
                    {
                        Schema = "my-schema",
                        Data   = new DynamicData
                        {
                            ["id"] = new JObject
                            {
                                ["iv"] = 1
                            },
                            ["text"] = new JObject
                            {
                                ["iv"] = "Hello Squidex"
                            }
                        },
                        Status = "Published"
                    }
                }
            };

            await jsonHelper.WriteWithSchema(directoryInfo, "contents/__contents.json", sample, Ref);
        }
예제 #5
0
        public async Task ExportAsync(ISyncService sync, SyncOptions options, ISession session)
        {
            var schemas = await session.Schemas.GetSchemasAsync(session.App);

            var schemaMap = schemas.Items.ToDictionary(x => x.Id, x => x.Name);

            var context = QueryContext.Default.Unpublished().IgnoreFallback();

            foreach (var schema in schemas.Items)
            {
                var client = session.Contents(schema.Name);

                var contents     = new List <ContentModel>();
                var contentBatch = 0;

                Task SaveAsync()
                {
                    var model = new ContentsModel
                    {
                        Contents = contents
                    };

                    return(log.DoSafeAsync($"Exporting {schema.Name} ({contentBatch})", async() =>
                    {
                        await sync.WriteWithSchema(new FilePath("contents", schema.Name, $"{contentBatch}.json"), model, Ref);
                    }));
                }

                await client.GetAllAsync(async content =>
                {
                    content.MapComponents(schemaMap);

                    contents.Add(content.ToModel(schema.Name));

                    if (contents.Count > 50)
                    {
                        await SaveAsync();

                        contents.Clear();
                        contentBatch++;
                    }
                }, context : context);

                if (contents.Count > 0)
                {
                    await SaveAsync();
                }
            }
        }
예제 #6
0
        public async Task ExportAsync(DirectoryInfo directoryInfo, JsonHelper jsonHelper, SyncOptions options, ISession session)
        {
            var schemas = await session.Schemas.GetSchemasAsync(session.App);

            var context = QueryContext.Default.Unpublished().IgnoreFallback();

            foreach (var schema in schemas.Items)
            {
                var client = session.Contents(schema.Name);

                var contents     = new List <ContentModel>();
                var contentBatch = 0;

                Task SaveAsync()
                {
                    var model = new ContentsModel
                    {
                        Contents = contents
                    };

                    return(log.DoSafeAsync($"Exporting {schema.Name} ({contentBatch})", async() =>
                    {
                        await jsonHelper.WriteWithSchema(directoryInfo, $"contents/{schema.Name}{contentBatch}.json", model, Ref);
                    }));
                }

                await client.GetAllAsync(50, async content =>
                {
                    contents.Add(content.ToModel(schema.Name));

                    if (contents.Count > 50)
                    {
                        await SaveAsync();

                        contents.Clear();
                        contentBatch++;
                    }
                }, context);

                if (contents.Count > 0)
                {
                    await SaveAsync();
                }
            }
        }