Beispiel #1
0
        static public bool IsUpdateAvailable(Uri uri, string username, string password, string domain)
        {
            bool retval = false;

            try
            {
                EnsureUpdateNotifier();

                if (_UpdateNotifier != null)
                {
                    _UpdateNotifier.BeginVersionCheck();
                }

                // Append the deployment manifest name to the end of the
                // update uri, if it isn't already provided
                if (!uri.AbsoluteUri.EndsWith(".application", true, CultureInfo.CurrentCulture))
                {
                    string applicationName = Path.GetFileNameWithoutExtension(
                        Assembly.GetEntryAssembly().ManifestModule.Name) + ".application";

                    UriBuilder uriBuilder = new UriBuilder(uri.AbsoluteUri);
                    uriBuilder.Path = Path.Combine(uriBuilder.Path, applicationName);
                    uri             = uriBuilder.Uri;
                }

                // Try to download a deployment manifest
                DeploymentManifest = new DeploymentManifest(uri, username, password, domain);

                // Get the local deployment manifest
                LoadLocalDeploymentManifest();

                // Determine if the local version is less than the server version
                Version serverVersion = new Version(1, 0);
                Version localVersion  = new Version(0, 0);

                log.Debug("Comparing versions...");

                if (DeploymentManifest != null)
                {
                    serverVersion = DeploymentManifest.CurrentPublishedVersion;
                }

                if (LocalDeploymentManifest != null)
                {
                    localVersion = LocalDeploymentManifest.CurrentPublishedVersion;
                }

                log.Debug("Server version is: " + serverVersion);
                log.Debug("Local version is: " + localVersion);

                if (localVersion < serverVersion)
                {
                    log.Debug("An update is available!");

                    // If the server version is newer than our local version,
                    // then an update is available!
                    retval = true;
                    return(retval);
                }
                log.Debug("No update is necessary.");
            }
            catch (WebException ex)
            {
                string s = ex.Message;
            }
            catch (Exception)
            {
                // FIXME: log information on catch
            }
            finally
            {
                if (_UpdateNotifier != null)
                {
                    _UpdateNotifier.EndVersionCheck(retval);
                }
            }

            return(retval);
        }