Permalink
Browse files

Extract Updateversion code from MainWindow

  • Loading branch information...
1 parent ff547aa commit feee9b30587e63814c9ac30928d02ffd4554d0a1 @ejsmile committed Mar 7, 2012
Showing with 61 additions and 49 deletions.
  1. +45 −0 Client/CheckUpdate.cs
  2. +1 −0 Client/Client.csproj
  3. +15 −49 Client/MainWindow.xaml.cs
View
@@ -0,0 +1,45 @@
+using System;
+using System.Threading;
+using System.Xml;
+using ToDoLib;
+using System.Windows;
+
+namespace Client
+{
+ class CheckUpdate
+ {
+ public const string updateXMLUrl = @"https://raw.github.com/benrhughes/todotxt.net/master/Updates.xml";
+ public const string updateClientUrl = @"https://github.com/benrhughes/todotxt.net/downloads";
+
+ public delegate void CheckUpdateVershion(string version);
+ public event CheckUpdateVershion OnCheckedUpdateVershion;
+
+ private XmlDocument xDoc;
+
+ public CheckUpdate()
+ {
+ xDoc = new XmlDocument();
+ }
+
+ public void Check()
+ {
+ ThreadPool.QueueUserWorkItem(x => CheckForUpdates());
+ }
+
+ private void CheckForUpdates()
+ {
+ try
+ {
+ xDoc.Load(new XmlTextReader(updateXMLUrl));
+
+ var version = xDoc.SelectSingleNode("//version").InnerText;
+ var changelog = xDoc.SelectSingleNode("//changelog").InnerText;
+ OnCheckedUpdateVershion(version);
+ }
+ catch (Exception ex)
+ {
+ Log.Error("Error checking for updates", ex);
+ }
+ }
+ }
+}
View
@@ -78,6 +78,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
+ <Compile Include="CheckUpdate.cs" />
<Compile Include="FilterDialog.xaml.cs">
<DependentUpon>FilterDialog.xaml</DependentUpon>
</Compile>
View
@@ -56,6 +56,7 @@ enum SortType
TrayMainWindows _tray;
HotKeyMainWindows _hotkey;
ObserverChangeFile _changefile;
+ CheckUpdate _checkupdate;
WindowLocation _previousWindowLocaiton;
@@ -75,6 +76,11 @@ public MainWindow()
_changefile = new ObserverChangeFile();
_changefile.OnFileTaskListChange += () => Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { this.Refresh(); }));
+ //CheckUpdate new version
+ _checkupdate = new CheckUpdate();
+ _checkupdate.OnCheckedUpdateVershion += (string version) => Dispatcher.BeginInvoke(new CheckUpdate.CheckUpdateVershion(this.ShowUpdateMenu), version);
+ _checkupdate.Check();
+
webBrowser1.Navigate("about:blank");
// migrate the user settings from the previous version, if necessary
@@ -103,29 +109,12 @@ public MainWindow()
Log.Error(msg, ex);
MessageBox.Show(ex.Message, msg, MessageBoxButton.OK);
}
-
- ThreadPool.QueueUserWorkItem(x => CheckForUpdates());
+
}
#region private methods
- private void HideUnHideWindow()
- {
- if (this.WindowState == WindowState.Minimized)
- {
- this.Show();
- this.Topmost = true;
- this.Activate();
- this.WindowState = WindowState.Normal;
- }
- else
- {
- this.WindowState = WindowState.Minimized;
- this.Hide();
- }
- }
-
- private void Reload()
+ private void Reload()
{
try
{
@@ -417,37 +406,14 @@ private void FilterAndSort(SortType sort)
}
}
- private void CheckForUpdates()
- {
- const string updateXMLUrl = @"https://raw.github.com/benrhughes/todotxt.net/master/Updates.xml";
-
- var xDoc = new XmlDocument();
-
- try
- {
- xDoc.Load(new XmlTextReader(updateXMLUrl));
-
- var version = xDoc.SelectSingleNode("//version").InnerText;
- var changelog = xDoc.SelectSingleNode("//changelog").InnerText;
-
- var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
-
- if (version != assemblyVersion)
- {
- Dispatcher.Invoke(new Action<string>(ShowUpdateMenu), version);
- }
- }
- catch (Exception ex)
- {
- Log.Error("Error checking for updates", ex);
- }
-
- }
-
private void ShowUpdateMenu(string version)
{
- this.UpdateMenu.Header = "New version: " + version;
- this.UpdateMenu.Visibility = Visibility.Visible;
+ var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
+ if (version != assemblyVersion)
+ {
+ this.UpdateMenu.Header = "New version: " + version;
+ this.UpdateMenu.Visibility = Visibility.Visible;
+ }
}
#endregion
@@ -749,7 +715,7 @@ private void Sort_Alphabetical(object sender, RoutedEventArgs e)
#region Update notification
private void Get_Update(object sender, RoutedEventArgs e)
{
- Process.Start("https://github.com/benrhughes/todotxt.net/downloads");
+ Process.Start(CheckUpdate.updateClientUrl);
}
#endregion

0 comments on commit feee9b3

Please sign in to comment.