Skip to content

Commit

Permalink
Change options for checking for threadmarks and partitioning votes to…
Browse files Browse the repository at this point in the history
… per-quest

instead of global.
Adjust binding those elements to the current quest.
Save in configuration.  Remove unused configuration class.
Fix bug with radio buttons for partition type.
  • Loading branch information
Kinematics committed Mar 13, 2015
1 parent e7ccac1 commit 12db3a1
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 198 deletions.
94 changes: 37 additions & 57 deletions NetTally/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ public static void Load(Tally tally, QuestCollectionWrapper questsWrapper)
{
config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);

TallySection tallyConfig = config.Sections[TallySection.DefinedName] as TallySection;
if (tallyConfig == null)
{
tallyConfig = new TallySection();
tallyConfig.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser;
config.Sections.Add(TallySection.DefinedName, tallyConfig);
}

QuestsSection questConfig = config.Sections[QuestsSection.DefinedName] as QuestsSection;
if (questConfig == null)
{
Expand All @@ -33,7 +25,6 @@ public static void Load(Tally tally, QuestCollectionWrapper questsWrapper)
config.Sections.Add(QuestsSection.DefinedName, questConfig);
}

tallyConfig.Load(tally);
questConfig.Load(questsWrapper);
}

Expand All @@ -42,58 +33,13 @@ public static void Save(Tally tally, QuestCollectionWrapper questsWrapper)
if (config == null)
return;

TallySection tallyConfig = config.Sections[TallySection.DefinedName] as TallySection;
tallyConfig.Save(tally);

QuestsSection questConfig = config.Sections[QuestsSection.DefinedName] as QuestsSection;
questConfig.Save(questsWrapper);

config.Save(ConfigurationSaveMode.Minimal);
}
}

/// <summary>
/// Class to handle the section for storing tally preference flags in the user config file.
/// </summary>
public class TallySection : ConfigurationSection
{
public const string DefinedName = "NetTally.TallySettings";

[ConfigurationProperty("CheckForLastThreadmark", DefaultValue = false)]
public bool CheckForLastThreadmark
{
get { return (bool)this["CheckForLastThreadmark"]; }
set { this["CheckForLastThreadmark"] = value; }
}

[ConfigurationProperty("UseVotePartitions", DefaultValue = false)]
public bool UseVotePartitions
{
get { return (bool)this["UseVotePartitions"]; }
set { this["UseVotePartitions"] = value; }
}

[ConfigurationProperty("PartitionByLine", DefaultValue = true)]
public bool PartitionByLine
{
get { return (bool)this["PartitionByLine"]; }
set { this["PartitionByLine"] = value; }
}

public void Load(Tally tally)
{
tally.CheckForLastThreadmark = CheckForLastThreadmark;
tally.UseVotePartitions = UseVotePartitions;
tally.PartitionByLine = PartitionByLine;
}

public void Save(Tally tally)
{
CheckForLastThreadmark = tally.CheckForLastThreadmark;
UseVotePartitions = tally.UseVotePartitions;
PartitionByLine = tally.PartitionByLine;
}
}

/// <summary>
/// Class to handle the section for storing quests in the user config file.
Expand Down Expand Up @@ -127,7 +73,15 @@ public void Load(QuestCollectionWrapper questWrapper)

foreach (QuestElement quest in Quests)
{
IQuest q = new Quest() { Name = quest.Name, StartPost = quest.StartPost, EndPost = quest.EndPost };
IQuest q = new Quest()
{
Name = quest.Name,
StartPost = quest.StartPost,
EndPost = quest.EndPost,
CheckForLastThreadmark = quest.CheckForLastThreadmark,
UseVotePartitions = quest.UseVotePartitions,
PartitionByLine = quest.PartitionByLine
};
questWrapper.QuestCollection.Add(q);
}
}
Expand Down Expand Up @@ -185,7 +139,8 @@ public QuestElement this[int index]

public void Add(IQuest quest)
{
var questElement = new QuestElement(quest.Name, quest.StartPost, quest.EndPost);
var questElement = new QuestElement(quest.Name, quest.StartPost, quest.EndPost,
quest.CheckForLastThreadmark, quest.UseVotePartitions, quest.PartitionByLine);
BaseAdd(questElement);
}

Expand All @@ -201,11 +156,15 @@ public void Clear()
/// </summary>
public class QuestElement : ConfigurationElement
{
public QuestElement(string name, int startPost, int endPost)
public QuestElement(string name, int startPost, int endPost, bool checkForLastThreadmark,
bool useVotePartitions, bool partitionByLine)
{
Name = name;
StartPost = startPost;
EndPost = endPost;
CheckForLastThreadmark = checkForLastThreadmark;
UseVotePartitions = useVotePartitions;
PartitionByLine = partitionByLine;
}

public QuestElement()
Expand All @@ -232,6 +191,27 @@ public int EndPost
get { return (int)this["EndPost"]; }
set { this["EndPost"] = value; }
}

[ConfigurationProperty("CheckForLastThreadmark", DefaultValue = false)]
public bool CheckForLastThreadmark
{
get { return (bool)this["CheckForLastThreadmark"]; }
set { this["CheckForLastThreadmark"] = value; }
}

[ConfigurationProperty("UseVotePartitions", DefaultValue = false)]
public bool UseVotePartitions
{
get { return (bool)this["UseVotePartitions"]; }
set { this["UseVotePartitions"] = value; }
}

[ConfigurationProperty("PartitionByLine", DefaultValue = true)]
public bool PartitionByLine
{
get { return (bool)this["PartitionByLine"]; }
set { this["PartitionByLine"] = value; }
}
}

}
8 changes: 4 additions & 4 deletions NetTally/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
Text="{Binding Path=CurrentItem.EndPost, ValidatesOnExceptions=True}" GotFocus="textEntry_GotFocus" PreviewMouseDown="textEntry_PreviewMouseDown" MaxLines="1"
IsEnabled="{Binding ElementName=tallyButton, Path=IsEnabled, Converter={StaticResource BoolConverter}, ConverterParameter=Normal, Mode=OneWay}"/>
<CheckBox x:Name="tryLastThreadmark" HorizontalAlignment="Left" Margin="140,80,0,0" VerticalAlignment="Top"
RenderTransformOrigin="0.24,0.938" Content="Try Last Threadmark" IsChecked="{Binding Path=CheckForLastThreadmark}"
RenderTransformOrigin="0.24,0.938" Content="Try Last Threadmark" IsChecked="{Binding Path=CurrentItem.CheckForLastThreadmark}"
IsEnabled="{Binding ElementName=tallyButton, Path=IsEnabled, Converter={StaticResource BoolConverter}, ConverterParameter=Normal, Mode=OneWay}"/>
<CheckBox x:Name="partitionedVotes" Content="Partition Votes" Margin="318,45,0,0" VerticalAlignment="Top"
IsChecked="{Binding Path=UseVotePartitions}" HorizontalAlignment="Left" Width="95"
IsChecked="{Binding Path=CurrentItem.UseVotePartitions}" HorizontalAlignment="Left" Width="95"
IsEnabled="{Binding ElementName=tallyButton, Path=IsEnabled, Converter={StaticResource BoolConverter}, ConverterParameter=Normal, Mode=OneWay}"/>
<StackPanel HorizontalAlignment="Left" Height="51" Margin="418,45,0,0" VerticalAlignment="Top" Width="87"
IsEnabled="{Binding ElementName=tallyButton, Path=IsEnabled, Converter={StaticResource BoolConverter}, ConverterParameter=Normal, Mode=OneWay}">
<RadioButton x:Name="partitionByLine" Content="By Line" HorizontalAlignment="Left" VerticalAlignment="Top"
GroupName="PartitionType" IsChecked="{Binding PartitionByLine, ConverterParameter=Normal, Converter={StaticResource BoolConverter}}"
GroupName="PartitionType" IsChecked="{Binding Path=CurrentItem.PartitionByLine, ConverterParameter=Normal, Converter={StaticResource BoolConverter}}"
IsEnabled="{Binding IsChecked, ElementName=partitionedVotes}"/>
<RadioButton x:Name="partitionByBlock" Content="By Block" HorizontalAlignment="Left" VerticalAlignment="Top"
GroupName="PartitionType" IsChecked="{Binding PartitionByLine, ConverterParameter=Invert, Converter={StaticResource BoolConverter}}"
GroupName="PartitionType" IsChecked="{Binding ElementName=partitionByLine, Path=IsChecked, ConverterParameter=Invert, Converter={StaticResource BoolConverter}, Mode=OneWay}"
IsEnabled="{Binding IsChecked, ElementName=partitionedVotes}"/>
</StackPanel>
<Button x:Name="clearTallyCacheButton" Height="47" Margin="0,10,173,0" VerticalAlignment="Top" Click="clearTallyCacheButton_Click" HorizontalAlignment="Right" Width="49"
Expand Down
4 changes: 0 additions & 4 deletions NetTally/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public MainWindow()
DataContext = QuestCollectionView;

resultsWindow.DataContext = tally;
partitionedVotes.DataContext = tally;
partitionByBlock.DataContext = tally;
partitionByLine.DataContext = tally;
tryLastThreadmark.DataContext = tally;

}

Expand Down
6 changes: 0 additions & 6 deletions TallyCore/Interfaces/IPageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,5 @@ public interface IPageProvider
/// Have an event that can be watched for status messages.
/// </summary>
event EventHandler<MessageEventArgs> StatusChanged;

/// <summary>
/// Flag for whether to try to override the provided starting post by
/// looking for the last threadmark.
/// </summary>
bool CheckForLastThreadmark { get; set; }
}
}
8 changes: 8 additions & 0 deletions TallyCore/Interfaces/IQuest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public interface IQuest
int StartPost { get; set; }
int EndPost { get; set; }

/// <summary>
/// Flag for whether to try to override the provided starting post by
/// looking for the last threadmark.
/// </summary>
bool CheckForLastThreadmark { get; set; }
bool UseVotePartitions { get; set; }
bool PartitionByLine { get; set; }

bool ReadToEndOfThread { get; }
}
}
4 changes: 0 additions & 4 deletions TallyCore/Interfaces/IVoteCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ public interface IVoteCounter
Dictionary<string, HashSet<string>> VotesWithSupporters { get; }
Dictionary<string, string> VoterMessageId { get; }

bool UseVotePartitions { get; set; }
bool PartitionByLine { get; set; }


void TallyVotes(List<HtmlDocument> pages, IQuest quest);
}
}
55 changes: 51 additions & 4 deletions TallyCore/Quest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
}
#endregion

#region Properties
string name = NewEntryName;
int startPost = 1;
int endPost = 0;
bool checkForLastThreadmark = false;
bool useVotePartitions = false;
bool partitionByLine = true;

#region IQuest Properties
/// <summary>
/// The name of the quest thread.
/// </summary>
Expand All @@ -54,7 +60,6 @@ public string Name
}
}

int startPost = 1;
/// <summary>
/// The number of the post to start looking for votes in.
/// Not valid below 1.
Expand All @@ -71,7 +76,6 @@ public int StartPost
}
}

int endPost = 0;
/// <summary>
/// The number of the last post to look for votes in.
/// Not valid below 0.
Expand All @@ -89,11 +93,55 @@ public int EndPost
}
}

/// <summary>
/// Flag for whether to use vote partitioning when tallying votes.
/// </summary>
public bool UseVotePartitions
{
get { return useVotePartitions; }
set
{
useVotePartitions = value;
OnPropertyChanged();
}
}

/// <summary>
/// Flag for whether to use by-line or by-block partitioning,
/// if partitioning votes during the tally.
/// </summary>
public bool PartitionByLine
{
get { return partitionByLine; }
set
{
partitionByLine = value;
OnPropertyChanged();
}
}

/// <summary>
/// Flag for whether to try to override the provided starting post by
/// looking for the last threadmark.
/// </summary>
public bool CheckForLastThreadmark
{
get { return checkForLastThreadmark; }
set
{
checkForLastThreadmark = value;
OnPropertyChanged();
}
}



/// <summary>
/// Boolean value indicating if the tally system should read to the end
/// of the thread. This is done when the EndPost is 0.
/// </summary>
public bool ReadToEndOfThread => EndPost < 1;
#endregion

/// <summary>
/// Function to clean up a user-entered name that may contain a web URL.
Expand All @@ -112,7 +160,6 @@ string Clean(string name)

return name;
}
#endregion


public override string ToString()
Expand Down
40 changes: 0 additions & 40 deletions TallyCore/Tally.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,6 @@ public string TallyResults
}
}

/// <summary>
/// Flag for whether to use vote partitioning when tallying votes.
/// </summary>
public bool UseVotePartitions
{
get { return voteCounter.UseVotePartitions; }
set
{
voteCounter.UseVotePartitions = value;
OnPropertyChanged();
}
}

/// <summary>
/// Flag for whether to use by-line or by-block partitioning,
/// if partitioning votes during the tally.
/// </summary>
public bool PartitionByLine
{
get { return voteCounter.PartitionByLine; }
set
{
voteCounter.PartitionByLine = value;
OnPropertyChanged();
}
}

/// <summary>
/// Flag for whether we should try to find the start post based on the last
/// threadmark of the thread.
/// </summary>
public bool CheckForLastThreadmark
{
get { return pageProvider.CheckForLastThreadmark; }
set
{
pageProvider.CheckForLastThreadmark = value;
OnPropertyChanged();
}
}
#endregion

#region Interface functions
Expand Down
Loading

0 comments on commit 12db3a1

Please sign in to comment.