True, In the past I would have agreed, however one could argue that the
XML file is a "Database" of sorts, I was trying to avoid the overheads
of another (SQL) database in my site.
The simplicity of this solution was what interested me as I already have
a sophisitcated XML file handling utility class which has meant that I
only needed to add 4 lines of code to an overriden usercontrol to
impliment the majority of the functionality.
So thanks for the Sql Solution, but I'm still interested in finding out
the recomended safe way to update the XML file that may be in use by the
AdRotator for rendering or other instances also tring to update.
Regards
Mike Caddy
> Hi MC,
>
[quoted text clipped - 18 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
True, In the past I would have agreed, however one could argue that the
XML file is a "Database" of sorts, I was trying to avoid the overheads
of another (SQL) database in my site.
The simplicity of this solution was what interested me as I already have
a sophisitcated XML file handling utility class which has meant that I
only needed to add 4 lines of code to an overriden usercontrol to
impliment the majority of the functionality.
So thanks for the Sql Solution, but I'm still interested in finding out
the recomended safe way to update the XML file that may be in use by the
AdRotator for rendering or other instances also tring to update.
Regards
MC
> Hi MC,
>
[quoted text clipped - 18 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
MC - 03 Oct 2007 23:33 GMT
The code below is my current solution to creating a Tracked adRotator, I
hope you can agree that (along with two web.config lines) it is a very
compact solution. I have not included the XML Utility function as it
comes from a seperate library. It is this function that I think needs to
be modified?
Currently it loads the AdvertismentFile into a "XmlDocument" selects the
First node with the matching "ImageUrl" Attribute, Increments the
"DisplayCount" or "ClickCount" atribute (as Appropriate). and then saves
the document back to the file system.
There are two situations when this function fails. An Inability to load
the file because it is locked by another process and the same when saving.
Do I just have a loop with a try catch and loop until I can gain access
or time out?
Regards
MC
------------------ TrackedAdRotator.cs ------------------
using System;
using System.Web;
namespace mrc.AdRotator
{
public class TrackedAdRotator : System.Web.UI.WebControls.AdRotator
{
protected override void
OnAdCreated(System.Web.UI.WebControls.AdCreatedEventArgs e)
{
Utils.IncrementAdvertNumericAttribute(e.ImageUrl,
"ImageUrl", "DisplayCount", Page.Server.MapPath(AdvertisementFile));
if (e.NavigateUrl != "")
{
e.NavigateUrl =
string.Format("~/Adverts/AdvertHandler.ashx?Url={0}&AdvertismentFile={1}",
Page.Server.UrlEncode(e.NavigateUrl),
Page.Server.UrlEncode(AdvertisementFile));
}
base.OnAdCreated(e);
}
}
public class Redirector : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
Utils.IncrementAdvertNumericAttribute(context.Request["Url"],
"NavigateUrl", "ClickCount",
context.Server.MapPath(context.Request["AdvertismentFile"]));
context.Response.Redirect(context.Request["Url"]);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
> True, In the past I would have agreed, however one could argue that the
> XML file is a "Database" of sorts, I was trying to avoid the overheads
[quoted text clipped - 36 lines]
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
Walter Wang [MSFT] - 04 Oct 2007 00:26 GMT
Hi MC,
Even if we could update the xml file "database", there's a high chance that
we will encounter locking issues since multiple requests can take place at
the same time and they all need to write to the xml file. Note IO
operations are slow, therefore such locking and IO errors will occur very
frequently.
On the other hand, database is much better handling such concurrent
operations, especially if you're inserting two irrelevant new records
(instead of updating a single record); and database operations are much
faster than IO operations.
Hope this helps.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
MC - 04 Oct 2007 00:37 GMT
Ok, I agree, However the application is quite low traffic, I guess that
with time we will have more traffic and maybe the DB route is worth
doing now to save re-implimenting in the future, currently with the
simple "Try Catch Solution" there is about 2 IO errors a week.
Regards
MC
> Hi MC,
>
[quoted text clipped - 21 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.