MobFox test Ads - XNA

Oct 19, 2013 at 11:11 AM
Hi!
Can you help me with run test Ads from MobFox? I have xml file with this content:
<?xml version="1.0" encoding="utf-8"?>
<AdSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <CultureDescriptors>
    <AdCultureDescriptor CultureName="en-US">
      <Probabilities Probability="50" AdType="MobFox" AppID="fe96717d9875b9da4339ea5367eff1ec" IsTest="true"/>
      <Probabilities Probability="10" AdType="PubCenter" AppID="78b9455f-db44-4de8-b0c3-1a91784790cd" SecondaryID="10029821" />
      <Probabilities Probability="10" AdType="AdDuplex" AppID="57435"/>
      <Probabilities AdType="DefaultHouseAd" AppID="http://xna-uk.net/AdRotator/XNAHouseAdImage.png"/>
    </AdCultureDescriptor>
    <AdCultureDescriptor CultureName="en-GB">
      <Probabilities Probability="5" AdType="MobFox" AppID="fe96717d9875b9da4339ea5367eff1ec" IsTest="true"/>
      <Probabilities Probability="40" AdType="PubCenter" AppID="78b9455f-db44-4de8-b0c3-1a91784790cd" SecondaryID="10029821" />
      <Probabilities Probability="10" AdType="AdDuplex" AppID="57435"/>
      <Probabilities AdType="DefaultHouseAd" AppID="http://xna-uk.net/AdRotator/XNAHouseAdImage.png"/>
    </AdCultureDescriptor>
    <AdCultureDescriptor CultureName="de-DE">
      <Probabilities Probability="40" AdType="MobFox" AppID="fe96717d9875b9da4339ea5367eff1ec" IsTest="true"/>
      <Probabilities Probability="5" AdType="PubCenter" AppID="78b9455f-db44-4de8-b0c3-1a91784790cd" SecondaryID="10029821" />
      <Probabilities Probability="5" AdType="AdDuplex" AppID="57435"/>
      <Probabilities AdType="DefaultHouseAd" AppID="http://xna-uk.net/AdRotator/XNAHouseAdImage.png"/>
    </AdCultureDescriptor>
    <AdCultureDescriptor CultureName="default">
      <Probabilities Probability="20" AdType="MobFox" AppID="fe96717d9875b9da4339ea5367eff1ec" IsTest="true"/>
      <Probabilities Probability="20" AdType="PubCenter" AppID="78b9455f-db44-4de8-b0c3-1a91784790cd" SecondaryID="10029821" />
      <Probabilities Probability="20" AdType="AdDuplex" AppID="57435"/>
      <Probabilities AdType="DefaultHouseAd" AppID="http://xna-uk.net/AdRotator/XNAHouseAdImage.png"/>
    </AdCultureDescriptor>
  </CultureDescriptors>
</AdSettings>
As you can see there is a MobFox test ID from Mobfox site but it is not working for me. I can see AdDuplex banner so i think everything is good with code. I am using AdRotator 0.5 for XNA and WP 7 emulator.

By the way AdRotator is a great tool!

Best Regards
Nov 8, 2013 at 5:42 PM
It works for me but I have made some workaround in AdWebRequest.ReadMobFoxResponse(...).
   List<AdWebResponse> AdWebResponse = (from item in xdoc.Descendants("request")
             select new AdWebResponse()
             {
                  URL = item.IfNullEmptyString("clickurl"),
                   ImageURL = string.IsNullOrEmpty(item.IfNullEmptyString("imageurl")) ? item.ifNullHTMLImageSource("htmlString") : item.IfNullEmptyString("imageurl")
              }).ToList();
At line with ImageURL is a bug, we get few html tags from there:
<htmlString>
- <![CDATA[ <body style="text-align:center;margin:0;padding:0;"><div align="center"><a href="http://account.mobfox.com/activation-info.php" target="_self"><img src="http://creative1cdn.mobfox.com/static/documents/testbanner/216x36.jpg" border="0"/></a></div></body>
  ]]> 
  </htmlString>
with CDATA flag so for XML parser it is empty line. I have made some changes and replace above code with:
foreach (var item in xdoc.Descendants("request"))
{
         response.ImageURL = item.IfNullEmptyString("htmlString");
         response.URL = item.IfNullEmptyString("clickurl");
}
xdoc = XDocument.Parse(response.ImageURL);
foreach (var item in xdoc.Descendants("img"))
{
        response.ImageURL = item.FirstAttribute.Value; 
}
where response is AdWebResponse response = new AdWebResponse()

or you can use another way:
 foreach (var item in xdoc.Descendants("request"))
 {
         response.ImageURL = item.IfNullEmptyString("htmlString");
         response.URL = item.IfNullEmptyString("clickurl");
 }
 StringReader stream = new StringReader(response.ImageURL);
  XmlReader reader = XmlReader.Create(stream);

   while (reader.Read())
    {
          switch (reader.NodeType)
          {
                  case XmlNodeType.Element: // The node is an element.
                   if (reader.Name.Equals("img"))
                    {
                            reader.MoveToAttribute(0);
                            response.ImageURL = reader.Value;
                    }
                     break;
           }
   }
Maybe not best code but works :)
Sep 30, 2014 at 12:17 PM
Edited Sep 30, 2014 at 12:18 PM
I was having exactly this problem. I solved it even simpler by editing the file:
AdRotator\AdRotatorSharedModel\Networking\NetworkExtensions.cs
where I just replaced the line in method ifNullHTMLImageSource(this XElement item, string key):
var ImgPos = HTMLText.IndexOf("<img id=");
with:
var ImgPos = HTMLText.IndexOf("<img src=");