Пример #1
0
        public async Task TestRemoteSource_GetLocalContentAsync()
        {
            string drive   = Path.GetPathRoot(new Uri(typeof(TemplatePackageTests).Assembly.CodeBase).LocalPath);
            string testDir = Path.Combine(drive, $@"Temp\TestRts{Process.GetCurrentProcess().Id}_{Thread.CurrentThread.ManagedThreadId}");

            try
            {
                RemoteTemplatesSource   rts = new RemoteTemplatesSource(Platforms.Uwp, ProgrammingLanguages.CSharp);
                CancellationTokenSource cts = new CancellationTokenSource();

                var packageFile = Path.GetFullPath(@".\Packaging\MsSigned\Templates.mstx");

                var package = new TemplatesPackageInfo()
                {
                    Name           = Path.GetFileName(packageFile),
                    LocalPath      = packageFile,
                    WizardVersions = new List <Version>()
                    {
                        GenContext.GetWizardVersionFromAssembly()
                    },
                };

                var contentInfo = await rts.GetContentAsync(package, testDir, cts.Token);

                Assert.True(Directory.Exists(contentInfo.Path));
            }
            finally
            {
                if (Directory.Exists(testDir))
                {
                    Directory.Delete(testDir, true);
                }
            }
        }
        private static string GetBlobName(string env, string sourceFile, string version)
        {
            Version specifedVersion;

            if (!Version.TryParse(version, out specifedVersion))
            {
                throw new ArgumentException($"The value '{version}' is not valid for parameter '{nameof(version)}'.");
            }

            Version versionInFile = TemplatesPackageInfo.ParseVersion(Path.GetFileName(sourceFile));

            if (versionInFile != null && versionInFile != specifedVersion)
            {
                throw new ArgumentException($"Parameter '{nameof(sourceFile)}' (with value '{sourceFile}') contains the version {versionInFile.ToString()} that do not match with the value specified in the parameter '{nameof(version)}' (with value '{version}').");
            }

            var    envInFile = ParseEnv(Path.GetFileNameWithoutExtension(sourceFile));
            string prefix    = string.Empty;

            if (!envInFile.ToString().Equals(env, StringComparison.OrdinalIgnoreCase) || envInFile == EnvEnum.Unknown)
            {
                prefix = env + ".";
            }

            string blobName = (versionInFile == null) ? $"{prefix}{Path.GetFileNameWithoutExtension(sourceFile)}_{version}.mstx" : sourceFile;

            return(blobName);
        }
        public override TemplatesContentInfo GetContent(TemplatesPackageInfo packageInfo, string workingFolder)
        {
            LoadConfig();
            var package = Config.Latest;

            Acquire(ref package);
            return(base.GetContent(package, workingFolder));
        }
        public override async Task <TemplatesContentInfo> GetContentAsync(TemplatesPackageInfo packageInfo, string workingFolder, CancellationToken ct)
        {
            await AcquireAsync(packageInfo, ct);

            var templatecontent = await base.GetContentAsync(packageInfo, workingFolder, ct);

            return(templatecontent);
        }
Пример #5
0
        public override async Task <TemplatesContentInfo> GetContentAsync(TemplatesPackageInfo packageInfo, string workingFolder, CancellationToken ct)
        {
            await LoadConfigAsync(ct);

            var package = Config.Latest;

            await AcquireAsync(package, ct);

            return(await base.GetContentAsync(package, workingFolder, ct));
        }
Пример #6
0
        public override async Task <TemplatesContentInfo> GetContentAsync(TemplatesPackageInfo packageInfo, string workingFolder, CancellationToken ct)
        {
            await AcquireAsync(packageInfo, ct);

            var templatecontent = await base.GetContentAsync(packageInfo, workingFolder, ct);

            // Workaround for version 2.4, as templates contain "Templates" folder
            await Fs.SafeMoveDirectoryAsync(Path.Combine(templatecontent.Path, "Templates"), templatecontent.Path);

            return(templatecontent);
        }
        private static TemplatesPackageInfo ResolvePackageForVersion(TemplatesSourceConfig config, string version, string platform, string language, TextWriter output)
        {
            Version v = new Version(version);

            if (v.Build != 0 || v.Revision != 0)
            {
                output.WriteCommandText($"WARN: Downloading main version for {v.Major}.{v.Minor}, ignoring the version parts build and revision ({v.Build}.{v.Revision}).");
            }

            TemplatesPackageInfo match = config.ResolvePackage(v, platform, language);

            return(match);
        }
        public static void DownloadContent(RemoteSourceDownloadOptions options, TextWriter output, TextWriter error)
        {
            try
            {
                var shortLanguage = ProgrammingLanguages.GetShortProgrammingLanguage(options.Language);

                output.WriteCommandHeader($"Downloading templates content from environment {options.Env.ToString()} ({options.StorageAccount})");

                TemplatesSourceConfig config = GetConfigFromCdn(options.Env);

                TemplatesPackageInfo package = null;
                if (options.Version != null)
                {
                    package = ResolvePackageForVersion(config, options.Version, options.Platform, shortLanguage, output);
                }
                else
                {
                    package = config.Latest;
                }

                if (package != null)
                {
                    Fs.EnsureFolderExists(options.Destination);

                    var result = RemoteSource.DownloadCdnElement(Environments.CdnUrls[options.Env], package.Name, options.Destination);
                    output.WriteLine();
                    output.WriteCommandText($"Successfully downloaded '{result}'");
                    output.WriteLine();
                }
                else
                {
                    output.WriteLine();
                    output.WriteCommandText($"Package not found for the version '{options.Version}', platform '{options.Platform}' and laguage '{options.Language}'");
                    output.WriteLine();
                }
            }
            catch (Exception ex)
            {
                error.WriteException(ex, $"Unable to download the file content from the specified environment.");
            }
        }