diff --git a/NetTally/MainWindow.xaml b/NetTally/MainWindow.xaml
index e05ec2da..e9d7fc77 100644
--- a/NetTally/MainWindow.xaml
+++ b/NetTally/MainWindow.xaml
@@ -46,12 +46,12 @@
IsEnabled="{Binding ElementName=tallyButton, Path=IsEnabled, Converter={StaticResource BoolConverter}, ConverterParameter=Normal, Mode=OneWay}"/>
+ IsEnabled="{Binding ElementName=tallyButton, Path=IsEnabled, Converter={StaticResource BoolConverter}, ConverterParameter=Normal, Mode=OneWay}" Checked="partitionedVotes_CheckedChanged" Unchecked="partitionedVotes_CheckedChanged"/>
+ IsEnabled="{Binding IsChecked, ElementName=partitionedVotes}" Checked="partitionByLine_CheckedChanged" Unchecked="partitionByLine_CheckedChanged"/>
diff --git a/NetTally/MainWindow.xaml.cs b/NetTally/MainWindow.xaml.cs
index 40aab34e..7919067e 100644
--- a/NetTally/MainWindow.xaml.cs
+++ b/NetTally/MainWindow.xaml.cs
@@ -68,11 +68,12 @@ public MainWindow()
private void Window_Closing(object sender, CancelEventArgs e)
{
string selectedQuest = "";
- IQuest currentQuest = QuestCollectionView.CurrentItem as IQuest;
- if (currentQuest != null)
+
+ if (CurrentlySelectedQuest() != null)
{
- selectedQuest = currentQuest.ThreadName;
+ selectedQuest = CurrentlySelectedQuest().ThreadName;
}
+
QuestCollectionWrapper qcw = new QuestCollectionWrapper(questCollection, selectedQuest);
NetTallyConfig.Save(tally, qcw);
@@ -82,6 +83,11 @@ private void Window_Closing(object sender, CancelEventArgs e)
}
#endregion
+ private IQuest CurrentlySelectedQuest()
+ {
+ return QuestCollectionView.CurrentItem as IQuest;
+ }
+
#region User action events
///
/// Start running the tally on the currently selected quest and post range.
@@ -299,6 +305,27 @@ private void editQuestThread_KeyUp(object sender, KeyEventArgs e)
}
}
+
+ ///
+ /// If the option to partition votes is changed, retally the results.
+ ///
+ ///
+ ///
+ private void partitionedVotes_CheckedChanged(object sender, RoutedEventArgs e)
+ {
+ tally.TallyMethodChanged(CurrentlySelectedQuest());
+ }
+
+ ///
+ /// If the partition type is changed, retally the results.
+ ///
+ ///
+ ///
+ private void partitionByLine_CheckedChanged(object sender, RoutedEventArgs e)
+ {
+ tally.TallyMethodChanged(CurrentlySelectedQuest());
+ }
+
#endregion
diff --git a/TallyCore/Tally.cs b/TallyCore/Tally.cs
index d3d9bccc..93bbcd69 100644
--- a/TallyCore/Tally.cs
+++ b/TallyCore/Tally.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
@@ -6,6 +7,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
+using HtmlAgilityPack;
namespace NetTally
{
@@ -73,18 +75,10 @@ public bool UseSpoilerForVoters
set
{
useSpoilerForVoters = value;
- UpdateResults();
+ ChangeSpoilers();
}
}
-
- IQuest lastTallyQuest = null;
- private void UpdateResults()
- {
- if (lastTallyQuest != null)
- ConstructResults(lastTallyQuest);
- }
-
#endregion
#region Interface functions
@@ -100,21 +94,24 @@ public async Task Run(IQuest quest, CancellationToken token)
try
{
TallyResults = string.Empty;
+ lastTallyQuest = quest;
await quest.GetForumAdapter(token);
// Load pages from the website
- var pages = await pageProvider.LoadPages(quest, token).ConfigureAwait(false);
+ loadedPages = await pageProvider.LoadPages(quest, token).ConfigureAwait(false);
// Tally the votes from the loaded pages.
- voteCounter.TallyVotes(quest, pages);
+ voteCounter.TallyVotes(quest, loadedPages);
// Compose the final result string from the compiled votes.
ConstructResults(quest);
}
- catch (NotImplementedException)
+ catch (Exception)
{
+ lastTallyQuest = null;
+ loadedPages.Clear();
throw;
}
finally
@@ -140,8 +137,6 @@ public void ClearPageCache()
///
private void ConstructResults(IQuest quest)
{
- lastTallyQuest = quest;
-
StringBuilder sb = new StringBuilder();
var assembly = Assembly.GetExecutingAssembly();
@@ -199,5 +194,30 @@ private string GenerateSupporterUrl(IQuest quest, string supporter)
return sb.ToString();
}
#endregion
- }
+
+ #region Live Updates
+
+
+ IQuest lastTallyQuest = null;
+ List loadedPages = null;
+ private void ChangeSpoilers()
+ {
+ if (lastTallyQuest != null)
+ ConstructResults(lastTallyQuest);
+ }
+
+ public void TallyMethodChanged(IQuest changedQuest)
+ {
+ if (lastTallyQuest != null && changedQuest == lastTallyQuest)
+ {
+ if (loadedPages != null && loadedPages.Count > 0)
+ {
+ voteCounter.TallyVotes(lastTallyQuest, loadedPages);
+ ConstructResults(lastTallyQuest);
+ }
+ }
+ }
+ #endregion
+
+ }
}