コード例 #1
0
        public async Task <CommandResult> Handle(SaveContentCollectionCommand command)
        {
            var result = new CommandResult();

            if (command.ContentCollection.ContentType != null)
            {
                command.ContentCollection.ContentType.AppId = command.AppId;
            }

            if (!await _validator.IsValid(command.ContentCollection))
            {
                result.AddValidationErrors(_validator.Errors);
            }
            else
            {
                if (!await _versioner.SetVersion(command.AppId, command.ContentCollection))
                {
                    result.SetVersionError();
                }
                else
                {
                    if (command.ContentCollection.Id == null)
                    {
                        await _contentStore.AddContentCollection(command.ContentCollection);
                    }
                    else
                    {
                        await _contentStore.UpdateContentCollection(command.ContentCollection);
                    }
                }
            }
            return(result);
        }
コード例 #2
0
        public async Task <CommandResult> Handle(SaveContentTypeCommand command)
        {
            var result = new CommandResult();

            if (!await _versioner.SetVersion(command.AppId, command.ContentType))
            {
                result.SetVersionError();
            }
            else
            {
                if (!await _validator.IsValid(command.ContentType))
                {
                    result.AddValidationErrors(_validator.Errors);
                }
                else
                {
                    if (command.ContentType.Id == null)
                    {
                        await _store.AddContentType(command.ContentType);
                    }
                    else
                    {
                        await _store.UpdateContentType(command.ContentType);

                        await _dispatcher.PublishEvent(new ContentTypeChangedEvent { ContentType = command.ContentType });
                    }
                }
            }
            return(result);
        }
コード例 #3
0
        public async Task <CommandResult> Handle(SaveContentItemCommand command)
        {
            var result = new CommandResult();

            ContentItem contentItem;

            if (command.Id == null)
            {
                contentItem = command.CreateContentItem(_currentUser);
            }
            else
            {
                contentItem = await _store.GetContentItem(command.Id, command.AppId);

                if (contentItem == null)
                {
                    result.SetNotFound();
                    return(result);
                }
                command.UpdateContentItem(contentItem, _currentUser);
            }

            if (!await _validator.IsValidForLanguages(contentItem, command.LanguagesToValidate))
            {
                result.AddValidationErrors(_validator.Errors);
            }
            else
            {
                if (!await _versioner.SetVersion(command.AppId, contentItem))
                {
                    result.SetVersionError();
                }
                else
                {
                    if (contentItem.Id == null)
                    {
                        await _store.AddContentItem(contentItem);
                    }
                    else
                    {
                        await _store.UpdateContentItem(contentItem);
                    }
                    result.SetResultData(contentItem);
                    await _dispatcher.PublishEvent(new ContentItemChangedEvent
                    {
                        AppId        = contentItem.AppId,
                        CollectionId = contentItem.CollectionId,
                        ContentKey   = contentItem.ContentKey,
                        Version      = contentItem.Version,
                        TimeStamp    = contentItem.LastModifiedAt ?? contentItem.CreatedAt.Value,
                        ModifiedBy   = contentItem.LastModifiedBy ?? contentItem.CreatedBy
                    });
                }
            }
            return(result);
        }
コード例 #4
0
        private bool Execute(Migration migration)
        {
            var type      = migration.Type;
            var version   = migration.Version;
            var dbVersion = _versioner.CurrentVersion(type);

            _logger.Info(string.Format("Database {0} version is : {1}", type, dbVersion));

            if (version <= dbVersion)
            {
                _logger.Warn(string.Format("{0} migration version {1} is less than database version", type, version));
                return(true);
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            _logger.Info("Executing migration to version " + version);
            try
            {
                migration.Execute(_conn);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Failed to execute {0} migration to version {1}", type, version), ex);
                return(false);
            }

            sw.Stop();
            _logger.Info(string.Format("migration to version {0} took {1} seconds.", version, sw.Elapsed.TotalSeconds));

            if (!_versioner.SetVersion(migration))
            {
                _logger.Error("Failed to update database version. Leaving...");
                return(false);
            }

            return(true);
        }