Пример #1
0
        public async Task <VirtualFile> DownloadVersion(string version, VirtualDirectory downloadDirectory,
                                                        IProgressNotifier parentProgress = null,
                                                        string proxy = "")
        {
            await EnsureRepository(proxy).ConfigureAwait(false);

            string actualVersion = await CheckVersion(version, proxy).ConfigureAwait(false);

            CliVersionDefinition versionDefinition = repository.Version.FirstOrDefault(v => v.GetInformalVersion() == actualVersion);

            if (versionDefinition == null)
            {
                throw new UnkownVersionException(actualVersion);
            }

            FileDefinition downloadFile = GetCorrectVersion();

            if (downloadFile == null)
            {
                throw new UnsupportedSystemException(environmentService.PlatformName, environmentService.Architecture);
            }

            Uri downloadUri = InvalidUriFormatException.TryCreateUri(downloadFile.relPath,
                                                                     InvalidUriFormatException.TryCreateUri(settingsProvider.Settings.CliRepositoryRoot));
            VirtualFile result = downloadDirectory.File(downloadFile.name);

            using (Stream fileStream = result.OpenWrite())
            {
                await Download(downloadUri, fileStream, proxy, parentProgress).ConfigureAwait(false);
            }

            using (Stream fileStream = result.OpenRead())
            {
                try
                {
                    securityValidator.ValidateHash(fileStream, downloadFile.Fingerprint.hash, downloadFile.Fingerprint.algorithm);
                }
                catch (HashValidationException e)
                {
                    e.ValidationFileName = downloadUri.AbsolutePath;
                    throw;
                }
            }

            return(result);

            FileDefinition GetCorrectVersion()
            {
                FileDefinition[] correctArchitecture = versionDefinition.File
                                                       .Where(f => f.Architecture.ToString().Equals(environmentService.Architecture,
                                                                                                    StringComparison.OrdinalIgnoreCase))
                                                       .ToArray();
                return(correctArchitecture.FirstOrDefault(f => f.OS.ToString().Equals(environmentService.PlatformName,
                                                                                      StringComparison.OrdinalIgnoreCase)) ??
                       correctArchitecture.FirstOrDefault(f => f.OS == OSDefinition.unbound));
            }
        }
Пример #2
0
        public async Task <bool> IsCurrentVersion(string version, string proxy = "")
        {
            await EnsureRepository(proxy).ConfigureAwait(false);

            string actualVersion = await CheckVersion(version, proxy).ConfigureAwait(false);

            bool onlyUpdate = actualVersion != version;
            CliVersionDefinition versionDefinition = repository.Version.FirstOrDefault(v => v.GetInformalVersion() == actualVersion);

            if (versionDefinition != null)
            {
                Version formalVersion = Version.Parse(versionDefinition.version);

                return(onlyUpdate
                           ? formalVersion <= environmentService.AssemblyVersion
                           : formalVersion == environmentService.AssemblyVersion);
            }

            return(false);
        }