private static void PublishUpdatedRemoteSourceConfig(RemoteSourcePublishOptions options, TextWriter output) { output.WriteLine(); output.WriteCommandText("Generating updated configuration file info (config.json)..."); var targetFile = Path.Combine(Path.Combine(Path.GetTempPath(), "config.json")); Fs.SafeDeleteFile(targetFile); RemoteTemplatesSourceConfig config = RemoteSource.GetRemoteTemplatesSourceConfig(options.StorageAccount, options.Env); using (FileStream fs = new FileStream(targetFile, FileMode.CreateNew, FileAccess.Write)) { StreamWriter sw = new StreamWriter(fs, Encoding.UTF8); JsonSerializerSettings settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; settings.Converters.Add(new StringEnumConverter()); string content = JsonConvert.SerializeObject(config, settings); sw.WriteLine(content); sw.Flush(); } output.WriteCommandText("Updating CND configuration file (config.json)..."); output.WriteCommandText(RemoteSource.UploadElement(options.StorageAccount, options.AccountKey, options.Env.ToString().ToLowerInvariant(), targetFile)); }
public static RemoteTemplatesSourceConfig GetRemoteTemplatesSourceConfig(string storageAccount, EnvEnum environment) { string env = environment.ToString().ToLowerInvariant(); CloudBlobContainer container = RemoteSource.GetContainerAnonymous(storageAccount, env); var remoteElements = RemoteSource.GetAllElements(container); var remotePackages = remoteElements.Where(e => e != null && e.Name.StartsWith(env, StringComparison.OrdinalIgnoreCase) && e.Name.EndsWith(".mstx", StringComparison.OrdinalIgnoreCase)) .Select((e) => new RemoteTemplatesPackage() { Name = e.Name, StorageUri = e.Uri, Bytes = e.Properties.Length, Date = e.Properties.LastModified.Value.DateTime, Version = ParseVersion(e.Name), }) .OrderByDescending(e => e.Date) .OrderByDescending(e => e.Version) .GroupBy(e => e.MainVersion) .Select(e => e.FirstOrDefault()); RemoteTemplatesSourceConfig config = new RemoteTemplatesSourceConfig() { VersionCount = remotePackages.Count(), Latest = remotePackages.FirstOrDefault(), Versions = remotePackages.ToList() }; return(config); }
private static RemoteTemplatesSourceConfig GetConfigFromCdn(EnvEnum env) { Fs.SafeDeleteFile(Path.Combine(Path.GetTempPath(), "config.json")); string configFile = RemoteSource.DownloadCdnElement(Environments.CdnUrls[env], "config.json", Path.GetTempPath()); RemoteTemplatesSourceConfig config = RemoteTemplatesSourceConfig.LoadFromFile(configFile); return(config); }
private static RemoteTemplatesSourceConfig GetConfig(RemoteSourceListOptions options, TextWriter output) { if (options.Build) { output.WriteCommandText("Building Remote Templates Source Configuration information..."); return(RemoteSource.GetRemoteTemplatesSourceConfig(options.StorageAccount, options.Env)); } else { output.WriteCommandText("Getting config file from the CDN (config.json)..."); return(GetConfigFromCdn(options.Env)); } }
public static void PublishContent(RemoteSourcePublishOptions options, TextWriter output, TextWriter error) { try { output.WriteCommandHeader($"Publishing {options.File} for environment {options.Env.ToString()} ({options.StorageAccount})"); output.WriteCommandText("Uploading template package..."); output.WriteCommandText(RemoteSource.UploadTemplatesContent(options.StorageAccount, options.AccountKey, options.Env.ToString().ToLowerInvariant(), options.File, options.Version)); PublishUpdatedRemoteSourceConfig(options, output); } catch (Exception ex) { error.WriteException(ex, $"Unable to publish the file {options.File} content to the specified environment container."); } }
public static void DownloadConfig(RemoteSourceDownloadOptions options, TextWriter output, TextWriter error) { try { output.WriteCommandHeader($"Downloading template source config file from environment {options.Env.ToString()} ({options.StorageAccount})"); output.WriteLine(); var result = RemoteSource.DownloadCdnElement(Environments.CdnUrls[options.Env], "config.json", options.Destination); output.WriteCommandText($"Successfully downloaded '{result}'"); output.WriteLine(); } catch (Exception ex) { error.WriteException(ex, $"Unable to download the config file from the specified environment."); } }
public static void DownloadContent(RemoteSourceDownloadOptions options, TextWriter output, TextWriter error) { try { output.WriteCommandHeader($"Downloading templates content from environment {options.Env.ToString()} ({options.StorageAccount})"); RemoteTemplatesSourceConfig config = GetConfigFromCdn(options.Env); RemoteTemplatesPackage package = null; if (options.Version != null) { package = ResolvePackageForVersion(config, options.Version, output); } else { package = config.Latest; } if (package != null) { Fs.EnsureFolder(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}'"); output.WriteLine(); } } catch (Exception ex) { error.WriteException(ex, $"Unable to download the file content from the specified environment."); } }