Beispiel #1
0
        public async Task <IHttpActionResult> PostVast(CreativeVastCreateViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var brand = await _brandService.GetBrand(model.BrandUuid.GetValueOrDefault(Guid.Empty)).ConfigureAwait(false);

            if (brand == null)
            {
                return(BadRequest("The specified brand was not found."));
            }

            var vastXml = await _vastService.Download(model.VastUrl).ConfigureAwait(false);

            var vastValidationResult = await _vastService.Validate(vastXml).ConfigureAwait(false);

            if (!vastValidationResult.Success)
            {
                Logger.Warn($"vast content is invalid at {model.VastUrl} with error {vastValidationResult.Error} with content {vastXml}.");
                ModelState.AddModelError("VastUrl", $"VastUrl is invalid with error {vastValidationResult.Error}.");
                return(BadRequest(ModelState));
            }

            var creativeVastCreateOptions = _mapping.Map <CreativeVastCreateOptions>(model);

            creativeVastCreateOptions.VastXml = vastXml; // set vast xml
            try
            {
                var creative = await _creativeService.CreateCreative(creativeVastCreateOptions).ConfigureAwait(false);

                creative = await _creativeService.GetCreative(creative.CreativeUuid).ConfigureAwait(false); // reload

                var creativeViewModel = _mapping.Map <CreativeViewModel>(creative);
                return(CreatedAtRoute("Creatives.GetById", new { Id = creativeViewModel.CreativeUuid }, creativeViewModel));
            }
            catch (BrandscreenException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequest(ModelState));
            }
        }
Beispiel #2
0
        private async Task <Tuple <string, VAST> > Unwrap(string url, VAST vast)
        {
            var wrapperUrl = ((VASTADWrapper)vast.Ad[0].Item).VASTAdTagURI;
            var xml        = await _vastService.Download(wrapperUrl).ConfigureAwait(false);

            var vastValidationResult = await _vastService.Validate(xml).ConfigureAwait(false);

            if (!vastValidationResult.Success)
            {
                Logger.Warn($"{url} contains invalid wrapped vast content at {wrapperUrl} with error {vastValidationResult.Error} with content {xml}.");
                throw new BrandscreenException($"Wrapped vast content is invalid at {wrapperUrl} with error {vastValidationResult.Error}.");
            }
            vast = await Deserialize(xml).ConfigureAwait(false);

            return(new Tuple <string, VAST>(wrapperUrl, vast));
        }