Filtration/Filtration/Services/UpdateCheckService.cs
2015-07-02 20:19:32 +01:00

45 lines
1.2 KiB
C#

using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Filtration.Models;
namespace Filtration.Services
{
internal interface IUpdateCheckService
{
Task<UpdateData> GetUpdateData();
}
internal class UpdateCheckService : IUpdateCheckService
{
private readonly IHTTPService _httpService;
private const string UpdateDataUrl = "http://ben-wallis.github.io/Filtration/filtration_version.xml";
public UpdateCheckService(IHTTPService httpService)
{
_httpService = httpService;
}
public async Task<UpdateData> GetUpdateData()
{
var updateXml = await _httpService.GetContentAsync(UpdateDataUrl);
return (DeserializeUpdateData(updateXml));
}
public UpdateData DeserializeUpdateData(string updateDataString)
{
var serializer = new XmlSerializer(typeof(UpdateData));
object result;
using (TextReader reader = new StringReader(updateDataString))
{
result = serializer.Deserialize(reader);
}
return result as UpdateData;
}
}
}