/// <summary>
        /// Uses the a REST client to pull from the Paratext send/receive server. This overrides the base implementation
        /// to avoid needing the current user's Paratext registration code to get the base revision.
        /// </summary>
        public override string[] Pull(string repository, SharedRepository pullRepo)
        {
            string tip = GetBaseRevision(repository);

            // Get bundle
            string        guid  = Guid.NewGuid().ToString();
            List <string> query = new List <string> {
                "guid", guid, "proj", pullRepo.ScrTextName, "projid",
                pullRepo.SendReceiveId, "type", "zstd-v2"
            };

            if (tip != null)
            {
                query.Add("base1");
                query.Add(tip);
            }

            byte[] bundle = client.GetStreaming("pullbundle", query.ToArray());
            // Finish bundle
            client.Get("pullbundlefinish", "guid", guid);
            if (bundle.Length == 0)
            {
                return(new string[0]);
            }

            // Use bundle
            string[] changeSets = HgWrapper.Pull(repository, bundle);

            MarkSharedChangeSetsPublic(repository);
            return(changeSets);
        }
        /// <summary>
        /// Uses the a REST client to push to the Paratext send/receive server. This overrides the base implementation
        /// to avoid needing the current user's Paratext registration code to get the base revision.
        /// </summary>
        public override void Push(string repository, SharedRepository pushRepo)
        {
            string tip = GetBaseRevision(repository);

            // Create bundle
            byte[] bundle = HgWrapper.Bundle(repository, tip);
            if (bundle.Length == 0)
            {
                return;
            }

            // Send bundle
            string guid = Guid.NewGuid().ToString();

            client.PostStreaming(bundle, "pushbundle", "guid", guid, "proj", pushRepo.ScrTextName, "projid",
                                 pushRepo.SendReceiveId, "registered", "yes", "userschanged", "no");

            MarkSharedChangeSetsPublic(repository);
        }
예제 #3
0
        public ParatextService(IWebHostEnvironment env, IOptions <ParatextOptions> paratextOptions,
                               IRepository <UserSecret> userSecretRepository, IRealtimeService realtimeService,
                               IExceptionHandler exceptionHandler, IOptions <SiteOptions> siteOptions, IFileSystemService fileSystemService,
                               ILogger <ParatextService> logger, IJwtTokenHelper jwtTokenHelper, IParatextDataHelper paratextDataHelper,
                               IInternetSharedRepositorySourceProvider internetSharedRepositorySourceProvider,
                               ISFRestClientFactory restClientFactory)
        {
            _paratextOptions      = paratextOptions;
            _userSecretRepository = userSecretRepository;
            _realtimeService      = realtimeService;
            _exceptionHandler     = exceptionHandler;
            _siteOptions          = siteOptions;
            _fileSystemService    = fileSystemService;
            _logger             = logger;
            _jwtTokenHelper     = jwtTokenHelper;
            _paratextDataHelper = paratextDataHelper;
            _internetSharedRepositorySourceProvider = internetSharedRepositorySourceProvider;
            _restClientFactory = restClientFactory;

            _httpClientHandler = new HttpClientHandler();
            _registryClient    = new HttpClient(_httpClientHandler);
            if (env.IsDevelopment() || env.IsEnvironment("DevelopmentBeta") || env.IsEnvironment("Testing") || env.IsEnvironment("TestingBeta"))
            {
                _httpClientHandler.ServerCertificateCustomValidationCallback
                    = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
                // This should be paratext-qa.thedigitalbiblelibrary.org, but it's broken as of 2021-04 and
                // qa.thedigitalbiblelibrary.org should be just as good, at least for the time being.
                _dblServerUri               = "https://qa.thedigitalbiblelibrary.org/";
                _registryServerUri          = "https://registry-dev.paratext.org";
                _registryClient.BaseAddress = new Uri(_registryServerUri);
                _sendReceiveServerUri       = InternetAccess.uriDevelopment;
            }
            else
            {
                _registryClient.BaseAddress = new Uri(_registryServerUri);
            }
            _registryClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            ScrTextCollection = new LazyScrTextCollection();
            HgWrapper         = new HgWrapper();

            SharingLogicWrapper = new SharingLogicWrapper();
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
        }
 /// <summary> Mark all changesets available on the PT server public. </summary>
 private void MarkSharedChangeSetsPublic(string repository)
 {
     HgWrapper.RunCommand(repository, "phase -p -r 'tip'");
 }
        /// <summary> Get the latest public revision. </summary>
        private string GetBaseRevision(string repository)
        {
            string ids = HgWrapper.RunCommand(repository, "log --rev \"public()\" --template \"{node}\n\"");

            return(ids.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault());
        }