Removed async update check due to threading issue

This commit is contained in:
Ben 2015-07-31 22:13:58 +01:00
parent 94146467a3
commit 4185c3dbde
4 changed files with 13 additions and 16 deletions

View File

@ -8,13 +8,13 @@ namespace Filtration.Tests.Services
public class TestHTTPService public class TestHTTPService
{ {
[Test] [Test]
public async void GetContent_FetchesDataFromUrl() public void GetContent_FetchesDataFromUrl()
{ {
// Arrange // Arrange
var service = new HTTPService(); var service = new HTTPService();
// Act // Act
var result = await service.GetContentAsync("http://ben-wallis.github.io/Filtration/filtration_version.xml"); var result = service.GetContent("http://ben-wallis.github.io/Filtration/filtration_version.xml");
// Assert // Assert
Assert.IsNotNull(result); Assert.IsNotNull(result);

View File

@ -1,24 +1,23 @@
using System; using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Threading.Tasks;
namespace Filtration.Services namespace Filtration.Services
{ {
internal interface IHTTPService internal interface IHTTPService
{ {
Task<string> GetContentAsync(string url); string GetContent(string url);
} }
internal class HTTPService : IHTTPService internal class HTTPService : IHTTPService
{ {
public async Task<string> GetContentAsync(string url) public string GetContent(string url)
{ {
var urlUri = new Uri(url); var urlUri = new Uri(url);
var request = WebRequest.Create(urlUri); var request = WebRequest.Create(urlUri);
var response = await request.GetResponseAsync(); var response = request.GetResponse();
using (var s = response.GetResponseStream()) using (var s = response.GetResponseStream())
{ {
using (var sr = new StreamReader(s)) using (var sr = new StreamReader(s))

View File

@ -1,5 +1,4 @@
using System.IO; using System.IO;
using System.Threading.Tasks;
using System.Xml.Serialization; using System.Xml.Serialization;
using Filtration.Models; using Filtration.Models;
@ -7,7 +6,7 @@ namespace Filtration.Services
{ {
internal interface IUpdateCheckService internal interface IUpdateCheckService
{ {
Task<UpdateData> GetUpdateDataAsync(); UpdateData GetUpdateData();
} }
internal class UpdateCheckService : IUpdateCheckService internal class UpdateCheckService : IUpdateCheckService
@ -20,9 +19,9 @@ namespace Filtration.Services
_httpService = httpService; _httpService = httpService;
} }
public async Task<UpdateData> GetUpdateDataAsync() public UpdateData GetUpdateData()
{ {
var updateXml = await _httpService.GetContentAsync(UpdateDataUrl); var updateXml = _httpService.GetContent(UpdateDataUrl);
return (DeserializeUpdateData(updateXml)); return (DeserializeUpdateData(updateXml));
} }

View File

@ -4,12 +4,14 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Forms.VisualStyles; using System.Windows.Forms.VisualStyles;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Filtration.Common.Services; using Filtration.Common.Services;
using Filtration.Common.ViewModels; using Filtration.Common.ViewModels;
using Filtration.Interface; using Filtration.Interface;
@ -191,10 +193,7 @@ namespace Filtration.ViewModels
} }
}); });
Task.Run(async () => CheckForUpdates();
{
await CheckForUpdatesAsync();
}).Wait();
} }
public RelayCommand OpenScriptCommand { get; private set; } public RelayCommand OpenScriptCommand { get; private set; }
@ -238,13 +237,13 @@ namespace Filtration.ViewModels
public RelayCommand ClearFiltersCommand { get; private set; } public RelayCommand ClearFiltersCommand { get; private set; }
public async Task CheckForUpdatesAsync() public void CheckForUpdates()
{ {
var assemblyVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location); var assemblyVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
try try
{ {
var result = await _updateCheckService.GetUpdateDataAsync(); var result = _updateCheckService.GetUpdateData();
if (result.LatestVersionMajorPart >= assemblyVersion.FileMajorPart && if (result.LatestVersionMajorPart >= assemblyVersion.FileMajorPart &&
result.LatestVersionMinorPart > assemblyVersion.FileMinorPart) result.LatestVersionMinorPart > assemblyVersion.FileMinorPart)