Beispiel #1
0
        public static int GetMaxClientThreads(string appId)
        {
            PassportPDFApplicationManagerApi passportPDFApplicationManagerApi = new PassportPDFApplicationManagerApi(FrameworkGlobals.PassportPdfApiUri);

            Exception e       = null;
            int       pauseMs = 5000;

            for (int i = 0; i < FrameworkGlobals.MAX_RETRYING_REQUESTS; i++)
            {
                try
                {
                    return(Math.Max(passportPDFApplicationManagerApi.PassportPDFApplicationManagerGetMaxClientThreads(appId).Value, 1));
                }
                catch (Exception ex)
                {
                    if (i < FrameworkGlobals.MAX_RETRYING_REQUESTS - 1)
                    {
                        Thread.Sleep(pauseMs); //marking a pause in case of cnx temporarily out and to avoid overhead.
                        pauseMs += 2000;
                    }
                    else
                    {//last iteration
                        e = ex;
                    }
                }
            }

            throw e;
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether the current version of a PassportPDF app is supported, using its Application ID.
        /// </summary>
        /// <param name="applicationId">The ID representing the PassportPDF app.</param>
        /// <param name="currentVersion">The current version of the PassportPDF app.</param>
        /// <returns>Null if the minimum app version failed to be retrieved, and whether the current application version is supported.</returns>
        public static bool?IsCurrentApplicationVersionSupported(string applicationId, Version currentVersion)
        {
            try
            {
                PassportPDFApplicationManagerApi applicationManagerApi = new PassportPDFApplicationManagerApi(FrameworkGlobals.PassportPdfApiUri);
                string minimumSupportedVersion = applicationManagerApi.PassportPDFApplicationManagerGetApplicationMinimumSupportedVersion(applicationId).Value;

                return(currentVersion.CompareTo(new Version(minimumSupportedVersion)) >= 0);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #3
0
        public static bool?IsNewVersionAvailable(string applicationId, Version currentVersion, out string latestVersionNumber)
        {
            try
            {
                Client.GlobalConfiguration.Timeout = FrameworkGlobals.CHECK_FOR_UPDATE_TIMEOUT_MS;

                PassportPDFApplicationManagerApi applicationManagerApi = new PassportPDFApplicationManagerApi()
                {
                    BasePath = FrameworkGlobals.PassportPdfApiUri
                };

                latestVersionNumber = applicationManagerApi.PassportPDFApplicationManagerGetApplicationLatestVersion(applicationId).Value;
                return(latestVersionNumber != null && currentVersion.CompareTo(new Version(latestVersionNumber)) < 0);
            }
            catch
            {
                latestVersionNumber = null;
                return(null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Downloads the last version of a PassportPDF app, using its application ID.
        /// </summary>
        /// <param name="applicationId">The ID representing the PassportPDF app.</param>
        /// <param name="downloadCompletionEventHandler">The event handler for the download completion.</param>
        /// <param name="downloadProgressEventHandler">The (optional) event handler for the download progress.</param>
        /// <returns>Null if the download failed, the path to the archive containing the last version of the app otherwise.</returns>
        /// <remarks>
        /// The downloaded file should not be accesed before the download completion event handler is called.
        /// </remarks>
        public static string DownloadAppLatestVersion(string applicationId, AsyncCompletedEventHandler downloadCompletionEventHandler, DownloadProgressChangedEventHandler downloadProgressEventHandler = null)
        {
            if (downloadCompletionEventHandler == null)
            {
                throw new ArgumentNullException("downloadCompletionEventHandler");
            }

            try
            {
                using (WebClient webClient = new WebClient())
                {
                    if (downloadProgressEventHandler != null)
                    {
                        webClient.DownloadProgressChanged += downloadProgressEventHandler;
                    }
                    if (downloadCompletionEventHandler != null)
                    {
                        webClient.DownloadFileCompleted += downloadCompletionEventHandler;
                    }

                    string downloadedFilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".exe");

                    PassportPDFApplicationManagerApi applicationManagerApi = new PassportPDFApplicationManagerApi(FrameworkGlobals.PassportPdfApiUri);

                    string appDownloadLink = applicationManagerApi.PassportPDFApplicationManagerGetApplicationDownloadLink(applicationId).Value;

                    webClient.DownloadFileAsync(new Uri(appDownloadLink), downloadedFilePath);

                    return(downloadedFilePath);
                }
            }
            catch
            {
                return(null);
            }
        }