Skip to content

Commit

Permalink
Merge pull request #4008 from RussKie/Remove_RSS_feeds
Browse files Browse the repository at this point in the history
Remove RSS feeds functionality
  • Loading branch information
jbialobr committed Sep 23, 2017
2 parents 0ea6bb0 + 321963b commit 4e48ea9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 315 deletions.
18 changes: 6 additions & 12 deletions GitCommands/Repository/Repositories.cs
Expand Up @@ -158,28 +158,22 @@ private static BindingList<RepositoryCategory> DeserializeRepositories(string xm
try
{
var serializer = new XmlSerializer(typeof(BindingList<RepositoryCategory>));
StringReader stringReader = null;
try
using (var stringReader = new StringReader(xml))
{
stringReader = new StringReader(xml);
using (var xmlReader = new XmlTextReader(stringReader))
{
stringReader = null;
repositories = serializer.Deserialize(xmlReader) as BindingList<RepositoryCategory>;
if (repositories != null)
var repos = serializer.Deserialize(xmlReader) as BindingList<RepositoryCategory>;
if (repos != null)
{
foreach (var repositoryCategory in repositories)
repositories = new BindingList<RepositoryCategory>();
foreach (var repositoryCategory in repos.Where(r => r.CategoryType == RepositoryCategoryType.Repositories))
{
repositoryCategory.SetIcon();
repositories.Add(repositoryCategory);
}
}
}
}
finally
{
if (stringReader != null)
stringReader.Dispose();
}
}
catch (Exception ex)
{
Expand Down
126 changes: 1 addition & 125 deletions GitCommands/Repository/RepositoryCategory.cs
@@ -1,6 +1,4 @@
using System;
using System.ComponentModel;
using System.Xml;
using System.ComponentModel;

namespace GitCommands.Repository
{
Expand Down Expand Up @@ -32,132 +30,10 @@ public BindingList<Repository> Repositories

public string Description { get; set; }

public string RssFeedUrl { get; set; }

public RepositoryCategoryType CategoryType { get; set; }

public virtual void SetIcon()
{
foreach (var recentRepository in Repositories)
{
if (CategoryType == RepositoryCategoryType.RssFeed)
recentRepository.RepositoryType = RepositoryType.RssFeed;
}
}

public void DownloadRssFeed()
{
try
{
// Create a new XmlTextReader from the specified URL (RSS feed)
var rssReader = new XmlTextReader(RssFeedUrl);
var rssDoc = new XmlDocument();

// Load the XML content into a XmlDocument
rssDoc.Load(rssReader);

//Clear old entries
Repositories.Clear();

// Loop for the <rss> or (atom) <feed> tag
for (var r = 0; r < rssDoc.ChildNodes.Count; r++)
{
// If it is the (atom) feed tag
if (rssDoc.ChildNodes[r].Name == "feed")
{
HandleFeedTag(rssDoc, r);
}

// If it is the rss tag
if (rssDoc.ChildNodes[r].Name == "rss")
{
HandleRssTag(rssDoc, r);
}
}
}
catch (Exception ex)
{
Repositories.Clear();

var repository = new Repository
{
Title = "Error loading rssfeed from :" + RssFeedUrl,
Description = ex.Message,
Path = RssFeedUrl,
RepositoryType = RepositoryType.RssFeed
};
Repositories.Add(repository);
}
}

private void HandleRssTag(XmlNode rssDoc, int r)
{
// <rss> tag found
var nodeRss = rssDoc.ChildNodes[r];

// Loop for the <channel> tag
for (var c = 0; c < nodeRss.ChildNodes.Count; c++)
{
// If it is the channel tag
if (nodeRss.ChildNodes[c].Name != "channel")
continue;
// <channel> tag found
var nodeChannel = nodeRss.ChildNodes[c];

// Set the labels with information from inside the nodes
/*string title = nodeChannel["title"].InnerText;
string link = nodeChannel["link"].InnerText;
string description = nodeChannel["description"].InnerText;*/

//loop through all items
for (var i = 0; i < nodeChannel.ChildNodes.Count; i++)
{
// If it is the item tag, then it has children tags which we will add as items to the ListView
if (nodeChannel.ChildNodes[i].Name != "item")
continue;
var nodeItem = nodeChannel.ChildNodes[i];

// Create a new row in the ListView containing information from inside the nodes
var repository = new Repository();
var title = nodeItem["title"];
if (title != null)
repository.Title = title.InnerText.Trim();
var description = nodeItem["description"];
if (description != null)
repository.Description = description.InnerText.Trim();
var link = nodeItem["link"];
if (link != null)
repository.Path = link.InnerText.Trim();
repository.RepositoryType = RepositoryType.RssFeed;
Repositories.Add(repository);
}
}
}

private void HandleFeedTag(XmlNode rssDoc, int r)
{
// <feed> tag found
var nodeFeed = rssDoc.ChildNodes[r];

//loop through all entries
for (var i = 0; i < nodeFeed.ChildNodes.Count; i++)
{
var nodeItem = nodeFeed.ChildNodes[i];

if (nodeItem.Name != "entry")
continue;
// Create a new row in the ListView containing information from inside the nodes
var repository = new Repository();
var title = nodeItem["title"];
if (title != null)
repository.Title = title.InnerText.Trim();
//repository.Description = nodeItem["content"].InnerText.Trim();
var link = nodeItem["link"];
if (link != null)
repository.Path = link.Attributes["href"].Value;
repository.RepositoryType = RepositoryType.RssFeed;
Repositories.Add(repository);
}
}

public void RemoveRepository(Repository repository)
Expand Down
Expand Up @@ -231,7 +231,6 @@ public void ShowRecentRepositories()

RepositoryCategory filteredRecentRepositoryHistory = new RepositoryCategory();
filteredRecentRepositoryHistory.Description = Repositories.RepositoryHistory.Description;
filteredRecentRepositoryHistory.CategoryType = Repositories.RepositoryHistory.CategoryType;

foreach (Repository repository in Repositories.RepositoryHistory.Repositories)
{
Expand Down
Expand Up @@ -2,7 +2,6 @@
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using GitCommands.Repository;
using ResourceManager;
Expand Down Expand Up @@ -54,17 +53,7 @@ public RepositoryCategory RepositoryCategory
set
{
m_repositoryCategory = value;

if (m_repositoryCategory != null && m_repositoryCategory.CategoryType == RepositoryCategoryType.RssFeed)
{
Task.Factory.StartNew(() => m_repositoryCategory.DownloadRssFeed())
.ContinueWith((task) => InitRepositoryCategory(),
TaskScheduler.FromCurrentSynchronizationContext());
}
else
{
InitRepositoryCategory();
}
InitRepositoryCategory();
}
}

Expand Down Expand Up @@ -113,15 +102,14 @@ private void InitRepositoryCategory()

SuspendLayout();
flowLayoutPanel.SuspendLayout();

foreach (Repository repository in m_repositoryCategory.Repositories)
{
var dashboardItem = new DashboardItem(repository);
dashboardItem.Click += dashboardItem_Click;
dashboardItem.Tag = repository;

if (m_repositoryCategory.CategoryType == RepositoryCategoryType.Repositories)
dashboardItem.ContextMenuStrip = contextMenu;
dashboardItem.ContextMenuStrip = contextMenu;
AddItem(dashboardItem);
}

Expand Down Expand Up @@ -190,11 +178,8 @@ private void moveToMenuItem_DropDownOpening(object sender, EventArgs e)

foreach (RepositoryCategory repositoryCategory in Repositories.RepositoryCategories)
{
if (repositoryCategory.CategoryType == RepositoryCategoryType.Repositories)
{
ToolStripItem addToItem = moveToMenuItem.DropDownItems.Add(repositoryCategory.Description);
addToItem.Click += addToItem_Click;
}
ToolStripItem addToItem = moveToMenuItem.DropDownItems.Add(repositoryCategory.Description);
addToItem.Click += addToItem_Click;
}

if (moveToMenuItem.DropDownItems.Count > 0)
Expand Down

0 comments on commit 4e48ea9

Please sign in to comment.