2012-12-12 09:07:06 -01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Configuration
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class ClientDependencyConfiguration
|
|
|
|
|
|
{
|
2015-01-09 10:51:15 +11:00
|
|
|
|
private readonly ILogger _logger;
|
2012-12-12 09:07:06 -01:00
|
|
|
|
private readonly string _fileName;
|
|
|
|
|
|
|
2015-01-09 10:51:15 +11:00
|
|
|
|
public ClientDependencyConfiguration(ILogger logger)
|
2012-12-12 09:07:06 -01:00
|
|
|
|
{
|
2015-01-09 10:51:15 +11:00
|
|
|
|
if (logger == null) throw new ArgumentNullException("logger");
|
|
|
|
|
|
_logger = logger;
|
2012-12-12 09:07:06 -01:00
|
|
|
|
_fileName = IOHelper.MapPath(string.Format("{0}/ClientDependency.config", SystemDirectories.Config));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2014-02-22 14:47:59 +01:00
|
|
|
|
/// Changes the version number in ClientDependency.config to a random value to avoid stale caches
|
2012-12-12 09:07:06 -01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal bool IncreaseVersionNumber()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var clientDependencyConfigXml = XDocument.Load(_fileName, LoadOptions.PreserveWhitespace);
|
|
|
|
|
|
if (clientDependencyConfigXml.Root != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var versionAttribute = clientDependencyConfigXml.Root.Attribute("version");
|
|
|
|
|
|
|
2014-02-10 13:53:12 +11:00
|
|
|
|
//Set the new version to the hashcode of now
|
2014-02-10 14:29:29 +11:00
|
|
|
|
var oldVersion = versionAttribute.Value;
|
2014-02-19 16:57:33 +11:00
|
|
|
|
var newVersion = Math.Abs(DateTime.UtcNow.GetHashCode());
|
2012-12-12 09:07:06 -01:00
|
|
|
|
|
|
|
|
|
|
versionAttribute.SetValue(newVersion);
|
|
|
|
|
|
clientDependencyConfigXml.Save(_fileName, SaveOptions.DisableFormatting);
|
|
|
|
|
|
|
2015-01-09 10:51:15 +11:00
|
|
|
|
_logger.Info<ClientDependencyConfiguration>(string.Format("Updated version number from {0} to {1}", oldVersion, newVersion));
|
2012-12-12 09:07:06 -01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2015-01-09 10:51:15 +11:00
|
|
|
|
_logger.Error<ClientDependencyConfiguration>("Couldn't update ClientDependency version number", ex);
|
2012-12-12 09:07:06 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|