-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,529 additions
and
237 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
c-sharp-tests/Projects/RawDirectoryProjectStreamManagerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Paranext.DataProvider.Projects; | ||
|
||
namespace TestParanextDataProvider.Projects | ||
{ | ||
internal class RawDirectoryProjectStorageInterpreterTests | ||
{ | ||
[Test] | ||
public void RawDirPSI_GetExistingDataStreamNames_NotEmpty() | ||
{ | ||
var metadata = new ProjectMetadata( | ||
new Guid(), | ||
"test", | ||
ProjectStorageType.ParatextFolders, | ||
"test" | ||
); | ||
// For now we are just reusing the "assets" directory to verify this works when reading from a directory | ||
var projectDetails = new ProjectDetails(metadata, "assets"); | ||
var psi = new RawDirectoryProjectStreamManager(projectDetails); | ||
Assert.That(psi.GetExistingDataStreamNames(), Has.Length.GreaterThan(80)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Newtonsoft.Json.Linq; | ||
using Paranext.DataProvider.Projects; | ||
|
||
namespace Paranext.DataProvider.JsonUtils; | ||
|
||
internal static class ProjectDataScopeConverter | ||
{ | ||
private const string PROJECT_ID = "projectId"; | ||
private const string PROJECT_NAME = "projectName"; | ||
private const string EXTENSION_NAME = "extensionName"; | ||
private const string DATA_TYPE = "dataType"; | ||
private const string DATA_QUALIFIER = "dataQualifier"; | ||
|
||
public static bool TryGetProjectDataScope( | ||
string jsonString, | ||
out ProjectDataScope? dataScope, | ||
out string errorMessage | ||
) | ||
{ | ||
try | ||
{ | ||
JObject parsedArgs = JObject.Parse(jsonString); | ||
dataScope = new ProjectDataScope() | ||
{ | ||
ProjectID = Guid.Parse(Get(parsedArgs, PROJECT_ID)!), | ||
ProjectName = Get(parsedArgs, PROJECT_NAME), | ||
ExtensionName = Get(parsedArgs, EXTENSION_NAME), | ||
DataType = Get(parsedArgs, DATA_TYPE), | ||
DataQualifier = Get(parsedArgs, DATA_QUALIFIER) | ||
}; | ||
if ( | ||
(dataScope.ProjectID == null) | ||
&& (dataScope.ProjectName == null) | ||
&& (dataScope.ExtensionName == null) | ||
&& (dataScope.DataType == null) | ||
&& (dataScope.DataQualifier == null) | ||
) | ||
{ | ||
throw new Exception("Data scope cannot be empty"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
dataScope = null; | ||
errorMessage = ex.ToString(); | ||
return false; | ||
} | ||
|
||
errorMessage = ""; | ||
return true; | ||
} | ||
|
||
private static string? Get(JObject jObject, string propertyName) | ||
{ | ||
if ( | ||
!jObject.TryGetValue(propertyName, out var property) | ||
|| (property.Value<string>() == null) | ||
) | ||
return null; | ||
|
||
return property.Value<string>()!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Newtonsoft.Json.Linq; | ||
using Paranext.DataProvider.Projects; | ||
|
||
namespace Paranext.DataProvider.JsonUtils | ||
{ | ||
internal static class ProjectMetadataConverter | ||
{ | ||
private const string ID = "id"; | ||
private const string NAME = "name"; | ||
private const string STORAGE_TYPE = "storageType"; | ||
private const string PROJECT_TYPE = "projectType"; | ||
|
||
public static bool TryGetMetadata( | ||
string jsonString, | ||
out ProjectMetadata? projectMetadata, | ||
out string errorMessage | ||
) | ||
{ | ||
try | ||
{ | ||
JObject parsedArgs = JObject.Parse(jsonString); | ||
Guid id = Guid.Parse(Get(parsedArgs, ID)); | ||
string name = Get(parsedArgs, NAME); | ||
Get(parsedArgs, STORAGE_TYPE).FromSerializedString(out ProjectStorageType pst); | ||
string projectType = Get(parsedArgs, PROJECT_TYPE); | ||
projectMetadata = new ProjectMetadata(id, name, pst, projectType); | ||
} | ||
catch (Exception ex) | ||
{ | ||
projectMetadata = null; | ||
errorMessage = ex.ToString(); | ||
return false; | ||
} | ||
|
||
errorMessage = ""; | ||
return true; | ||
} | ||
|
||
private static string Get(JObject jObject, string propertyName) | ||
{ | ||
if ( | ||
!jObject.TryGetValue(propertyName, out var property) | ||
|| (property.Value<string>() == null) | ||
) | ||
throw new ArgumentException($"Missing \"{propertyName}\" property in JSON"); | ||
|
||
return property.Value<string>()!; | ||
} | ||
|
||
public static string ToJsonString(this ProjectMetadata projectMetadata) | ||
{ | ||
return new JObject | ||
{ | ||
[ID] = projectMetadata.ID.ToString(), | ||
[NAME] = projectMetadata.Name, | ||
[STORAGE_TYPE] = projectMetadata.ProjectStorageType.ToSerializedString(), | ||
[PROJECT_TYPE] = projectMetadata.ProjectType | ||
}.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ out string errorMessage | |
versification | ||
); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.