public IInternetSharedRepositorySource GetSource(UserSecret userSecret, string sendReceiveServerUri, string registryServerUri) { if (userSecret == null || string.IsNullOrEmpty(sendReceiveServerUri) || string.IsNullOrEmpty(registryServerUri)) { throw new ArgumentException(); } string ptUsername = _jwtTokenHelper.GetParatextUsername(userSecret); var ptUser = new SFParatextUser(ptUsername); JwtRestClient jwtClient = GenerateParatextRegistryJwtClient(userSecret, registryServerUri); IInternetSharedRepositorySource source = new JwtInternetSharedRepositorySource(userSecret.ParatextTokens.AccessToken, jwtClient, ptUser, sendReceiveServerUri); source.RefreshToken(userSecret.ParatextTokens.AccessToken); return(source); }
protected override ScrText CreateScrText(string ptUsername, ProjectName projectName) { var associatedPtUser = new SFParatextUser(ptUsername); return(new MockScrText(associatedPtUser, projectName)); }
/// <summary> Write up-to-date notes from the mongo database to the Paratext project folder </summary> public void PutNotes(UserSecret userSecret, string projectId, string notesText) { // TODO: should accept some data structure instead of XML string username = GetParatextUsername(userSecret); List <string> users = new List <string>(); int nbrAddedComments = 0, nbrDeletedComments = 0, nbrUpdatedComments = 0; ScrText scrText = ScrTextCollection.FindById(username, projectId); if (scrText == null) { throw new DataNotFoundException("Can't get access to cloned project."); } CommentManager manager = CommentManager.Get(scrText); var ptUser = new SFParatextUser(username); var notes = NotesFormatter.ParseNotes(notesText, ptUser); // Algorithm sourced from Paratext DataAccessServer foreach (var thread in notes) { CommentThread existingThread = manager.FindThread(thread[0].Thread); foreach (var comment in thread) { var existingComment = existingThread?.Comments.FirstOrDefault(c => c.Id == comment.Id); if (existingComment == null) { manager.AddComment(comment); nbrAddedComments++; } else if (comment.Deleted) { existingComment.Deleted = true; nbrDeletedComments++; } else { existingComment.ExternalUser = comment.ExternalUser; existingComment.Contents = comment.Contents; existingComment.VersionNumber += 1; nbrUpdatedComments++; } if (!users.Contains(comment.User)) { users.Add(comment.User); } } } try { foreach (string user in users) { manager.SaveUser(user, false); } _paratextDataHelper.CommitVersionedText(scrText, $"{nbrAddedComments} notes added and " + $"{nbrDeletedComments + nbrUpdatedComments} notes updated or deleted in synchronize"); _logger.LogInformation("{0} added {1} notes, updated {2} notes and deleted {3} notes", userSecret.Id, nbrAddedComments, nbrUpdatedComments, nbrDeletedComments); } catch (Exception e) { _logger.LogError(e, "Exception while updating notes: {0}", e.Message); } }
protected virtual ScrText CreateScrText(string ptUsername, ProjectName projectName) { var associatedUser = new SFParatextUser(ptUsername); return(new ScrText(projectName, associatedUser)); }