/// <summary> /// Initializes a new instance of the <see cref="SFInstallableDblResource" /> class. /// </summary> /// <param name="userSecret">The user secret.</param> /// <param name="paratextOptions">The paratext options.</param> /// <param name="restClientFactory">The rest client factory.</param> /// <param name="fileSystemService">The file system service.</param> /// <param name="jwtTokenHelper">The JWT token helper.</param> /// <param name="projectDeleter">The project deleter.</param> /// <param name="migrationOperations">The migration operations.</param> /// <param name="passwordProvider">The password provider.</param> /// <exception cref="ArgumentNullException">restClientFactory</exception> private SFInstallableDblResource(UserSecret userSecret, ParatextOptions paratextOptions, ISFRestClientFactory restClientFactory, IFileSystemService fileSystemService, IJwtTokenHelper jwtTokenHelper, IProjectDeleter projectDeleter, IMigrationOperations migrationOperations, IZippedResourcePasswordProvider passwordProvider) : base(projectDeleter, migrationOperations, passwordProvider) { this._userSecret = userSecret; this._paratextOptions = paratextOptions; this._restClientFactory = restClientFactory; this._fileSystemService = fileSystemService; this._jwtTokenHelper = jwtTokenHelper; if (this._restClientFactory == null) { throw new ArgumentNullException(nameof(restClientFactory)); } else if (this._fileSystemService == null) { throw new ArgumentNullException(nameof(fileSystemService)); } }
/// <summary> /// Converts the JSON response to a list of Installable DBL Resources. /// </summary> /// <param name="baseUri">The base URI.</param> /// <param name="response">The response.</param> /// <param name="restClientFactory">The rest client factory.</param> /// <param name="fileSystemService">The file system service.</param> /// <param name="jwtTokenHelper">The JWT token helper.</param> /// <param name="createdTimestamp">The created timestamp.</param> /// <param name="userSecret">The user secret.</param> /// <param name="paratextOptions">The paratext options.</param> /// <param name="projectDeleter">The project deleter.</param> /// <param name="migrationOperations">The migration operations.</param> /// <param name="passwordProvider">The password provider.</param> /// <returns> /// The Installable Resources. /// </returns> private static IEnumerable <SFInstallableDblResource> ConvertJsonResponseToInstallableDblResources( string baseUri, string response, ISFRestClientFactory restClientFactory, IFileSystemService fileSystemService, IJwtTokenHelper jwtTokenHelper, DateTime createdTimestamp, UserSecret userSecret, ParatextOptions paratextOptions, IProjectDeleter projectDeleter, IMigrationOperations migrationOperations, IZippedResourcePasswordProvider passwordProvider) { if (!string.IsNullOrWhiteSpace(response)) { JObject jsonResources; try { jsonResources = JObject.Parse(response); } catch (JsonReaderException) { // Ignore the exception and just return empty result // This is probably caused by partial result from poor connection to DBL yield break; } foreach (JToken jsonResource in jsonResources["resources"] as JArray ?? new JArray()) { var name = (string)jsonResource["name"]; var nameCommon = (string)jsonResource["nameCommon"]; var fullname = (string)jsonResource["fullname"]; if (string.IsNullOrWhiteSpace(fullname)) { fullname = nameCommon; } var languageName = (string)jsonResource["languageName"]; var id = (string)jsonResource["id"]; var revision = (string)jsonResource["revision"]; var permissionsChecksum = (string)jsonResource["permissions-checksum"]; var manifestChecksum = (string)jsonResource["p8z-manifest-checksum"]; var languageIdLdml = (string)jsonResource["languageLDMLId"]; var languageIdCode = (string)jsonResource["languageCode"]; LanguageId languageId = migrationOperations.DetermineBestLangIdToUseForResource(languageIdLdml, languageIdCode); if (string.IsNullOrEmpty(languageId.Id)) { languageId = LanguageIdHelper.FromCommonLanguageName(languageName); } else { languageId = LanguageId.FromEthnologueCode(languageId.Id); } string url = BuildDblResourceEntriesUrl(baseUri, id); var resource = new SFInstallableDblResource(userSecret, paratextOptions, restClientFactory, fileSystemService, jwtTokenHelper, projectDeleter, migrationOperations, passwordProvider) { DisplayName = name, Name = name, FullName = fullname, LanguageID = languageId, DblSourceUrl = url, DBLEntryUid = id, DBLRevision = int.Parse(revision), PermissionsChecksum = permissionsChecksum, ManifestChecksum = manifestChecksum, CreatedTimestamp = createdTimestamp, }; resource.LanguageName = MacroLanguageHelper.GetMacroLanguage(resource.LanguageID) ?? languageName; yield return(resource); } } }