Skip to content

Commit

Permalink
Adding feed sync import/export and fixing datetime parsing bug
Browse files Browse the repository at this point in the history
--HG--
branch : dev
  • Loading branch information
Albert Hajdu committed Sep 22, 2016
1 parent d60274a commit b152b6c
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Drivers/FeedSyncProfilePartDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Lombiq.FeedAggregator.ViewModels;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Settings;
using Orchard.Localization;
Expand Down Expand Up @@ -257,6 +258,16 @@ protected override DriverResult Editor(FeedSyncProfilePart part, IUpdateModel up
return Editor(part, shapeHelper);
}

protected override void Exporting(FeedSyncProfilePart part, ExportContentContext context)
{
ExportInfoset(part, context);
}

protected override void Importing(FeedSyncProfilePart part, ImportContentContext context)
{
ImportInfoset(part, context);
}


private IEnumerable<string> GetTypesWithFeedSyncProfileItemPart()
{
Expand Down
41 changes: 41 additions & 0 deletions Helpers/DateTimeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Lombiq.FeedAggregator.Helpers
{
/// <summary>
/// Helper for parsing dates.
/// </summary>
public class DateTimeHelper
{
/// <summary>
/// Parses the given string to date. This is neccessary because the simple tryparse can't parse the
/// date strings which ends with "EDT".
/// </summary>
/// <param name="dateString">The date string.</param>
/// <param name="date">The parsed date.</param>
/// <returns>True if the parse was successful.</returns>
public static bool TryGetDateTime(string dateString, out DateTime date)
{
// Checking if the simple tryparse can parse the date.
date = new DateTime();
if (DateTime.TryParse(dateString, out date))
{
return true;
}

// If the given string ends with "EDT", then parse it manually.
if (dateString.Substring(dateString.Length - 3) == "EDT")
{
if (DateTime.TryParse(dateString.Substring(0, dateString.Length - 3) + " -0400", out date))
{
return true;
}
}

return false;
}
}
}
1 change: 1 addition & 0 deletions Lombiq.FeedAggregator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<Compile Include="Handlers\FeedSyncProfilePartHandler.cs" />
<Compile Include="Extensions\ContentItemExtensions.cs" />
<Compile Include="Extensions\XDocumentExtensions.cs" />
<Compile Include="Helpers\DateTimeHelper.cs" />
<Compile Include="Migrations\FeedSyncProfileItemPartMigrations.cs" />
<Compile Include="Migrations\FeedSyncProfilePartMigrations.cs" />
<Compile Include="Models\IFeedDataSavingProviderContext.cs" />
Expand Down
1 change: 1 addition & 0 deletions Migrations/FeedSyncProfilePartMigrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public int Create()
.Securable()
.DisplayedAs("Feed sync profile")
.WithPart("TitlePart")
.WithPart("IdentityPart")
.WithPart("CommonPart",
part => part
.WithSetting("OwnerEditorSettings.ShowOwnerEditor", "False")
Expand Down
5 changes: 3 additions & 2 deletions Services/FeedEntryExtractors/AtomFeedEntryExtractor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lombiq.FeedAggregator.Models;
using Lombiq.FeedAggregator.Helpers;
using Lombiq.FeedAggregator.Models;
using Orchard.Logging;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -48,7 +49,7 @@ public IList<XElement> GetNewValidEntries(FeedSyncProfilePart feedSyncProfilePar
var modificationDate = new DateTime();
if (updatedElement == null ||
idElement == null ||
!DateTime.TryParse(updatedElement.Value, out modificationDate))
!DateTimeHelper.TryGetDateTime(updatedElement.Value, out modificationDate))
{
i++;
continue;
Expand Down
6 changes: 4 additions & 2 deletions Services/FeedEntryExtractors/RssFeedEntryExtractor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Lombiq.FeedAggregator.Models;
using Lombiq.FeedAggregator.Helpers;
using Lombiq.FeedAggregator.Models;
using Orchard.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml;
Expand Down Expand Up @@ -49,7 +51,7 @@ public IList<XElement> GetNewValidEntries(FeedSyncProfilePart feedSyncProfilePar
var modificationDate = new DateTime();
if (pubDateElement == null ||
idElement == null ||
!DateTime.TryParse(pubDateElement.Value, out modificationDate))
!DateTimeHelper.TryGetDateTime(pubDateElement.Value, out modificationDate))
{
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion Services/FeedSyncProfileUpdaterScheduledTask.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Lombiq.FeedAggregator.Constants;
using Lombiq.FeedAggregator.Extensions;
using Lombiq.FeedAggregator.Helpers;
using Lombiq.FeedAggregator.Models;
using Lombiq.FeedAggregator.Services.FeedDataSavingProviders;
using Lombiq.FeedAggregator.Services.FeedEntryExtractors;
Expand Down Expand Up @@ -81,7 +82,7 @@ public void Process(ScheduledTaskContext context)
var feedItemModificationDateNode = newEntry.GetDescendantNodeByName(feedSyncProfilePart.FeedItemModificationDateType);
var feedItemModificationDate = new DateTime();
if (feedItemModificationDateNode == null ||
!DateTime.TryParse(feedItemModificationDateNode.Value, out feedItemModificationDate)) continue;
!DateTimeHelper.TryGetDateTime(feedItemModificationDateNode.Value, out feedItemModificationDate)) continue;

var feedSyncProfileItem = _contentManager
.Query(feedSyncProfilePart.ContentType)
Expand Down

0 comments on commit b152b6c

Please sign in to comment.