//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary>Converts a complex adResponse object, into a collection of SimpleCreativeElements.</summary> /// <param name="simpleAdresponse">A complex adResponse</param> /// <returns>A collection of SimpleCreativeElements</returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public static SimpleAdResponse SimplifyAdResponse(Bluevia.Advertising.Schemas.SimpleAdResponseType simpleAdresponse) { //CAN BE IMPROVED //This function could be implemented with a for loop, to save the List instantiation List<CreativeElement> response = new List<CreativeElement>(); foreach (CreativeElementType cet in simpleAdresponse.ad.resource.creative_element) { CreativeElement sce = new CreativeElement(); sce.type = (TypeId)Enum.Parse(typeof(TypeId), cet.type); //Searching for the advertise attribute foreach (AttributeType attribute in cet.attribute) { if (("text".Equals(cet.type.ToLower()) && attribute.type.ToLower().Equals("adtext")) || ("image".Equals(cet.type.ToLower()) && attribute.type.ToLower().Equals("locator"))) { sce.value = attribute.Value; break; } } sce.interaction = cet.interaction[0].attribute[0].Value; response.Add(sce); } return new SimpleAdResponse(simpleAdresponse.id, response.ToArray()); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary>Initializes a new instance of the <see cref="SimpleAdResponse"/></summary> /// <param name="Id">The id of the relative request sent.</param> /// <param name="elements">The Advertisings retrieved info.</param> //////////////////////////////////////////////////////////////////////////////////////////////////// public SimpleAdResponse(string Id, CreativeElement[] elements) { RequestId = Id; AdvertisingList = elements; }