/// <summary>
        /// Checks to see if there is an update for the service. The size of the update will be return. 
        /// If the service returns 0 if no update is available.
        /// </summary>
        /// <param name="details">The details of the service that is checking for the update.</param>
        /// <returns>The size of the update.</returns>
        public WindowsServiceUpdate CheckForUpdate(WindowsServiceDetails details)
        {
            var response = new WindowsServiceUpdate();
            if (!Directory.Exists(_appDataDirectory))
            {
                response.Size = -1;
                return response;
            }

            var filter = details.Name + "-*.zip";
            var zipFilePath = Directory.GetFiles(_appDataDirectory, filter).OrderByDescending(x => x).FirstOrDefault();
            if (zipFilePath == null)
            {
                response.Size = -2;
                return response;
            }

            var fileNameParts = Path.GetFileNameWithoutExtension(zipFilePath).Split('-');
            if (fileNameParts.Length != 2)
            {
                response.Size = -3;
                return response;
            }

            var version = fileNameParts[1];
            if (version != details.Version)
            {
                response.Name = Path.GetFileName(zipFilePath);
                response.Size = new FileInfo(zipFilePath).Length;
                return response;
            }

            return response;
        }
        /// <summary>
        /// Checks to see if there is an update for the service. The size of the update will be return. 
        /// If the service returns an empty name and 0 size if no update is available.
        /// </summary>
        /// <param name="details">The details of the service that is checking for the update.</param>
        /// <returns>The size of the update.</returns>
        public WindowsServiceUpdate CheckForUpdate(WindowsServiceDetails details)
        {
            if (_credentials != null)
            {
                Login(_credentials);
            }

            using (var response = _client.Post("CheckForUpdate", details))
            {
                CheckResponse(response);

                using (var content = response.Content)
                {
                    return JsonConvert.DeserializeObject<WindowsServiceUpdate>(content.ReadAsStringAsync().Result);
                }
            }
        }
        /// <summary>
        /// Checks to see if there is an update for the service. The size of the update will be return.
        /// If the service returns 0 if no update is available.
        /// </summary>
        /// <param name="details">The details of the service that is checking for the update.</param>
        /// <returns>The size of the update.</returns>
        public WindowsServiceUpdate CheckForUpdate(WindowsServiceDetails details)
        {
            var response = new WindowsServiceUpdate();

            if (!Directory.Exists(_appDataDirectory))
            {
                response.Size = -1;
                return(response);
            }

            var filter      = details.Name + "-*.zip";
            var zipFilePath = Directory.GetFiles(_appDataDirectory, filter).OrderByDescending(x => x).FirstOrDefault();

            if (zipFilePath == null)
            {
                response.Size = -2;
                return(response);
            }

            var fileNameParts = Path.GetFileNameWithoutExtension(zipFilePath).Split('-');

            if (fileNameParts.Length != 2)
            {
                response.Size = -3;
                return(response);
            }

            var version = fileNameParts[1];

            if (version != details.Version)
            {
                response.Name = Path.GetFileName(zipFilePath);
                response.Size = new FileInfo(zipFilePath).Length;
                return(response);
            }

            return(response);
        }
Exemple #4
0
		/// <summary>
		/// Checks the client to see if there is an update available. If so it starts the update process
		/// and returns true. If no update is found then return false.
		/// </summary>
		/// <returns>True if an update has started or false otherwise.</returns>
		protected void CheckForUpdate()
		{
			if (_client == null)
			{
				return;
			}

			try
			{
				WriteLine("Check for a service update.", LogLevel.Trace);
				var serviceDetails = new WindowsServiceDetails { Name = ServiceFileName, Version = ServiceVersion };
				var update = _client.CheckForUpdate(serviceDetails);

				if (update.Size > 0)
				{
					WriteLine("Starting to update the service.");
					StartServiceUpdate(update);
				}
			}
			catch (Exception ex)
			{
				WriteLine(ex.ToDetailedString(), LogLevel.Fatal);
			}
		}
Exemple #5
0
        /// <summary>
        /// Checks the client to see if there is an update available. If so it starts the update process
        /// and returns true. If no update is found then return false.
        /// </summary>
        /// <returns>True if an update has started or false otherwise.</returns>
        protected void CheckForUpdate()
        {
            if (_client == null)
            {
                return;
            }

            try
            {
                WriteLine("Check for a service update.", LogLevel.Trace);
                var serviceDetails = new WindowsServiceDetails { Name = ServiceFileName, Version = ServiceVersion };
                var update = _client.CheckForUpdate(serviceDetails);

                if (update.Size > 0)
                {
                    WriteLine("Starting to update the service.");
                    StartServiceUpdate(update);
                }
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToDetailedString(), LogLevel.Fatal);
            }
        }