Remove feed reading async code

Update to new binding expression code on options dialog
Update to .NET framework 4.5.1
This commit is contained in:
2014-07-11 20:40:47 -04:00
parent 6cdc334d53
commit 7e3eedd844
8 changed files with 63 additions and 83 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
@@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FeedCenter</RootNamespace>
<AssemblyName>FeedCenter</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
@@ -347,9 +347,9 @@
<None Include="Scripts\CreateDatabase.sqlce" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
<BootstrapperPackage Include=".NETFramework,Version=v4.5.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<ProductName>Microsoft .NET Framework 4.5.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">

View File

@@ -1,18 +1,13 @@
using System;
using System.Collections.Generic;
using Common.Debug;
using Common.Xml;
using FeedCenter.FeedParsers;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Common.Debug;
using Common.Extensions;
using Common.Xml;
using FeedCenter.Data;
using FeedCenter.FeedParsers;
using System.Threading.Tasks;
namespace FeedCenter
{
#region Enumerations
@@ -73,7 +68,7 @@ namespace FeedCenter
Tracer.WriteLine("Reading feed: {0}", Source);
Tracer.IncrementIndentLevel();
FeedReadResult result = ReadFeed(database, forceRead);
var result = ReadFeed(database, forceRead);
// Handle the result
switch (result)
@@ -92,7 +87,7 @@ namespace FeedCenter
}
// If the feed was successfully read and we have no last update timestamp - set the last update timestamp to now
if (result == FeedReadResult.Success && LastUpdated == FeedCenter.Data.Extensions.SqlDateTimeZero.Value)
if (result == FeedReadResult.Success && LastUpdated == Data.Extensions.SqlDateTimeZero.Value)
LastUpdated = DateTime.Now;
Tracer.DecrementIndentLevel();
@@ -101,25 +96,28 @@ namespace FeedCenter
return result;
}
private async Task<Tuple<FeedReadResult, string>> RetrieveFeed()
private Tuple<FeedReadResult, string> RetrieveFeed()
{
try
{
// Create the web request
WebRequest oRequest = WebRequest.Create(new Uri(Source));
var oRequest = WebRequest.Create(new Uri(Source));
// Attempt to cast to a web request
var webRequest = oRequest as HttpWebRequest;
// If this is an http request set some special properties
if (oRequest is HttpWebRequest)
if (webRequest != null)
{
// Cast the request
HttpWebRequest webRequest = (HttpWebRequest) oRequest;
// Make sure to use HTTP version 1.1
webRequest.ProtocolVersion = HttpVersion.Version11;
// Set that we'll accept compressed data
webRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
// Set a timeout
webRequest.Timeout = 10000;
// If we need to authenticate then set the credentials
if (Authenticate)
webRequest.Credentials = new NetworkCredential(Username, Password, Domain);
@@ -129,21 +127,17 @@ namespace FeedCenter
}
// Set the default encoding
Encoding encoding = Encoding.UTF8;
// Attempt to get the response
var response = (HttpWebResponse) await oRequest.GetResponseAsync().WithTimeout(10000).ConfigureAwait(false);
var encoding = Encoding.UTF8;
// If there was no response assume it was a timeout of the async method
if (response == null)
return Tuple.Create(FeedReadResult.Timeout, string.Empty);
// Attempt to get the response
var response = (HttpWebResponse) oRequest.GetResponse();
// If the response included an encoding then change the encoding
if (response.ContentEncoding.Length > 0)
encoding = Encoding.GetEncoding(response.ContentEncoding);
// Get the response stream
Stream responseStream = response.GetResponseStream();
var responseStream = response.GetResponseStream();
if (responseStream == null)
return Tuple.Create(FeedReadResult.NoResponse, string.Empty);
@@ -152,7 +146,7 @@ namespace FeedCenter
StreamReader textReader = new XmlSanitizingStream(responseStream, encoding);
// Get the feed text
string feedText = textReader.ReadToEnd();
var feedText = textReader.ReadToEnd();
// Get rid of any leading and trailing whitespace
feedText = feedText.Trim();
@@ -170,12 +164,12 @@ namespace FeedCenter
}
catch (WebException webException)
{
FeedReadResult result = FeedReadResult.UnknownError;
var result = FeedReadResult.UnknownError;
if (webException.Response is HttpWebResponse)
var errorResponse = webException.Response as HttpWebResponse;
if (errorResponse != null)
{
HttpWebResponse errorResponse = (HttpWebResponse) webException.Response;
switch (errorResponse.StatusCode)
{
case HttpStatusCode.InternalServerError:
@@ -224,8 +218,6 @@ namespace FeedCenter
{
try
{
string feedText;
// If not enabled then do nothing
if (!Enabled)
return FeedReadResult.NotEnabled;
@@ -234,7 +226,7 @@ namespace FeedCenter
if (!forceRead)
{
// Figure out how long since we last checked
TimeSpan timeSpan = DateTime.Now - LastChecked;
var timeSpan = DateTime.Now - LastChecked;
// Check if we are due to read the feed
if (timeSpan.TotalMinutes < CheckInterval)
@@ -247,19 +239,16 @@ namespace FeedCenter
// Read the feed text
var retrieveResult = RetrieveFeed();
// Wait on the result
retrieveResult.Wait();
// Get the information out of the async result
FeedReadResult result = retrieveResult.Result.Item1;
feedText = retrieveResult.Result.Item2;
var result = retrieveResult.Item1;
var feedText = retrieveResult.Item2;
// If we didn't successfully retrieve the feed then stop
if (result != FeedReadResult.Success)
return result;
// Create a new RSS parser
FeedParserBase feedParser = FeedParserBase.CreateFeedParser(this, feedText);
var feedParser = FeedParserBase.CreateFeedParser(this, feedText);
// Parse the feed
result = feedParser.ParseFeed(feedText);
@@ -269,14 +258,14 @@ namespace FeedCenter
return result;
// Create the removed items list - if an item wasn't seen during this check then remove it
List<FeedItem> removedItems = Items.Where(testItem => testItem.LastFound != LastChecked).ToList();
var removedItems = Items.Where(testItem => testItem.LastFound != LastChecked).ToList();
// If items were removed the feed was updated
if (removedItems.Count > 0)
LastUpdated = DateTime.Now;
// Loop over the items to be removed
foreach (FeedItem itemToRemove in removedItems)
foreach (var itemToRemove in removedItems)
{
// Delete the item from the database
database.FeedItems.DeleteObject(itemToRemove);
@@ -308,7 +297,7 @@ namespace FeedCenter
{
var sortedActions = from action in Actions orderby action.Sequence ascending select action;
foreach (FeedAction feedAction in sortedActions)
foreach (var feedAction in sortedActions)
{
switch (feedAction.Field)
{
@@ -329,10 +318,10 @@ namespace FeedCenter
var lastReadResult = (FeedReadResult) LastReadResult;
// Build the name of the resource using the enum name and the value
string resourceName = string.Format("{0}_{1}", typeof(FeedReadResult).Name, lastReadResult);
var resourceName = string.Format("{0}_{1}", typeof(FeedReadResult).Name, lastReadResult);
// Try to get the value from the resources
string resourceValue = Properties.Resources.ResourceManager.GetString(resourceName);
var resourceValue = Properties.Resources.ResourceManager.GetString(resourceName);
// Return the value or just the enum value if not found
return resourceValue ?? lastReadResult.ToString();

View File

@@ -1,11 +1,9 @@
using System.Collections.Generic;
using Common.Wpf.Extensions;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Common.Wpf.Extensions;
namespace FeedCenter.Options
{
public partial class CategoryWindow
@@ -33,25 +31,22 @@ namespace FeedCenter.Options
private void HandleOkayButtonClick(object sender, RoutedEventArgs e)
{
// Get a list of all explicit binding expressions
Dictionary<FrameworkElement, BindingExpression> bindingExpressionDictionary = this.GetExplicitBindingExpressions();
// Get the values as a list
List<BindingExpression> bindingExpressions = bindingExpressionDictionary.Values.ToList();
var bindingExpressions = this.GetBindingExpressions(new[] { UpdateSourceTrigger.Explicit });
// Loop over each binding expression and clear any existing error
bindingExpressions.ForEach(Validation.ClearInvalid);
bindingExpressions.ForEach(b => Validation.ClearInvalid(b.BindingExpression));
// Force all explicit bindings to update the source
bindingExpressions.ForEach(bindingExpression => bindingExpression.UpdateSource());
bindingExpressions.ForEach(bindingExpression => bindingExpression.BindingExpression.UpdateSource());
// See if there are any errors
bool hasError = bindingExpressions.Exists(bindingExpression => bindingExpression.HasError);
var hasError = bindingExpressions.Exists(bindingExpression => bindingExpression.BindingExpression.HasError);
// If there was an error then set focus to the bad controls
if (hasError)
{
// Get the first framework element with an error
FrameworkElement firstErrorElement = bindingExpressionDictionary.First(pair => pair.Value.HasError).Key;
var firstErrorElement = bindingExpressions.First(b => b.BindingExpression.HasError).FrameworkElement;
// Set focus
firstErrorElement.Focus();

View File

@@ -1,12 +1,10 @@
using System.Collections.Generic;
using Common.Wpf.Extensions;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using Common.Wpf.Extensions;
namespace FeedCenter.Options
{
public partial class FeedWindow
@@ -36,11 +34,8 @@ namespace FeedCenter.Options
private void HandleOkayButtonClick(object sender, RoutedEventArgs e)
{
// Get a dictionary of all framework elements and explicit binding expressions
Dictionary<FrameworkElement, BindingExpression> bindingExpressionDictionary = this.GetExplicitBindingExpressions();
// Get just the binding expressions
var bindingExpressions = bindingExpressionDictionary.Values;
// Get a list of all framework elements and explicit binding expressions
var bindingExpressions = this.GetBindingExpressions(new[] { UpdateSourceTrigger.Explicit });
// Loop over each binding expression and clear any existing error
this.ClearAllValidationErrors(bindingExpressions);
@@ -49,19 +44,19 @@ namespace FeedCenter.Options
this.UpdateAllSources(bindingExpressions);
// See if there are any errors
bool hasError = bindingExpressions.Any(b => b.HasError);
var hasError = bindingExpressions.Any(b => b.BindingExpression.HasError);
// If there was an error then set focus to the bad controls
if (hasError)
{
// Get the first framework element with an error
FrameworkElement firstErrorElement = bindingExpressionDictionary.First(pair => pair.Value.HasError).Key;
var firstErrorElement = bindingExpressions.First(b => b.BindingExpression.HasError).FrameworkElement;
// Loop over each tab item
foreach (TabItem tabItem in optionsTabControl.Items)
{
// Cast the content as visual
Visual content = (Visual) tabItem.Content;
var content = (Visual) tabItem.Content;
// See if the control with the error is a descendant
if (firstErrorElement.IsDescendantOf(content))

View File

@@ -1,7 +1,7 @@
using System.Windows.Controls;
using Common.Internet;
using Common.Internet;
using Common.Wpf.Extensions;
using System.Windows.Controls;
using System.Windows.Data;
namespace FeedCenter.Options
{
@@ -30,11 +30,12 @@ namespace FeedCenter.Options
{
var settings = Properties.Settings.Default;
string browser = (string) ((ComboBoxItem) browserComboBox.SelectedItem).Tag;
if (settings.Browser != browser)
settings.Browser = browser;
var browser = (string) ((ComboBoxItem) browserComboBox.SelectedItem).Tag;
this.UpdateAllSources();
settings.Browser = browser;
var expressions = this.GetBindingExpressions(new[] { UpdateSourceTrigger.Explicit });
this.UpdateAllSources(expressions);
}
public override string CategoryName
@@ -51,7 +52,7 @@ namespace FeedCenter.Options
var browsers = Browser.DetectInstalledBrowsers();
foreach (var browser in browsers)
{
ComboBoxItem item = new ComboBoxItem { Content = browser.Value.Name, Tag = browser.Key };
var item = new ComboBoxItem { Content = browser.Value.Name, Tag = browser.Key };
comboBox.Items.Add(item);

View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34003
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -431,7 +431,7 @@ namespace FeedCenter.Properties {
/// <summary>
/// Looks up a localized string similar to CREATE TABLE DatabaseVersion
///(
/// Value int NOT NULL DEFAULT &apos;&apos;,
/// Value int NOT NULL DEFAULT 0
///)
///GO
///

View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18213
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -12,7 +12,7 @@ namespace FeedCenter.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View File

@@ -80,7 +80,7 @@
</FeedCenter.Properties.Settings>
</applicationSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
<!--<system.data>
<DbProviderFactories>