Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the AutoUpdateManifest class.
 /// </summary>
 public AutoUpdateManifest()
 {
     _id              = Guid.NewGuid().ToString();
     _product         = new AutoUpdateProductDescriptor();
     _moreInfo        = new AutoUpdateHref();
     _changeSummaries = new AutoUpdateChangeSummaryList();
 }
		/// <summary>
		/// Initializes a new instance of the AutoUpdateManifest class.
		/// </summary>
		public AutoUpdateManifest()
		{
			_id = Guid.NewGuid().ToString();
			_product = new AutoUpdateProductDescriptor();
			_moreInfo = new AutoUpdateHref();
			_changeSummaries = new AutoUpdateChangeSummaryList();
		}
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the AutoUpdateManifest class.
 /// </summary>
 /// <param name="id">A unique identifier to assign to the manifest.</param>
 /// <param name="product">A descriptor that describes the product the update is for.</param>
 /// <param name="moreInfo">A link for displaying more information about the update.</param>
 /// <param name="changeSummaries">A collection of change summaries that can be found in the update.</param>
 /// <param name="urlOfUpdate">The url of the update.</param>
 /// <param name="sizeOfUpdate">The size of the update.</param>
 public AutoUpdateManifest(string id, AutoUpdateProductDescriptor product, AutoUpdateHref moreInfo, AutoUpdateChangeSummaryList changeSummaries, string urlOfUpdate, long sizeOfUpdate)
 {
     _id              = id;
     _product         = product;
     _moreInfo        = moreInfo;
     _changeSummaries = changeSummaries;
     _urlOfUpdate     = urlOfUpdate;
     _sizeOfUpdate    = sizeOfUpdate;
 }
		/// <summary>
		/// Initializes a new instance of the AutoUpdateManifest class.
		/// </summary>
		/// <param name="id">A unique identifier to assign to the manifest.</param>
		/// <param name="product">A descriptor that describes the product the update is for.</param>
		/// <param name="moreInfo">A link for displaying more information about the update.</param>
		/// <param name="changeSummaries">A collection of change summaries that can be found in the update.</param>
		/// <param name="urlOfUpdate">The url of the update.</param>
		/// <param name="sizeOfUpdate">The size of the update.</param>
		public AutoUpdateManifest(string id, AutoUpdateProductDescriptor product, AutoUpdateHref moreInfo, AutoUpdateChangeSummaryList changeSummaries, string urlOfUpdate, long sizeOfUpdate)
		{
			_id = id;
			_product = product;
			_moreInfo = moreInfo;
			_changeSummaries = changeSummaries;
			_urlOfUpdate = urlOfUpdate;
			_sizeOfUpdate = sizeOfUpdate;
		}
        /// <summary>
        /// Instructs the AutoUpdateDownloader to query for the latest version available
        /// </summary>
        /// <param name="progressViewer">The progress viewer by which progress should be displayed</param>
        /// <param name="options">The options that affect this downloader</param>
        /// <param name="productToUpdate">The product descriptor for the product that should be updated</param>
        /// <param name="updateAvailable">The download descriptor that describes the download that could potentially occur</param>
        /// <returns></returns>
        public virtual bool QueryLatestVersion(
            IProgressViewer progressViewer,
            AutoUpdateOptions options,
            AutoUpdateProductDescriptor productToUpdate,
            out AutoUpdateDownloadDescriptor updateAvailable)
        {
            updateAvailable = null;

            return(false);
        }
		/// <summary>
		/// Instructs the AutoUpdateDownloader to query for the latest version available 
		/// </summary>
		/// <param name="progressViewer">The progress viewer by which progress should be displayed</param>
		/// <param name="options">The options that affect this downloader</param>
		/// <param name="productToUpdate">The product descriptor for the product that should be updated</param>
		/// <param name="updateAvailable">The download descriptor that describes the download that could potentially occur</param>
		/// <returns></returns>
		public override bool QueryLatestVersion(IProgressViewer progressViewer, AutoUpdateOptions options, AutoUpdateProductDescriptor productToUpdate, out AutoUpdateDownloadDescriptor updateAvailable)
		{
			updateAvailable = null;
			
			try
			{
				// create a manual web service proxy based on the url specified in the options
				Debug.WriteLine(string.Format("Creating a web service proxy to the following url.\n\tThe web service url is '{0}'.", options.WebServiceUrl), MY_TRACE_CATEGORY);			
				AutoUpdateWebServiceProxy service = new AutoUpdateWebServiceProxy(options.WebServiceUrl);

				// use the web service to query for updates
				Debug.WriteLine(string.Format("Querying the web service for the latest version of '{0}'.\n\tThe current product's version is '{1}'.\n\tThe current product's id is '{2}'.\n\tThe web service url is '{3}'.", productToUpdate.Name, productToUpdate.Version.ToString(), productToUpdate.Id, options.WebServiceUrl), MY_TRACE_CATEGORY);			
				XmlNode node = service.QueryLatestVersion(productToUpdate.Name, productToUpdate.Version.ToString(), productToUpdate.Id);
				
				// if the service returned no results, then there is no update availabe
				if (node == null)
				{
					// bail out 
					Debug.WriteLine(string.Format("No updates are available from the web service at '{0}' for this product.", options.WebServiceUrl), MY_TRACE_CATEGORY);
					return false;
				}

				// otherwise create a reader and try and read the xml from the xml node returned from the web service
				XmlAutoUpdateManifestReader reader = new XmlAutoUpdateManifestReader(node);

				// using the reader we can recreate the manifeset from the xml
				AutoUpdateManifest manifest = reader.Read();	

				/*
				* now create a download descriptor that says, yes we have found an update.
				* we are capable of downloading it, according to these options.
				* the autoupdate manager will decide which downloader to use to download the update
				* */
				updateAvailable = new AutoUpdateDownloadDescriptor(manifest, this, options);
				
				// just to let everyone know that there is a version available
				Debug.WriteLine(string.Format("Version '{0}' of '{1}' is available for download.\n\tThe download url is '{2}'.\n\tThe size of the download is {3}.", updateAvailable.Manifest.Product.Version.ToString(), updateAvailable.Manifest.Product.Name, updateAvailable.Manifest.UrlOfUpdate, this.FormatFileLengthForDisplay(updateAvailable.Manifest.SizeOfUpdate)), MY_TRACE_CATEGORY);

				// we've successfully queried for the latest version of the product to update
				return true;
			}
			catch(ThreadAbortException)
			{

			}
			catch (WebException ex)
			{
                Debug.WriteLine(ex.Message, MY_TRACE_CATEGORY);
			}
			return false;
		}
        /// <summary>
        /// Creates a descriptor that describes the product from it's assembly and version.
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public static AutoUpdateProductDescriptor FromAssembly(Assembly assembly, Version version)
        {
            // create a product descriptor
            AutoUpdateProductDescriptor productDescriptor = new AutoUpdateProductDescriptor();

            // grab its assembly name
            AssemblyName assemblyName = assembly.GetName();

            // set the name of the product
            productDescriptor.Name = assemblyName.Name.Replace(".exe", null);

            // the version will be the starting folder name parsed to a version
            // this is based on the bootstrap's ability to look at folders and determine the appropriate
            // version. we view the versions of the product as a collection of assemblies as a whole, not
            // just individual assemblies. we do this to keep compiliation references together, we compile
            // for releases of versions, and therefore when one changes, we view that single changes as applying to a
            // particular update, which taken in context represents a version of the product.
            productDescriptor.Version = version;

            // snag the product id attribute from the assembly
            ProductIdentifierAttribute pia = ProductIdentifierAttribute.FromAssembly(assembly);

            if (pia != null)
            {
                productDescriptor.Id = pia.Id;
            }

            // snag the product requires registration attribute from the assembly
            ProductRequiresRegistrationAttribute rra = ProductRequiresRegistrationAttribute.FromAssembly(assembly);

            if (rra != null)
            {
                productDescriptor.RequiresRegistration = rra.RequiresRegistration;
            }

            return(productDescriptor);
        }
		/// <summary>
		/// Initializes a new instance of the AutoUpdateProductDescriptorEventArgs class.
		/// </summary>
		/// <param name="productDescriptor">The descriptor that is the context of the event.</param>
		public AutoUpdateProductDescriptorEventArgs(AutoUpdateProductDescriptor productDescriptor) 
			: base()
		{
			_productDescriptor = productDescriptor;
		}
		/// <summary>
		/// Creates a descriptor that describes the product from it's assembly and version.
		/// </summary>
		/// <param name="assembly"></param>
		/// <param name="version"></param>
		/// <returns></returns>
		public static AutoUpdateProductDescriptor FromAssembly(Assembly assembly, Version version)
		{			
			// create a product descriptor
			AutoUpdateProductDescriptor productDescriptor = new AutoUpdateProductDescriptor();				
						
			// grab its assembly name
			AssemblyName assemblyName = assembly.GetName();

			// set the name of the product
			productDescriptor.Name = assemblyName.Name.Replace(".exe", null);
			
			// the version will be the starting folder name parsed to a version
			// this is based on the bootstrap's ability to look at folders and determine the appropriate
			// version. we view the versions of the product as a collection of assemblies as a whole, not 
			// just individual assemblies. we do this to keep compiliation references together, we compile 
			// for releases of versions, and therefore when one changes, we view that single changes as applying to a 
			// particular update, which taken in context represents a version of the product.
			productDescriptor.Version = version;
			
			// snag the product id attribute from the assembly
			ProductIdentifierAttribute pia = ProductIdentifierAttribute.FromAssembly(assembly);
			if (pia != null)
				productDescriptor.Id = pia.Id;

			// snag the product requires registration attribute from the assembly
			ProductRequiresRegistrationAttribute rra = ProductRequiresRegistrationAttribute.FromAssembly(assembly);
			if (rra != null)
				productDescriptor.RequiresRegistration = rra.RequiresRegistration;
		
			return productDescriptor;			
		}
        /// <summary>
        /// Initializes a new instance of the AutoUpdateManager class
        /// </summary>
        /// <param name="options">The options that will control the behaviour of the engine</param>
        /// <param name="productToUpdate">A product descriptor that will be used as the product to find updates for</param>
        public AutoUpdateManager(AutoUpdateOptions options, AutoUpdateProductDescriptor productToUpdate)
        {
			if (options == null)
			{
				throw new ArgumentNullException("options");
			}

			if (productToUpdate == null)
			{
				throw new ArgumentNullException("productToUpdate");
			}

            /*
             * however if we wanted to not do the norm
             * and create an update engine that could update another app
             * then we are all about it, makes no never mind at all
             * */
            _options = options;
            _productToUpdate = productToUpdate;
            _downloaders = new AutoUpdateDownloaderList();
            _downloaders.AddRange(this.CreateDownloadersForInternalUse());
            if (_options.DownloadPath == null || _options.DownloadPath == string.Empty)
                _options.DownloadPath = this.GetBootstrapPath();		
        }	
        /// <summary>
        /// Initializes a new instance of the AutoUpdateManager class
        /// </summary>
        /// <param name="options">The options that will control the behaviour of the engine</param>
        public AutoUpdateManager(AutoUpdateOptions options) 
        {
            // we can't do anything without options to control our behavior
			if (options == null)
			{
				throw new ArgumentNullException("options");
			}

            /*
             * the default options will be used
             * to update the current hosting engine 
             * and download into the bootstrap directory along side the other versions of this hosting engine
             * */
            _options = options;					
            _productToUpdate = AutoUpdateProductDescriptor.FromAssembly(PluginContext.Current.StartingAssembly, PluginContext.Current.AppVersion);			
            _downloaders = new AutoUpdateDownloaderList();
            _downloaders.AddRange(this.CreateDownloadersForInternalUse());
            if (_options.DownloadPath == null || _options.DownloadPath == string.Empty)
                _options.DownloadPath = this.GetBootstrapPath();		
        }
		/// <summary>
		/// Instructs the AutoUpdateDownloader to query for the latest version available 
		/// </summary>
		/// <param name="progressViewer">The progress viewer by which progress should be displayed</param>
		/// <param name="options">The options that affect this downloader</param>
		/// <param name="productToUpdate">The product descriptor for the product that should be updated</param>
		/// <param name="updateAvailable">The download descriptor that describes the download that could potentially occur</param>
		/// <returns></returns>
		public virtual bool QueryLatestVersion(
			IProgressViewer progressViewer,
			AutoUpdateOptions options,
			AutoUpdateProductDescriptor productToUpdate, 
			out AutoUpdateDownloadDescriptor updateAvailable)
		{			
			updateAvailable = null;

			return false;							
		}
 /// <summary>
 /// Initializes a new instance of the AutoUpdateProductDescriptorEventArgs class.
 /// </summary>
 /// <param name="productDescriptor">The descriptor that is the context of the event.</param>
 public AutoUpdateProductDescriptorEventArgs(AutoUpdateProductDescriptor productDescriptor)
     : base()
 {
     _productDescriptor = productDescriptor;
 }