Skip to content

Commit

Permalink
Adding Fixes and Handling Edge Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Stern committed Jul 3, 2020
1 parent faa4b89 commit 1ffda1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Converter/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void ConversionLogic() {
for (int i = 0; i < totalLinks; i++)
{
var link = _serviceMongo.GetLinkAt(i, _serviceSQLite);
_serviceSQLite.AddAsync(link);
if(link != null) _serviceSQLite.AddAsync(link);

//bool hasNew = false;
//if (link.LinkGroup.Id == 0) {
Expand Down
15 changes: 14 additions & 1 deletion Converter/SefariaMongoDBService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public LinkItem GetLinkAt(int index, SefariaSQLiteConversionContext targetContex
BsonValue availableLangs = null;
foreach (var element in value.Elements)
{
//Need to fix for { "_id" : ObjectId("51de8ce8edbab4523cea399f")}
switch (element.Name)
{
case "availableLangs":
Expand All @@ -227,11 +228,23 @@ public LinkItem GetLinkAt(int index, SefariaSQLiteConversionContext targetContex
case "expandedRefs1":
SecondaryTopic = element.Value.AsBsonArray.Values.ToList()[0].AsString;
break;
case "refs":
var refs = element.Value.AsBsonArray.Values.ToList();
if (refs != null && refs.Count >= 2) {
PrimaryTopic = refs[0].AsString;
SecondaryTopic = refs[1].AsString;
}
break;
default:
break;

}
}

if (PrimaryTopic == null || SecondaryTopic == null) {
return null;
}

var primaryTopicSeperator = PrimaryTopic.LastIndexOf(' ');
string primaryTopicName = PrimaryTopic.Substring(0, primaryTopicSeperator);
string primaryTopicLocation = PrimaryTopic.Substring(primaryTopicSeperator + 1);
Expand Down Expand Up @@ -265,7 +278,7 @@ public LinkItem GetLinkAt(int index, SefariaSQLiteConversionContext targetContex
targetContext.Add(targetContext.LinkGroups, link.LinkGroup);
}

if (availableLangs.IsBsonArray)
if (availableLangs != null && availableLangs.IsBsonArray)
{
if (link.LinkGroup.LinkedLanguages == null)
{
Expand Down

0 comments on commit 1ffda1e

Please sign in to comment.