diff --git a/FeedCenter.csproj b/FeedCenter.csproj index b8a5462..e27b036 100644 --- a/FeedCenter.csproj +++ b/FeedCenter.csproj @@ -1,5 +1,5 @@  - + Debug x86 @@ -10,7 +10,7 @@ Properties FeedCenter FeedCenter - v4.5 + v4.5.1 512 @@ -347,9 +347,9 @@ - + False - Microsoft .NET Framework 4.5 %28x86 and x64%29 + Microsoft .NET Framework 4.5.1 %28x86 and x64%29 true diff --git a/Feeds/Feed.cs b/Feeds/Feed.cs index f1a19d7..c0f9cd7 100644 --- a/Feeds/Feed.cs +++ b/Feeds/Feed.cs @@ -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> RetrieveFeed() + private Tuple 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 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(); diff --git a/Options/CategoryWindow.xaml.cs b/Options/CategoryWindow.xaml.cs index 42c1690..318e080 100644 --- a/Options/CategoryWindow.xaml.cs +++ b/Options/CategoryWindow.xaml.cs @@ -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 bindingExpressionDictionary = this.GetExplicitBindingExpressions(); - - // Get the values as a list - List 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(); diff --git a/Options/FeedWindow.xaml.cs b/Options/FeedWindow.xaml.cs index 36f9f99..266904c 100644 --- a/Options/FeedWindow.xaml.cs +++ b/Options/FeedWindow.xaml.cs @@ -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 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)) diff --git a/Options/ReadingOptionsPanel.xaml.cs b/Options/ReadingOptionsPanel.xaml.cs index f530e02..680a707 100644 --- a/Options/ReadingOptionsPanel.xaml.cs +++ b/Options/ReadingOptionsPanel.xaml.cs @@ -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); diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 9ae64be..159093f 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // 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 { /// /// Looks up a localized string similar to CREATE TABLE DatabaseVersion ///( - /// Value int NOT NULL DEFAULT '', + /// Value int NOT NULL DEFAULT 0 ///) ///GO /// diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index a9e1ed8..884de74 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // 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()))); diff --git a/app.config b/app.config index 589a752..0f37a9b 100644 --- a/app.config +++ b/app.config @@ -80,7 +80,7 @@ - +