Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / operating-systems / Windows / Win8

AdRotator for Windows 8

0.00/5 (No votes)
23 Oct 2012CPOL6 min read 7.8K  
AdRotator for Windows 8

This article appears in the Third Party Products and Tools section. Articles in this section are for the members only and must not be used to promote or advertise products in any way, shape or form. Please report any spam or advertising.

*Note: By popular request, here’s a sample (pulled from the AdRotator site) showing AdRotator implemented in a Windows 8 app with AdDuplex, PubCenter and a local House AD.

As battles go, this was certainly one of the strangest. Windows 8 introduces so many different ways of working, some expected and welcome, some not so.

One of the biggest unexpected challenges is that libraries and packages can no longer distribute User Controls as part of a separate DLL or class library, if it’s another project in the same solution that’s fine, but if you want to distribute a control such as AdRotator, this presents a bit of a problem.

It’s not that you can’t, it’s just that Microsoft has packed up the goal posts and sold them to a foreign investor waving goodbye with a polite smile. There is a very good reason for this (in MS eyes), Security, by not allowing you to just expose anything and everything outside of a Class library or DLL, they ensure YOU don’t accidentally leave THEIR (aka your machine) system open to attack or dreaded buffer overrun, in short they are making you stand up and stand accounted for anything you develop and want to put on to other peoples machines, most (including me) do see this as a good move but it is a learning curve.

Ok, well you didn’t come here for a history / future lesson, you came here for our latest release AdRotator for Windows 8.

What’s Supported in the Windows 8 Version of AdRotator

Now these are early days of AdRotator for Windows 8 so bear with us as we get up to par with another platform, out of all the mainline features, here’s what we can currently support:

  • Ad Provider – AdDuplex
  • Ad Provider – MS Pubcenter
  • Ad Provider – Local House Ads
  • Ad Provider – Remote House Ads **New
  • Local Configuration file support (obviously, wouldn’t work without this)
  • Remote Configuration file support
  • All of the Caching and fall-back function for providing ads

What’s not working yet:

  • Sliding Ads are out – may not come back for Win 8, will have to see
  • Other Ad Providers, above were supporting those that have native controls but we will add others including Web API Providers
  • Remote House Ads – shouldn’t be long just need to sort out the Windows 8 equivalent Done

If you have a question / query or request, be sure to add them to the main discussion forum on codeplex

Getting Hold of AdRotator

Now in a change to our scheduled programming, you can no longer just download AdRotator (well for Windows 8 anyway), part of the security bits mentioned above mean there are only two methods for getting a redistributable library on to your Dev environment, a Visual Studio VSIX installer (extension to you and me) or NuGet, we opted for number 2.

So getting AdRotator actually becomes easier as does getting updates, for those who haven’t come across it before NuGet is a library delivery solution now built into Visual Studio 2012 (in 2010 you had to download and install a separate extension to enable it).

Just right click the “References” branch in Visual studio (with your project open!) and select “Manage NuGet packages”.

image

This will bring you up the NuGet Package viewer:

image

You’ll see a nice selection of libraries / components and add-ons for your project but you can look at them in your own time, I’m on the meter here.

So if you search for “AdRotator” in the top right hand search window, you’ll find our happy little project.

image

Note, not all of these libraries are for Windows 8, most are for .NET 4 and Studio 2010 so be sure you read the description before installing a lib, as you can see above searching for us shows one of our competitors the UAC, I’d recommend checking them out and seeing what they have to offer, we’d prefer you to use AdRotator of course, but as you can see, it’s for Windows Phone and that won’t work in a Windows 8 project (try it and see what I mean, no biggie you can always uninstall it again with no ill effects).

*Note

If you install a lib from NuGet, be sure to use NuGet to uninstall it, if you manually remove the reference manually it won’t break anything but it will get very confusing.

So if you select AdRotator and click “Install” and this will download the package, add a new reference to your solution and you’re done, that simple.

From here, it is pretty much exactly the same as the Silverlight version.

XML Configuration File

Now, we could have shipped a default configuration file with NuGet but we are also just learning the toolset plus I’ve had some odd experiences with file delivery in the past so we left it out for now.

Just create (or copy) a “defaultAdSettings.xml” config file into your project, the difference with Windows 8 is that you need to set the “CopyTo” action to “Copy Always” or “CopyNewer” to ensure it gets delivered with your project (no Resource build action anymore)

image

And in your XAML configuration below, we no longer need to mention namespaces, project folders or anything like that, just supply the name of the Config file you have added.

The format of the file hasn’t changed so either look on the AdRotator site or one of the previous blog posts about it like this one.

Ad Providers

Getting your Ad Providers in is just as easy, AdDuplex also has a NuGet Package, whereas Microsoft has a Windows 8 component which is already delivered as part of Windows 8, just right click References and select the “Extensions” branch and you will see it there. As this is still V1, you will have to add both references even when you are not using the external providers, in V2 this should no longer be necessary.

House Ads are exactly the same, just define a user control in your project and add your content as you see fit, then Assign it to the “DefaultHouseAdBody” property before you call “Invalidate”.

Be sure to define a local House ad if you have put it in to your configuration XML, not doing so will have unintended results.

Adding the Control to Your Page

As mentioned earlier, this part is exactly the same as the Silverlight version of the control, just add the following XAML with your own settings:

XML
<AdRotatorWin8:AdRotatorControl
	x:Name="AdRotatorWin8"
    AdHeight="90"
	AdWidth="728"
	DefaultSettingsFileUri="defaultAdSettings.xml"
	SettingsUrl="http://adrotator.apphb.com/defaultAdSettingsWindows8.xml"/>

Now the AdHeight and AdWidth settings are crucial in the Windows 8 version as there are only a few Ad Sizes are allowed for each of the native Ad Providers.

Such as:

  • Horizontal units
    • 300 x 250 Medium rectangle
    • 728 x 90 Leaderboard
    • 500 x 130 Split view banner
    • 292 x 60 Default snap view banner
    • 250 x 125 Half tile
  • Vertical units
    • 160 x 600 Wide skyscraper
  • Square units
    • 250 x 250 Square pop-up

Lastly, with all that setup, all that remains is to call the “Invalidate” function to kick off AdRotator displaying Ads, we leave this in your control so you don’t have to display Ads if you don’t want to (if a Trial has been converted to paid for example).

The recommended way to do this is to call “Invalidate” in the pages “Loaded” event, for example:

C#
public AdRotatorBlankPage()
{
	this.InitializeComponent();
	Loaded += AdRotatorBlankPage_Loaded;
}

void AdRotatorBlankPage_Loaded(object sender, RoutedEventArgs e)
{
	AdRotatorWin8.DefaultHouseAdBody = new MyDefaultAd();
	AdRotatorWin8.Invalidate();
}

So here, I have created a new method and bound it to the Loaded Event and then just called “Invalidate”, you could also bind to the event in XAML if you wish. It will work just as well.

So feel free to start using AdRotator for Windows 8, let us know your feedback while we work on completing its feature set and providers.

Later...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)