private async Task <bool> ExtractAsync(TemplatesPackageInfo packageInfo, string finalDest, CancellationToken ct = default(CancellationToken))
        {
            try
            {
                _version = packageInfo.Version;
                if (!string.IsNullOrEmpty(packageInfo.LocalPath))
                {
                    var finalDestinationTemp = string.Concat(finalDest, _tmpExtension);

                    await _templatePackage.ExtractAsync(packageInfo.LocalPath, finalDestinationTemp, ReportExtractionProgress, ct);

                    Fs.SafeRenameDirectory(finalDestinationTemp, finalDest);

                    AppHealth.Current.Verbose.TrackAsync($"{StringRes.TemplatesContentExtractedToString} {finalDest}.").FireAndForget();
                    return(true);
                }
                else
                {
                    AppHealth.Current.Error.TrackAsync(StringRes.TemplatesSourceLocalPathEmptyMessage).FireAndForget();
                    return(false);
                }
            }
            catch (Exception ex) when(ex.GetType() != typeof(OperationCanceledException))
            {
                AppHealth.Current.Exception.TrackAsync(ex, StringRes.TemplatesSourceExtractContentMessage).FireAndForget();
                throw;
            }
        }
        public TemplatesPackageInfo ResolvePackage(Version v)
        {
            TemplatesPackageInfo match = Versions.Where(p => p.Version.Major == v.Major && p.Version.Minor == v.Minor)
                                         .OrderByDescending(p => p.Date).FirstOrDefault();

            return(match);
        }
Exemplo n.º 3
0
        public TemplatesPackageInfo ResolvePackage(Version v, string platform, string language)
        {
            TemplatesPackageInfo match = Versions
                                         .Where(p => p.Platform == platform || p.Platform == null)
                                         .Where(p => p.Language == language || p.Language == null)
                                         .Where(p => (p.WizardVersions != null && p.WizardVersions.Any(wv => wv.Major == v.Major && wv.Minor == v.Minor)) ||
                                                (p.WizardVersions == null && p.Version.Major == v.Major && p.Version.Minor == v.Minor))
                                         .OrderByDescending(p => p.Date).FirstOrDefault();

            return(match);
        }
 private static string Extract(TemplatesPackageInfo packageInfo, bool verifyPackageSignatures = true)
 {
     if (!string.IsNullOrEmpty(packageInfo.LocalPath))
     {
         Extract(packageInfo.LocalPath, Path.GetDirectoryName(packageInfo.LocalPath), verifyPackageSignatures);
         return(Path.GetDirectoryName(packageInfo.LocalPath));
     }
     else
     {
         AppHealth.Current.Error.TrackAsync(StringRes.TemplatesSourceLocalPathEmptyMessage).FireAndForget();
         return(null);
     }
 }
        public override void Acquire(ref TemplatesPackageInfo packageInfo)
        {
            if (string.IsNullOrEmpty(packageInfo.LocalPath) || !File.Exists(packageInfo.LocalPath))
            {
                var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                var sourceUrl  = $"{_cdnUrl}/{packageInfo.Name}";
                var fileTarget = Path.Combine(tempFolder, packageInfo.Name);
                Fs.EnsureFolder(tempFolder);

                DownloadContent(sourceUrl, fileTarget);

                packageInfo.LocalPath = fileTarget;
            }
        }
Exemplo n.º 6
0
        private async Task <string> ExtractAsync(TemplatesPackageInfo packageInfo, bool verifyPackageSignatures = true, CancellationToken ct = default(CancellationToken))
        {
            _version = packageInfo.Version;
            if (!string.IsNullOrEmpty(packageInfo.LocalPath))
            {
                await ExtractAsync(packageInfo.LocalPath, Path.GetDirectoryName(packageInfo.LocalPath), verifyPackageSignatures, ct);

                return(Path.GetDirectoryName(packageInfo.LocalPath));
            }
            else
            {
                AppHealth.Current.Error.TrackAsync(StringRes.TemplatesSourceLocalPathEmptyMessage).FireAndForget();
                return(null);
            }
        }
        public override async Task AcquireAsync(TemplatesPackageInfo packageInfo, CancellationToken ct)
        {
            if (string.IsNullOrEmpty(packageInfo.LocalPath) || !File.Exists(packageInfo.LocalPath))
            {
                _version = packageInfo.Version;

                var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                var sourceUrl  = $"{_cdnUrl}/{packageInfo.Name}";
                var fileTarget = Path.Combine(tempFolder, packageInfo.Name);
                Fs.EnsureFolderExists(tempFolder);

                await DownloadContentAsync(sourceUrl, fileTarget, ct);

                packageInfo.LocalPath = fileTarget;
            }
        }
Exemplo n.º 8
0
        public override async Task <TemplatesContentInfo> GetContentAsync(TemplatesPackageInfo packageInfo, string workingFolder, CancellationToken ct)
        {
            var extractionFolder = await ExtractAsync(packageInfo, true, ct);

            var finalDestination = Path.Combine(workingFolder, packageInfo.Version.ToString());

            await Fs.SafeMoveDirectoryAsync(Path.Combine(extractionFolder, "Templates"), finalDestination, true, ReportCopyProgress);

            Fs.SafeDeleteDirectory(Path.GetDirectoryName(packageInfo.LocalPath));

            var templatesInfo = new TemplatesContentInfo()
            {
                Date    = packageInfo.Date,
                Path    = finalDestination,
                Version = packageInfo.Version
            };

            return(templatesInfo);
        }
        public override TemplatesContentInfo GetContent(TemplatesPackageInfo packageInfo, string workingFolder)
        {
            var extractionFolder = Extract(packageInfo);

            var finalDestination = Path.Combine(workingFolder, packageInfo.Version.ToString());

            Fs.SafeMoveDirectory(Path.Combine(extractionFolder, "Templates"), finalDestination, true);

            var templatesInfo = new TemplatesContentInfo()
            {
                Date    = packageInfo.Date,
                Path    = finalDestination,
                Version = packageInfo.Version
            };

            Fs.SafeDeleteDirectory(Path.GetDirectoryName(packageInfo.LocalPath));

            return(templatesInfo);
        }
        public override async Task <TemplatesContentInfo> GetContentAsync(TemplatesPackageInfo packageInfo, string workingFolder, CancellationToken ct)
        {
            var finalDestination = Path.Combine(workingFolder, packageInfo.Version.ToString());

            RemoveTemplatesTempFolders(workingFolder);

            if (!Directory.Exists(finalDestination))
            {
                var extracted = await ExtractAsync(packageInfo, finalDestination, ct);

                if (!extracted)
                {
                    return(null);
                }
            }

            return(new TemplatesContentInfo()
            {
                Date = packageInfo.Date,
                Path = finalDestination,
                Version = packageInfo.Version,
            });
        }