Exemplo n.º 1
0
        public ManifestEntity Execute()
        {
            _DbContext.BeginTransaction(); //TODO should be using WebDbContentProvider

            var now           = _DateTimeProvider.Now();
            var releaseCutoff = now - TimeSpan.FromHours(_GaenContentConfig.ManifestLifetimeHours);

            var e = _DbContext.ManifestContent
                    .Where(x => x.Release > releaseCutoff)
                    .OrderByDescending(x => x.Release)
                    .Take(1)
                    .SingleOrDefault();

            if (e != null)
            {
                return(e);
            }

            _DbContext.BulkDelete(_DbContext.Set <ManifestEntity>().ToList()); //TODO execute sql.
            var content = JsonConvert.SerializeObject(_ManifestBuilder.Execute());
            var bytes   = Encoding.UTF8.GetBytes(content);

            e = new ManifestEntity
            {
                Release         = now,
                ContentTypeName = ContentHeaderValues.Json,
                Content         = bytes,
            };
            e.PublishingId = _PublishingId.Create(e.Content);
            _DbContext.ManifestContent.Add(e);
            _DbContext.SaveAndCommit();

            return(e);
        }