-
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.
Prepare the resource viewer to be able to open resource projects (#1271)
- Loading branch information
Showing
12 changed files
with
238 additions
and
73 deletions.
There are no files selected for viewing
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
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,66 @@ | ||
using Paranext.DataProvider.Projects.DigitalBibleLibrary; | ||
using Paratext.Data; | ||
using Paratext.Data.Users; | ||
using SIL.WritingSystems; | ||
|
||
namespace Paranext.DataProvider.ParatextUtils; | ||
|
||
/// <summary> | ||
/// Adapted from ParatextScrTextCollection | ||
/// </summary> | ||
public class PlatformScrTextCollection : ScrTextCollection | ||
{ | ||
// keep track of languages that weren't found in SLDR so we don't call over and over for the same bad code | ||
private static readonly HashSet<string> s_sldrLookupFailed = []; | ||
|
||
protected override ScrText CreateResourceProject(ProjectName name) | ||
{ | ||
return new ResourceScrText( | ||
name, | ||
RegistrationInfo.DefaultUser, | ||
new DblResourcePasswordProvider() | ||
); | ||
} | ||
|
||
protected override ScrText CreateXmlResourceProject(ProjectName name) | ||
{ | ||
return new XmlResourceScrText( | ||
name, | ||
RegistrationInfo.DefaultUser, | ||
new DblResourcePasswordProvider() | ||
); | ||
} | ||
|
||
protected override UnsupportedReason MigrateProjectIfNeeded(ScrText scrText) | ||
{ | ||
return scrText.NeedsMigration | ||
? UnsupportedReason.CannotUpgrade | ||
: UnsupportedReason.Supported; | ||
} | ||
|
||
protected override WritingSystemDefinition CreateWsDef(string languageId, bool allowSldr) | ||
{ | ||
// only check SLDR if allowed for this call and all internet access is enabled - SLDR isn't set up to use proxy | ||
WritingSystemDefinition? wsDef = null; | ||
if ( | ||
allowSldr | ||
&& InternetAccess.Status == InternetUse.Enabled | ||
&& !s_sldrLookupFailed.Contains(languageId) | ||
) | ||
{ | ||
try | ||
{ | ||
var sldrFactory = new SldrWritingSystemFactory(); | ||
sldrFactory.Create(languageId, out wsDef); | ||
} | ||
catch (Exception e) | ||
{ | ||
// ignore any SLDR errors - there have been problems with entries on the server failing to parse. | ||
// also the id being provided may not be valid | ||
Console.WriteLine("Getting {0} from SLDR failed: {1}", languageId, e); | ||
s_sldrLookupFailed.Add(languageId); | ||
} | ||
} | ||
return wsDef!; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
c-sharp/Projects/DigitalBibleLibrary/DblResourcePasswordProvider.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,39 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Paranext.DataProvider.Users; | ||
using Paratext.Data.ProjectFileAccess; | ||
using Paratext.Data.Users; | ||
using PtxUtils; | ||
|
||
namespace Paranext.DataProvider.Projects.DigitalBibleLibrary; | ||
|
||
/// <summary> | ||
/// Adapted from ParatextZippedResourcePasswordProvider | ||
/// </summary> | ||
internal class DblResourcePasswordProvider : IZippedResourcePasswordProvider | ||
{ | ||
private string? _cachedValue; | ||
|
||
public string GetPassword() | ||
{ | ||
if (!RegistrationInfo.DefaultUser.IsValid) | ||
{ | ||
// Throwing an exception here is invisible to users because ParatextData swallows it | ||
// Log the message instead in case it is helpful for someone troubleshooting | ||
Console.WriteLine(RegistrationRequiredException.ExceptionMessage); | ||
return "This is not the correct password"; | ||
} | ||
|
||
IConfigurationRoot config = new ConfigurationBuilder() | ||
.AddUserSecrets<DblResourcePasswordProvider>() | ||
.Build(); | ||
|
||
// Run the following from the command line to set a config value (quotes are important): | ||
// dotnet user-secrets set "<secret name>" "<secret value>" | ||
// DO NOT share the secret values, including checking in code, texts, emails, DMs, etc. | ||
_cachedValue ??= StringUtils.DecryptStringFromBase64( | ||
config["DblResourceBase64-DO-NOT-SHARE"] ?? "", | ||
config["DblResourceHash-DO-NOT-SHARE"] ?? "" | ||
); | ||
return _cachedValue; | ||
} | ||
} |
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
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,22 @@ | ||
namespace Paranext.DataProvider.Users; | ||
|
||
/// <summary> | ||
/// Exception to inform callers that a valid Paratext registration is required before DBL resources can be opened | ||
/// </summary> | ||
public class RegistrationRequiredException : Exception | ||
{ | ||
/// <summary> | ||
/// Exception to inform callers that a valid Paratext registration is required before DBL resources can be opened | ||
/// </summary> | ||
public RegistrationRequiredException() | ||
: base(ExceptionMessage) { } | ||
|
||
/// <summary> | ||
/// Exception to inform callers that a valid Paratext registration is required before DBL resources can be opened | ||
/// </summary> | ||
public RegistrationRequiredException(string? customMessage = null) | ||
: base(customMessage ?? ExceptionMessage) { } | ||
|
||
public static string ExceptionMessage { get; set; } = | ||
"You must provide a valid Paratext registration before opening resources from the Digital Bible Library."; | ||
} |
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
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.