Exemple #1
0
        /// <summary>
        /// Async call to request downloading a file from web.
        /// This call raises UpdateDownloaded event notification.
        /// </summary>
        /// <param name="url">Web URL for file to download.</param>
        /// <param name="version">The version of package that is to be downloaded.</param>
        /// <returns>Request status, it may return false if invalid URL was passed.</returns>
        private bool DownloadUpdatePackageAsynchronously(string url, BinaryVersion version)
        {
            if (string.IsNullOrEmpty(url) || (null == version))
            {
                _versionCheckInProgress = false;
                return(false);
            }

            UpdateFileLocation = string.Empty;
            string downloadedFileName = string.Empty;
            string downloadedFilePath = string.Empty;

            try
            {
                downloadedFileName = Path.GetFileName(url);
                downloadedFilePath = Path.Combine(Path.GetTempPath(), downloadedFileName);

                if (File.Exists(downloadedFilePath))
                {
                    File.Delete(downloadedFilePath);
                }
            }
            catch (Exception)
            {
                _versionCheckInProgress = false;
                return(false);
            }

            var client = new WebClient();

            client.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadFileCompleted);
            client.DownloadFileAsync(new Uri(url), downloadedFilePath, downloadedFilePath);
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Get a binary version for the executing assembly
        /// </summary>
        /// <returns>A BinaryVersion</returns>
        internal static BinaryVersion GetCurrentBinaryVersion()
        {
            // If we're looking at dailies, latest build version will simply be
            // the current build version without a build or revision, ex. 0.6
            var v = Assembly.GetExecutingAssembly().GetName().Version;

            return(BinaryVersion.FromString(string.Format("{0}.{1}.{2}", v.Major, v.Minor, v.Build)));
        }
Exemple #3
0
        private BinaryVersion GetLatestInstallVersion()
        {
            var dynamoInstallations = GetDynamoInstalls();
            var latestVersion       =
                dynamoInstallations.Select(GetDynamoVersion).OrderBy(s => s).LastOrDefault();

            return(latestVersion == null ? null : BinaryVersion.FromString(latestVersion.ToString()));
        }
Exemple #4
0
 private void SetUpdateInfo(BinaryVersion latestBuildVersion, string latestBuildDownloadUrl, string signatureUrl)
 {
     UpdateInfo = new AppVersionInfo()
     {
         Version        = latestBuildVersion,
         VersionInfoURL = Configuration.DownloadSourcePath,
         InstallerURL   = latestBuildDownloadUrl,
         SignatureURL   = signatureUrl
     };
 }
Exemple #5
0
        /// <summary>
        /// Callback for the UpdateRequest's UpdateDataAvailable event.
        /// Reads the request's data, and parses for available versions.
        /// If a more recent version is available, the UpdateInfo object
        /// will be set.
        /// </summary>
        /// <param name="request">An instance of an update request.</param>
        public void UpdateDataAvailable(IAsynchronousRequest request)
        {
            UpdateInfo = null;

            //If there is error data or the request data is empty
            //bail out.
            if (!string.IsNullOrEmpty(request.Error) ||
                string.IsNullOrEmpty(request.Data))
            {
                _versionCheckInProgress = false;
                return;
            }

            XNamespace ns = "http://s3.amazonaws.com/doc/2006-03-01/";

            XDocument doc = null;

            using (TextReader td = new StringReader(request.Data))
            {
                doc = XDocument.Load(td);
            }

            var bucketresult = doc.Element(ns + "ListBucketResult");
            var builds       = bucketresult.Descendants(ns + "LastModified").
                               OrderByDescending(x => DateTime.Parse(x.Value)).
                               Where(x => x.Parent.Value.Contains("DynamoInstall")).
                               Select(x => x.Parent);

            var xElements = builds as XElement[] ?? builds.ToArray();

            if (!xElements.Any())
            {
                _versionCheckInProgress = false;
                return;
            }

            var latestBuild         = xElements.First();
            var latestBuildFileName = latestBuild.Element(ns + "Key").Value;

            var latestBuildDownloadUrl = Path.Combine(Configurations.UpdateDownloadLocation, latestBuildFileName);
            var latestBuildVersion     = BinaryVersion.FromString(Path.GetFileNameWithoutExtension(latestBuildFileName).Remove(0, 13));

            if (latestBuildVersion > ProductVersion)
            {
                UpdateInfo = new AppVersionInfo()
                {
                    Version        = latestBuildVersion,
                    VersionInfoURL = Configurations.UpdateDownloadLocation,
                    InstallerURL   = latestBuildDownloadUrl
                };
            }

            _versionCheckInProgress = false;
        }
Exemple #6
0
        public static BinaryVersion GetProductVersion()
        {
            if (null != productVersion)
            {
                return(productVersion);
            }

            var executingAssemblyName = Assembly.GetExecutingAssembly().GetName();

            productVersion = BinaryVersion.FromString(executingAssemblyName.Version.ToString());

            return(productVersion);
        }
Exemple #7
0
        /// <summary>
        /// Get a BinaryVersion from a file path.
        /// </summary>
        /// <param name="installNameBase">The base install name.</param>
        /// <param name="filePath">The path name of the file.</param>
        /// <returns>A BinaryVersion or null if one can not be parse from the file path.</returns>
        internal static BinaryVersion GetBinaryVersionFromFilePath(string installNameBase, string filePath)
        {
            // Filename format is DynamoInstall0.7.1.YYYYMMDDT0000.exe
            var index = filePath.IndexOf(installNameBase, StringComparison.Ordinal);

            if (index < 0)
            {
                return(null);
            }

            // Skip past the 'installNameBase' since we are only interested
            // in getting the version numbers that come after the base name.
            var fileName = Path.GetFileNameWithoutExtension(filePath);
            var version  = fileName.Substring(index + installNameBase.Length);

            var splits = version.Split(new [] { "." }, StringSplitOptions.RemoveEmptyEntries);

            if (splits.Count() < 3) // This can be 4 if it includes revision number.
            {
                return(null);
            }

            ushort major, minor, build;

            if (!ushort.TryParse(splits[0], out major))
            {
                return(null);
            }
            if (!ushort.TryParse(splits[1], out minor))
            {
                return(null);
            }
            if (!ushort.TryParse(splits[2], out build))
            {
                return(null);
            }

            return(BinaryVersion.FromString(string.Format("{0}.{1}.{2}.0", major, minor, build)));
        }
Exemple #8
0
        /// <summary>
        /// Get a BinaryVersion from a file path.
        /// </summary>
        /// <param name="installNameBase">The base install name.</param>
        /// <param name="filePath">The path name of the file.</param>
        /// <returns>A BinaryVersion or null if one can not be parse from the file path.</returns>
        internal static BinaryVersion GetBinaryVersionFromFilePath(string installNameBase, string filePath)
        {
            // Filename format is DynamoInstall0.7.1.YYYYMMDDT0000.exe

            if (!filePath.Contains(installNameBase))
            {
                return(null);
            }

            var fileName = Path.GetFileNameWithoutExtension(filePath).Replace(installNameBase, "");
            var splits   = fileName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);

            if (splits.Count() < 3)
            {
                return(null);
            }

            var major = ushort.Parse(splits[0]);
            var minor = ushort.Parse(splits[1]);
            var build = ushort.Parse(splits[2]);

            return(BinaryVersion.FromString(string.Format("{0}.{1}.{2}.0", major, minor, build)));
        }
 private void SetUpdateInfo(BinaryVersion latestBuildVersion, string latestBuildDownloadUrl, string signatureUrl)
 {
     UpdateInfo = new AppVersionInfo()
     {
         Version = latestBuildVersion,
         VersionInfoURL = Configuration.DownloadSourcePath,
         InstallerURL = latestBuildDownloadUrl,
         SignatureURL = signatureUrl
     };
 }
Exemple #10
0
        public static BinaryVersion GetProductVersion()
        {
            if (null != productVersion) return productVersion;

            var executingAssemblyName = Assembly.GetExecutingAssembly().GetName();
            productVersion = BinaryVersion.FromString(executingAssemblyName.Version.ToString());

            return productVersion;
        }
Exemple #11
0
        /// <summary>
        /// Async call to request downloading a file from web.
        /// This call raises UpdateDownloaded event notification.
        /// </summary>
        /// <param name="url">Web URL for file to download.</param>
        /// <param name="version">The version of package that is to be downloaded.</param>
        /// <param name="tempPath">Temp folder path where the update package
        /// to be downloaded.</param>
        /// <returns>Request status, it may return false if invalid URL was passed.</returns>
        private bool DownloadUpdatePackageAsynchronously(string url, BinaryVersion version, string tempPath)
        {
            currentDownloadProgress = -1;

            if (string.IsNullOrEmpty(url) || (null == version))
            {
                versionCheckInProgress = false;
                return false;
            }

            UpdateFileLocation = string.Empty;
            string downloadedFileName = string.Empty;
            string downloadedFilePath = string.Empty;

            try
            {
                downloadedFileName = Path.GetFileName(url);
                downloadedFilePath = Path.Combine(tempPath, downloadedFileName);

                if (File.Exists(downloadedFilePath))
                    File.Delete(downloadedFilePath);
            }
            catch (Exception)
            {
                versionCheckInProgress = false;
                return false;
            }

            var client = new WebClient();
            client.DownloadProgressChanged += client_DownloadProgressChanged;
            client.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadFileCompleted);
            client.DownloadFileAsync(new Uri(url), downloadedFilePath, downloadedFilePath);
            return true;
        }
        /// <summary>
        /// Async call to request downloading a file from web.
        /// This call raises UpdateDownloaded event notification.
        /// </summary>
        /// <param name="url">Web URL for file to download.</param>
        /// <param name="version">The version of package that is to be downloaded.</param>
        /// <returns>Request status, it may return false if invalid URL was passed.</returns>
        private bool DownloadUpdatePackage(string url, BinaryVersion version)
        {
            if (string.IsNullOrEmpty(url) || (null == version))
            {
                versionCheckInProgress = false;
                return false;
            }

            UpdateFileLocation = string.Empty;
            string downloadedFileName = string.Empty;
            string downloadedFilePath = string.Empty;

            try
            {
                //downloadedFileName = Path.GetFileNameWithoutExtension(url);
                //downloadedFileName += "." + version.ToString() + Path.GetExtension(url);
                downloadedFileName = Path.GetFileName(url);
                downloadedFilePath = Path.Combine(Path.GetTempPath(), downloadedFileName);

                if (File.Exists(downloadedFilePath))
                    File.Delete(downloadedFilePath);
            }
            catch (Exception)
            {
                versionCheckInProgress = false;
                return false;
            }

            WebClient client = new WebClient();
            client.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadFileCompleted);
            client.DownloadFileAsync(new Uri(url), downloadedFilePath, downloadedFilePath);
            return true;
        }
Exemple #13
0
        public override bool Equals(object other)
        {
            BinaryVersion rhs = other as BinaryVersion;

            return(this == rhs);
        }