Beispiel #1
0
        public async Task WriteAsync(Guid key, ContentState value, long oldVersion, long newVersion)
        {
            if (value.SchemaId.Id == Guid.Empty)
            {
                return;
            }

            var schema = await GetSchemaAsync(value.AppId.Id, value.SchemaId.Id);

            var idData = value.Data?.ToIdModel(schema.SchemaDef, true);

            var id = key.ToString();

            var document = SimpleMapper.Map(value, new MongoContentEntity
            {
                AppIdId       = value.AppId.Id,
                SchemaIdId    = value.SchemaId.Id,
                IsDeleted     = value.IsDeleted,
                DocumentId    = key.ToString(),
                DataText      = idData?.ToFullText(),
                DataByIds     = idData,
                ReferencedIds = idData?.ToReferencedIds(schema.SchemaDef),
            });

            document.Version = newVersion;
            if (document.Status == Core.Contents.Status.Published)
            {
                try
                {
                    await Collection.ReplaceOneAsync(x => x.DocumentId == id, document, Upsert);
                }
                catch (MongoWriteException ex)
                {
                    if (ex.WriteError.Category == ServerErrorCategory.DuplicateKey)
                    {
                        var existingVersion =
                            await Collection.Find(x => x.DocumentId == id).Only(x => x.DocumentId, x => x.Version)
                            .FirstOrDefaultAsync();

                        if (existingVersion != null)
                        {
                            throw new InconsistentStateException(existingVersion["vs"].AsInt64, oldVersion, ex);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            await LatestCollection.ReplaceOneAsync(x => x.DocumentId == document.DocumentId, document, Upsert);

            document.DocumentId = $"{key}_{newVersion}";

            await ArchiveCollection.ReplaceOneAsync(x => x.DocumentId == document.DocumentId, document, Upsert);
        }
        public async Task <IContentEntity> FindContentAsync(IAppEntity app, ISchemaEntity schema, Guid id, long version)
        {
            var contentEntity =
                await ArchiveCollection.Find(x => x.Id == id && x.Version >= version).SortBy(x => x.Version)
                .FirstOrDefaultAsync();

            contentEntity?.ParseData(schema.SchemaDef);

            return(contentEntity);
        }
Beispiel #3
0
        public ActionResult BlogArchives()
        {
            var model = new ArchiveCollection(GetPostsInternal());

            return(PartialView(model));
        }
        public ActionResult Archives()
        {
            var model = new ArchiveCollection(this.GetPosts());

            return(this.PartialView(model));
        }