public bool IsValid(ContentArgs args)
        {
            if (args == null)
            {
                return(false);
            }

            if (!ContentTypes.IsValid(args.ContentType))
            {
                return(false);
            }

            if (!IsValidJson(args.Json))
            {
                return(false);
            }

            return(true);
        }
        public async Task ExecuteAsync(ContentArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            var contentBytes = Encoding.UTF8.GetBytes(args.Json);

            var e = new ContentEntity
            {
                Created      = _dateTimeProvider.Snapshot,
                Release      = args.Release,
                Type         = args.ContentType,
                PublishingId = _publishingIdService.Create(contentBytes),
                Content      = await _signedFormatter.SignedContentPacketAsync(contentBytes)
            };

            await _dbContext.Content.AddAsync(e);
        }
Exemple #3
0
        public async Task ExecuteAsync(string[] args)
        {
            if (args.Length < 2)
            {
                throw new ArgumentException("Not enough args.");
            }

            var contentArgs = new ContentArgs
            {
                Release     = _DateTimeProvider.Snapshot,
                ContentType = ParseContentType(args[0]),
                Json        = File.ReadAllText(args[1])
            };

            if (!_Validator.IsValid(contentArgs))
            {
                throw new InvalidOperationException("Content not valid.");
            }

            _Logger.WriteStartWriting(contentArgs.ContentType);

            if (contentArgs.ContentType == ContentTypes.ResourceBundleV3) //needs direct signing with ev-cert
            {
                _ContentDbContext.BeginTransaction();
                await _InsertDbCommandV3().ExecuteAsync(contentArgs);

                _ContentDbContext.SaveAndCommit();
            }
            else
            {
                _ContentDbContext.BeginTransaction();
                await _InsertDbCommand.ExecuteAsync(contentArgs);

                _ContentDbContext.SaveAndCommit();
            }

            _Logger.WriteFinishedWriting(contentArgs.ContentType);
        }