Skip to content

Commit

Permalink
Merge dev to release channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinematics committed Mar 17, 2015
2 parents e07f781 + 883d8e6 commit 992131a
Show file tree
Hide file tree
Showing 20 changed files with 1,697 additions and 306 deletions.
4 changes: 4 additions & 0 deletions .hgtags
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
65b33fcde3ded5f84a2c74c41bf49d21c4e65338 AllInOne 1.0
78a169117b37518c7ee2a1e5d2f6f78a940b36c7 1.0.1
4875d8c801d1c441ee255a7dcd1cc512d38721a7 1.0.2
4875d8c801d1c441ee255a7dcd1cc512d38721a7 1.0.2
0000000000000000000000000000000000000000 1.0.2
0000000000000000000000000000000000000000 1.0.2
9ae5dcb45c7eafde8e6886b51aa5285ad0190dfc 1.0.2
48 changes: 41 additions & 7 deletions NetTally/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ public void Load(QuestCollectionWrapper questWrapper)
{
IQuest q = new Quest()
{
DisplayName = quest.DisplayName,
ThreadName = quest.ThreadName,
#pragma warning disable 0618
// These fields are obsolete, but we still want to read them from old config files.
Site = quest.Site,
Name = quest.Name,
#pragma warning restore 0618
StartPost = quest.StartPost,
EndPost = quest.EndPost,
CheckForLastThreadmark = quest.CheckForLastThreadmark,
Expand Down Expand Up @@ -169,7 +174,12 @@ protected override ConfigurationElement CreateNewElement()

protected override object GetElementKey(ConfigurationElement element)
{
return ((QuestElement)element).Name;
QuestElement qe = element as QuestElement;
if (qe.ThreadName != "")
return qe.ThreadName;
if (qe.Site != "" || qe.Name != "")
return qe.Site + qe.Name;
return qe.DisplayName;
}

public new QuestElement this[string name]
Expand All @@ -195,7 +205,7 @@ public QuestElement this[int index]

public void Add(IQuest quest)
{
var questElement = new QuestElement(quest.Site, quest.Name, quest.StartPost, quest.EndPost,
var questElement = new QuestElement(quest.ThreadName, quest.DisplayName, quest.StartPost, quest.EndPost,
quest.CheckForLastThreadmark, quest.UseVotePartitions, quest.PartitionByLine);
BaseAdd(questElement);
}
Expand All @@ -212,11 +222,13 @@ public void Clear()
/// </summary>
public class QuestElement : ConfigurationElement
{
public QuestElement(string site, string name, int startPost, int endPost, bool checkForLastThreadmark,
public QuestElement(string threadName, string displayName, int startPost, int endPost, bool checkForLastThreadmark,
bool useVotePartitions, bool partitionByLine)
{
Site = site;
Name = name;
//Site = site;
//Name = name;
ThreadName = threadName;
DisplayName = displayName;
StartPost = startPost;
EndPost = endPost;
CheckForLastThreadmark = checkForLastThreadmark;
Expand All @@ -228,14 +240,36 @@ public QuestElement()
{ }


[ConfigurationProperty("Site", DefaultValue = "", IsKey = true)]
[ConfigurationProperty("ThreadName", DefaultValue = "", IsKey = true)]
public string ThreadName
{
get
{
string prop = (string)this["ThreadName"];
if ((prop == null) || (prop == string.Empty))
{
prop = Site + Name;
}
return prop;
}
set { this["ThreadName"] = value; }
}

[ConfigurationProperty("DisplayName", DefaultValue = "")]
public string DisplayName
{
get { return (string)this["DisplayName"]; }
set { this["DisplayName"] = value; }
}

[ConfigurationProperty("Site", DefaultValue = "")]
public string Site
{
get { return (string)this["Site"]; }
set { this["Site"] = value; }
}

[ConfigurationProperty("Name", DefaultValue = "Name", IsRequired = true, IsKey = true)]
[ConfigurationProperty("Name", DefaultValue = "")]
public string Name
{
get { return (string)this["Name"]; }
Expand Down
13 changes: 6 additions & 7 deletions NetTally/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@
IsEnabled="{Binding ElementName=tallyButton, Path=IsEnabled, Converter={StaticResource BoolConverter}, ConverterParameter=Normal, Mode=OneWay}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding DisplayName}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBox x:Name="editQuestName" Height="30" Margin="10,10,227,0" TextWrapping="Wrap" VerticalAlignment="Top" Visibility="Hidden" FontSize="13.333"
Text="{Binding Path=CurrentItem.Name, UpdateSourceTrigger=PropertyChanged}" KeyUp="editQuestName_KeyUp" GotFocus="textEntry_GotFocus"
PreviewMouseDown="textEntry_PreviewMouseDown" Padding="2,4">

Text="{Binding Path=CurrentItem.DisplayName, UpdateSourceTrigger=PropertyChanged}" KeyUp="editQuestName_KeyUp" GotFocus="textEntry_GotFocus"
PreviewMouseDown="textEntry_PreviewMouseDown" Padding="2,4,70,4">
</TextBox>
<TextBox x:Name="editQuestSite" Height="30" Margin="10,10,227,0" TextWrapping="Wrap" VerticalAlignment="Top" Visibility="Hidden" FontSize="13.333"
Text="{Binding Path=CurrentItem.Site, UpdateSourceTrigger=PropertyChanged}" KeyUp="editQuestSite_KeyUp" GotFocus="textEntry_GotFocus"
PreviewMouseDown="textEntry_PreviewMouseDown" Padding="2,4"/>
<TextBox x:Name="editQuestThread" Height="30" Margin="10,10,227,0" TextWrapping="Wrap" VerticalAlignment="Top" Visibility="Hidden" FontSize="13.333"
Text="{Binding Path=CurrentItem.ThreadName, UpdateSourceTrigger=PropertyChanged}" KeyUp="editQuestThread_KeyUp" GotFocus="textEntry_GotFocus"
PreviewMouseDown="textEntry_PreviewMouseDown" Padding="2,4,70,4"/>
<Canvas x:Name="editDescriptorCanvas" Height="30" Margin="10,10,227,0" VerticalAlignment="Top" Visibility="Hidden">
<TextBlock x:Name="editDescriptor" FontSize="18" Foreground="BlueViolet" Text="Quest Name" Canvas.Top="3" Canvas.Right="4"/>
</Canvas>
Expand Down
42 changes: 24 additions & 18 deletions NetTally/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ public MainWindow()
/// <param name="e"></param>
private void Window_Closing(object sender, CancelEventArgs e)
{
QuestCollectionWrapper qcw = new QuestCollectionWrapper(questCollection, QuestCollectionView.CurrentItem?.ToString());
string selectedQuest = "";
IQuest currentQuest = QuestCollectionView.CurrentItem as IQuest;
if (currentQuest != null)
{
selectedQuest = currentQuest.ThreadName;
}
QuestCollectionWrapper qcw = new QuestCollectionWrapper(questCollection, selectedQuest);
NetTallyConfig.Save(tally, qcw);
}
#endregion
Expand Down Expand Up @@ -163,14 +169,14 @@ private void addQuestButton_Click(object sender, RoutedEventArgs e)
var newEntry = questCollection.AddNewQuest();
if (newEntry == null)
{
newEntry = questCollection.FirstOrDefault(q => q.Name == Quest.NewEntryName);
newEntry = questCollection.FirstOrDefault(q => q.ThreadName == Quest.NewThreadEntry);
if (newEntry == null)
return;
}

QuestCollectionView.MoveCurrentTo(newEntry);

EditQuestName();
EditQuestThread();
}

/// <summary>
Expand Down Expand Up @@ -225,13 +231,13 @@ private void Window_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.F2)
{
if ((editQuestName.Visibility == Visibility.Hidden) && (editQuestSite.Visibility == Visibility.Hidden))
if ((editQuestName.Visibility == Visibility.Hidden) && (editQuestThread.Visibility == Visibility.Hidden))
{
EditQuestName();
}
else if (editQuestSite.Visibility == Visibility.Hidden)
else if (editQuestThread.Visibility == Visibility.Hidden)
{
EditQuestSite();
EditQuestThread();
}
else
{
Expand All @@ -240,6 +246,7 @@ private void Window_KeyUp(object sender, KeyEventArgs e)
}
}


/// <summary>
/// When modifying the quest name, hitting enter will complete the entry,
/// and hitting escape will cancel the edits.
Expand All @@ -258,7 +265,7 @@ private void editQuestName_KeyUp(object sender, KeyEventArgs e)
// Restore original name if we escape.
IQuest quest = QuestCollectionView.CurrentItem as IQuest;
if (quest != null)
quest.Name = editingName;
quest.DisplayName = editingName;
DoneEditingQuestName();
}
}
Expand All @@ -269,7 +276,7 @@ private void editQuestName_KeyUp(object sender, KeyEventArgs e)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void editQuestSite_KeyUp(object sender, KeyEventArgs e)
private void editQuestThread_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Expand All @@ -293,21 +300,21 @@ private void editQuestSite_KeyUp(object sender, KeyEventArgs e)
private void EditQuestName()
{
DoneEditingQuestSite();
editingName = ((IQuest)QuestCollectionView.CurrentItem).Name;
editDescriptor.Text = "Quest Name";
editingName = ((IQuest)QuestCollectionView.CurrentItem).DisplayName;
editDescriptor.Text = "Name";
editQuestName.Visibility = Visibility.Visible;
editDescriptorCanvas.Visibility = Visibility.Visible;
editQuestName.Focus();
}

private void EditQuestSite()
private void EditQuestThread()
{
DoneEditingQuestName();
editingName = ((IQuest)QuestCollectionView.CurrentItem).Site;
editDescriptor.Text = "Site Name";
editQuestSite.Visibility = Visibility.Visible;
editingName = ((IQuest)QuestCollectionView.CurrentItem).ThreadName;
editDescriptor.Text = "Thread";
editQuestThread.Visibility = Visibility.Visible;
editDescriptorCanvas.Visibility = Visibility.Visible;
editQuestSite.Focus();
editQuestThread.Focus();
}

private void DoneEditing()
Expand All @@ -325,11 +332,10 @@ private void DoneEditingQuestName()

private void DoneEditingQuestSite()
{
editQuestSite.Visibility = Visibility.Hidden;
editQuestThread.Visibility = Visibility.Hidden;
editDescriptorCanvas.Visibility = Visibility.Hidden;
}
#endregion


#endregion
}
}
90 changes: 81 additions & 9 deletions TallyCore/Adapters/ForumAdapterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public static async Task<IForumAdapter> GetAdapter(IQuest quest, CancellationTok
/// <returns>Returns a forum adapter for the site the quest is on.</returns>
private static IForumAdapter GetExplicitAdapter(IQuest quest)
{
if (quest.Site.StartsWith("http://forums.sufficientvelocity.com/"))
if (quest.SiteName == "http://forums.sufficientvelocity.com/")
return new SufficientVelocityAdapter();
else if (quest.Site.StartsWith("http://forums.spacebattles.com/"))
else if (quest.SiteName == "http://forums.spacebattles.com/")
return new SpaceBattlesAdapter();
else if (quest.Site == string.Empty)
else if (quest.SiteName == string.Empty)
// Sufficient Velocity is the default if no site name is given
return new SufficientVelocityAdapter();
else return null;
Expand All @@ -68,18 +68,90 @@ private async static Task<IForumAdapter> GetImplicitAdapter(IQuest quest, Cancel
{
IPageProvider webPageProvider = new WebPageProvider();

string url = quest.Site + quest.Name;
var page = await webPageProvider.GetPage(quest.ThreadName, quest.SiteName, false, token);

var page = await webPageProvider.GetPage(url, quest.Site, false, token);
if (CheckForXenForo(page))
return new XenForoAdapter(quest.SiteName);

bool found = CheckForVBulletin(page);
if (found)
return new vBulletinAdapter(quest.Site);
if (CheckForVBulletin5(page))
return new vBulletinAdapter5(quest.SiteName);

if (CheckForVBulletin4(page))
return new vBulletinAdapter4(quest.SiteName);

if (CheckForVBulletin3(page))
return new vBulletinAdapter3(quest.SiteName);

return null;
}

private static bool CheckForVBulletin(HtmlDocument page)
/// <summary>
/// Determine if the provided page has the signature indicating that it
/// is a XenForo forum site.
/// </summary>
/// <param name="page">Page to check.</param>
/// <returns>Returns true if it's a XenForo forum.</returns>
private static bool CheckForXenForo(HtmlDocument page)
{
if (page == null)
return false;

var html = page.DocumentNode.Element("html");
if (html != null)
{
return (html.Id == "XenForo");
}

return false;
}

/// <summary>
/// Determine if the provided page has the signature indicating that it
/// is a XenForo forum site.
/// </summary>
/// <param name="page">Page to check.</param>
/// <returns>Returns true if it's a XenForo forum.</returns>
private static bool CheckForVBulletin5(HtmlDocument page)
{
if (page == null)
return false;

var body = page.DocumentNode?.Element("html")?.Element("body");
if (body != null)
{
return (body.Id == "vb-page-body");
}

return false;
}

/// <summary>
/// Determine if the provided page has the signature indicating that it
/// is a XenForo forum site.
/// </summary>
/// <param name="page">Page to check.</param>
/// <returns>Returns true if it's a XenForo forum.</returns>
private static bool CheckForVBulletin4(HtmlDocument page)
{
if (page == null)
return false;

var html = page.DocumentNode?.Element("html");
if (html != null)
{
return (html.Id == "vbulletin_html");
}

return false;
}

/// <summary>
/// Determine if the provided page has the signature indicating that it
/// is a vBulletin forum site.
/// </summary>
/// <param name="page">Page to check.</param>
/// <returns>Returns true if it's a vBulletin forum.</returns>
private static bool CheckForVBulletin3(HtmlDocument page)
{
if (page == null)
return false;
Expand Down
Loading

0 comments on commit 992131a

Please sign in to comment.