/// <summary> /// Loads the deployment manifest, if it exists! /// </summary> static public void LoadLocalDeploymentManifest() { DeploymentManifest manifest = null; log.Debug("Loading local deployment manifest..."); Assembly assembly = Assembly.GetExecutingAssembly(); string pathToManifest = Path.Combine(VersionRepositoryFolder, LocalDeploymentManifestFilename); log.Debug("Checking for deployment manifest at '" + pathToManifest + "'..."); // Check if an application manifest exists at the specified location... if (File.Exists(pathToManifest)) { log.Debug("Local deployment manifest found."); // Get the uri directory for the current assembly string baseUri = Path.GetDirectoryName(assembly.CodeBase); // Build a Uri to the manifest UriBuilder uriBuilder = new UriBuilder(pathToManifest); log.Debug("Loading deployment manifest..."); // Build an ApplicationManifest from the manifest file manifest = new DeploymentManifest(uriBuilder.Uri); } else { log.Warn("Manifest not found at '" + pathToManifest + "'."); } LocalDeploymentManifest = manifest; }
/// <summary> /// Saves deployment and application manifests /// to local directories for future reference. /// </summary> static private void SaveLocalManifests() { if (DeploymentManifest != null) { // Get the path where the application manifest should reside... Assembly assembly = Assembly.GetExecutingAssembly(); // Load the application manifest DeploymentManifest.LoadApplicationManifest(); // Save the local application manifest also DeploymentManifest.ApplicationManifest.Save(ApplicationDestinationPath); // Update information in the deployment manifest to reflect // the new location of the application manifest. foreach (DependentAssembly da in DeploymentManifest.DependentAssemblies) { // The deployment manifest should have a single dependent assembly - // the application manifest // Set new information about the application manifest FileInfo fi = new FileInfo(Path.GetFullPath(ApplicationDestinationPath)); // Set the codebase for the application to the new version // NOTE: this fixes bug #2001838 - deployment.manifest uses absolute paths da.CodeBase = ApplicationDestinationRelativePath; da.Size = fi.Length; } // Save the deployment manifest DeploymentManifest.Save(LocalDeploymentManifestPath); // Get a new local deployment manifest LoadLocalDeploymentManifest(); } }
/// <summary> /// Loads the deployment manifest, if it exists! /// </summary> static public void LoadLocalDeploymentManifest() { DeploymentManifest manifest = null; log.Debug("Loading local deployment manifest..."); Assembly assembly = Assembly.GetExecutingAssembly(); string pathToManifest = Path.Combine(VersionRepositoryFolder, LocalDeploymentManifestFilename); log.Debug("Checking for deployment manifest at '" + pathToManifest + "'..."); // Check if an application manifest exists at the specified location... if (File.Exists(pathToManifest)) { log.Debug("Local deployment manifest found."); // Get the uri directory for the current assembly string baseUri = Path.GetDirectoryName(assembly.CodeBase); // Build a Uri to the manifest UriBuilder uriBuilder = new UriBuilder(pathToManifest); log.Debug("Loading deployment manifest..."); // Build an ApplicationManifest from the manifest file manifest = new DeploymentManifest(uriBuilder.Uri); } else log.Warn("Manifest not found at '" + pathToManifest + "'."); LocalDeploymentManifest = manifest; }
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; }
static public ApplicationManifest GetCurrentApplicationManifest() { ApplicationManifest appManifest = null; DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update") as DDayUpdateConfigurationSection; // Try to load a local deployment manifest if (LocalDeploymentManifest == null) { LoadLocalDeploymentManifest(); } DeploymentManifest deploymentManifest = LocalDeploymentManifest ?? DeploymentManifest; // Try to retrieve the application manifest from the // deployment manifest. if (deploymentManifest != null) { // Load the deployment manifest, if we haven't done so already! log.Debug("Loading application manifest from deployment manifest..."); try { deploymentManifest.LoadApplicationManifest(); appManifest = deploymentManifest.ApplicationManifest; log.Debug("Loaded."); } catch { } } // If we haven't found an application manifest yet, then let's try to load // it from a previous version! if (appManifest == null) { log.Debug("The application manifest could not be located; searching previous versions..."); if (cfg != null) { Version[] localVersions = cfg.VersionManager.LocalVersions; if (localVersions.Length > 0) { for (int i = 0; i < localVersions.Length; i++) { log.Debug("Searching version '" + localVersions[i] + "'..."); // Try to load an application manifest // from this version! try { string directory = Path.Combine(VersionRepositoryFolder, localVersions[i].ToString()); Uri uri = new Uri( Path.Combine( directory, LocalApplicationManifestFilename ) ); log.Debug("Attempting to load manifest from '" + uri.AbsolutePath + "'..."); // Get the application manifest appManifest = new ApplicationManifest(uri); } catch { } // If we found an application manifest, then check to see // if the application name matches our bootstrap executable // name. If it doesn't, then we're looking at a version // of a *different* application, and should ignore it! if (appManifest.EntryPoint != null && appManifest.EntryPoint.AssemblyIdentity != null && appManifest.EntryPoint.AssemblyIdentity.Name != null) { string manifestName = appManifest.EntryPoint.AssemblyIdentity.Name; string appName = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location); if (!object.Equals(manifestName, appName)) { log.Debug("The application manifest for application '" + manifestName + "' was found and ignored (looking for '" + appName + "')"); appManifest = null; } } // We found an application manifest that we can use! if (appManifest != null) { log.Debug("Application manifest found!"); break; } } } } } return(appManifest); }
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); }
/// <summary> /// Downloads updated versions of each file that is outdated. /// </summary> /// <exception cref="DeploymentManifestException"> /// if the deployment manifest has not yet been loaded /// </exception> private bool UpdateFiles() { // Ensure the deployment manifest has been loaded if (DeploymentManifest == null) { throw new DeploymentManifestException(); } // First, load the application manifest from the deployment manifest DeploymentManifest.LoadApplicationManifest(); // Start a list of file downloaders the will be obtained from // the application manifest. _FileDownloaders = new List <FileDownloader>(); _Saved = new List <FileDownloader>(); // Then, iterate through each downloadable file, determine if // an update is required for it, and download a new version // if necessary. foreach (IDownloadableFile file in DeploymentManifest.ApplicationManifest.DownloadableFiles) { FileDownloader download = file.GetDownloader(); download.Completed += new EventHandler(download_Completed); download.Cancelled += new EventHandler(download_Cancelled); download.Error += new EventHandler <ExceptionEventArgs>(download_Error); download.Saved += new EventHandler(download_Saved); log.Debug("Retrieved a downloader for '" + download.DestinationName + "'..."); _FileDownloaders.Add(download); } log.Debug("Determining total download size..."); // Determine the file patterns that are preserved (never overwritten) // during the update process... List <string> preservedPatterns = new List <string>(); DDayUpdateConfigurationSection cfg = ConfigurationManager.GetSection("DDay.Update") as DDayUpdateConfigurationSection; if (cfg != null) { foreach (KeyValuePairConfigurationElement kvpe in cfg.Preserve) { if (!string.IsNullOrEmpty(kvpe.Value)) { preservedPatterns.Add(kvpe.Value); } } } // Determine the preserved status of each file downloader. // Preserved files will not be downloaded foreach (FileDownloader downloader in _FileDownloaders) { downloader.DeterminePreservedStatus(preservedPatterns.ToArray()); } // Determine the total size in bytes of updates to be made long totalSize = 0; foreach (FileDownloader downloader in _FileDownloaders) { totalSize += downloader.DownloadSize; } log.Debug("Total download size is " + totalSize + " bytes; notifying GUI..."); // Notify of the total update size in bytes if (UpdateNotifier != null) { UpdateNotifier.NotifyTotalUpdateSize(totalSize); } // Setup an event to synchronize with... _DownloadEvent = new AutoResetEvent(false); log.Debug("Downloading each file to be updated..."); // Download each file foreach (FileDownloader downloader in _FileDownloaders) { if (!CancelledOrError) { // Download the new copy of the file downloader.Download(UpdateNotifier); // Wait for the item to be downloaded _DownloadEvent.WaitOne(); } else { break; } } log.Info("File downloads finished."); return(true); }
public ConfirmDoUpdateWindow(DeploymentManifest deploymentManifest) { DeploymentManifest = deploymentManifest; this.InitializeComponent(); }