mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
source code checkin
This commit is contained in:
parent
5f8fb2c825
commit
7e57b72e35
675 changed files with 168433 additions and 0 deletions
54
src/ServerManager.Common/Utils/VersionFeedUtils.cs
Normal file
54
src/ServerManager.Common/Utils/VersionFeedUtils.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using ServerManagerTool.Common.Model;
|
||||
using System;
|
||||
using System.ServiceModel.Syndication;
|
||||
using System.Xml;
|
||||
|
||||
namespace ServerManagerTool.Common.Utils
|
||||
{
|
||||
public static class VersionFeedUtils
|
||||
{
|
||||
public static VersionFeed LoadVersionFeed(string inputUri, string currentVersion)
|
||||
{
|
||||
try
|
||||
{
|
||||
var reader = XmlReader.Create(inputUri);
|
||||
var feed = SyndicationFeed.Load(reader);
|
||||
|
||||
var versionFeed = new VersionFeed
|
||||
{
|
||||
Id = feed.Id,
|
||||
Title = feed.Title?.Text,
|
||||
SubTitle = feed.Description?.Text,
|
||||
Link = feed.Links?[0].Uri,
|
||||
Updated = feed.LastUpdatedTime.ToLocalTime(),
|
||||
};
|
||||
|
||||
//Loop through all items in the SyndicationFeed
|
||||
foreach (var item in feed.Items)
|
||||
{
|
||||
var textContent = item.Content as TextSyndicationContent;
|
||||
|
||||
var versionFeedEntry = new VersionFeedEntry
|
||||
{
|
||||
Id = item.Id,
|
||||
Title = item.Title?.Text,
|
||||
Summary = item.Summary?.Text,
|
||||
Link = item.Links?[0].Uri,
|
||||
Updated = item.LastUpdatedTime.ToLocalTime(),
|
||||
Content = textContent?.Text,
|
||||
Author = item.Authors?[0].Name,
|
||||
|
||||
IsCurrent = (item.Summary?.Text ?? string.Empty).Equals(currentVersion),
|
||||
};
|
||||
versionFeed.Entries.Add(versionFeedEntry);
|
||||
}
|
||||
|
||||
return versionFeed;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new VersionFeed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue