public async Task DownloadPackageAsync(KojtoCadVersion packageVersion, string destinationDir, IProgress <UpdateProgressData> progress, CancellationToken cancellationToken)
        {
            await Task.Run(() =>
            {
                cancellationToken.ThrowIfCancellationRequested();

                var containerUri = new Uri(_configurationProvider.GetBlobContainerUri());
                var directoryHoldingNewVersions = _configurationProvider.GetKojtoCadVirtualDirectoryName();
                var specifiedVersionDir         = Path.Combine(directoryHoldingNewVersions, GetDirectoryCorrespondingToVersion(packageVersion));
                var blobs = _blobRepository.GetBlobsFromDirectory(containerUri, specifiedVersionDir);

                var count = blobs.Length;
                for (var i = 0; i < blobs.Length; i++)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var cloudBlockBlob = blobs[i];
                    // make the same directory structure using relative paths
                    var relativePath = cloudBlockBlob.Name.Substring(specifiedVersionDir.Length + 1);
                    var file         = Path.Combine(destinationDir, relativePath);

                    new FileInfo(file).Directory.Create();
                    cloudBlockBlob.DownloadToFile(file, FileMode.Create);
                    progress.Report(new UpdateProgressData
                    {
                        CurrentFile = i + 1,
                        FilesCount  = count
                    });
                }
            }, cancellationToken);
        }
        public void DownloadPackage(KojtoCadVersion packageVersion, string destinationDir)
        {
            var containerUri = new Uri(_configurationProvider.GetBlobContainerUri());
            var directoryHoldingNewVersions = _configurationProvider.GetKojtoCadVirtualDirectoryName();
            var specifiedVersionDir         = Path.Combine(directoryHoldingNewVersions, GetDirectoryCorrespondingToVersion(packageVersion));
            var blobs = _blobRepository.GetBlobsFromDirectory(containerUri, specifiedVersionDir);

            foreach (var cloudBlockBlob in blobs)
            {
                var relativePath = cloudBlockBlob.Name.Substring(specifiedVersionDir.Length);
                var file         = Path.Combine(destinationDir, relativePath);

                new FileInfo(file).Directory.Create();

                cloudBlockBlob.DownloadToFile(file, FileMode.Create);
            }
        }
Exemplo n.º 3
0
        public KojtoCadVersion GetLastReleasedVersion(KojtoCadVersion currentVersion)
        {
            if (!_versionValidator.IsValid(currentVersion))
            {
                throw new ArgumentException(nameof(currentVersion));
            }

            var availableVersions = _packageRepository.GetAvailablePackageVersions();

            var latest =
                availableVersions.OrderBy(x => x.Major)
                .ThenBy(x => x.Year)
                .ThenBy(x => x.ElapsedDays)
                .ThenBy(x => x.Revision)
                .LastOrDefault();

            return(latest);
        }
Exemplo n.º 4
0
        public KojtoCadVersion GetVersionFromText(string versionText)
        {
            if (!_versionValidator.IsValid(versionText))
            {
                throw new ArgumentException(nameof(versionText));
            }

            // old
            // KojtoCAD2013.1.0.0.0
            // 2016.08.10.3

            // new
            // 1.2017.365.3
            var split       = versionText.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            var major       = int.Parse(split[0]);
            var year        = int.Parse(split[1]);
            var elapsedDays = int.Parse(split[2]);
            var revision    = int.Parse(split[3]);
            var version     = new KojtoCadVersion {
                Revision = revision, ElapsedDays = elapsedDays, Year = year, Major = major
            };

            return(version);
        }
Exemplo n.º 5
0
        public IEnumerable <Tuple <KojtoCadVersion, string> > GetPreviousInstalledVersions(string installDir, KojtoCadVersion currentVersion)
        {
            var dir = new DirectoryInfo(installDir);

            if (!dir.Exists)
            {
                throw new ArgumentException(nameof(installDir));
            }

            return
                (dir.EnumerateDirectories()
                 .Where(x => _versionValidator.IsValid(x.Name))
                 .Select(x => Tuple.Create(_versionProvider.GetVersionFromText(x.Name), x.FullName))
                 .Where(x => x.Item1 < currentVersion));
        }
Exemplo n.º 6
0
 public async Task <KojtoCadVersion> GetLastReleasedVersionAsync(KojtoCadVersion currentVersion)
 {
     return(await Task.Run(() => GetLastReleasedVersion(currentVersion)));
 }
Exemplo n.º 7
0
 public bool IsValid(KojtoCadVersion version)
 {
     return(version != null && ValidateMajor(version.Major.ToString()) && ValidateYear(version.Year.ToString()) &&
            ValidateElapsedDays(version.ElapsedDays.ToString(), version.Year) &&
            ValidateRevision(version.Revision.ToString()));
 }
 public async Task DownloadPackageAsync(KojtoCadVersion packageVersion, string destinationDir,
                                        IProgress <UpdateProgressData> progress)
 {
     await DownloadPackageAsync(packageVersion, destinationDir, progress, CancellationToken.None);
 }
 private string GetDirectoryCorrespondingToVersion(KojtoCadVersion packageVersion)
 {
     return(packageVersion.ToString());
 }
 public async Task DownloadPackageAsync(KojtoCadVersion packageVersion, string destinationDir)
 {
     await Task.Run(() => DownloadPackage(packageVersion, destinationDir));
 }