internal void ConvertFeedsToJson(FeedsMetadata meta, string rootDirectory) { if (!Directory.Exists(rootDirectory)) { throw new DirectoryNotFoundException($"The expected directory, `{rootDirectory}`, is not here."); } var rootInfo = new DirectoryInfo(rootDirectory); meta.Feeds.ForEachInEnumerable(feed => { traceSource?.TraceVerbose($"feed: {feed.Key}"); var xmlPath = rootInfo.ToCombinedPath($"{feed.Key}.xml"); if (!File.Exists(xmlPath)) { traceSource?.TraceWarning($"The expected file, `{xmlPath}`, is not here."); return; } var xml = File.ReadAllText(xmlPath); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); var jsonPath = rootInfo.ToCombinedPath($"{feed.Key}.json"); var json = JsonConvert.SerializeXmlNode(xmlDoc.DocumentElement, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(jsonPath, json); }); }
internal void DownloadFeeds(FeedsMetadata meta, string rootDirectory) { if (string.IsNullOrEmpty(meta.FeedsDirectory)) { throw new NullReferenceException("The expected feeds directory is not configured."); } foreach (var feed in meta.Feeds) { this.DownloadFeedAsync(feed, rootDirectory).GetAwaiter().GetResult(); } }
/// <summary> /// Convert <see cref="IConfigurationRoot"/> to <see cref="FeedsMetadata"/>. /// </summary> /// <param name="configuration">The configuration.</param> /// <returns></returns> /// <exception cref="NullReferenceException">The expected configuration is not here.</exception> public static FeedsMetadata ToFeedsMetadata(this IConfigurationRoot configuration) { if (configuration == null) { throw new NullReferenceException("The expected configuration is not here."); } var meta = new FeedsMetadata(); configuration.Bind(nameof(FeedsMetadata), meta); return(meta); }
/// <summary> /// Converts <see cref="FeedsMetadata"/> to root directory. /// </summary> /// <param name="meta">The meta.</param> /// <param name="args">The arguments.</param> /// <returns></returns> /// <exception cref="DirectoryNotFoundException">The expected root directory is not here.</exception> public static string ToRootDirectory(this FeedsMetadata meta, ProgramArgs args) { var basePath = args.HasArg(ProgramArgs.BasePath, requiresValue: false) ? args.GetBasePathValue() : Directory.GetCurrentDirectory(); var rootDirectory = meta.FeedsDirectory.StartsWith("./") ? ProgramFileUtility.GetCombinedPath(basePath, meta.FeedsDirectory) : meta.FeedsDirectory; rootDirectory = Path.GetFullPath(rootDirectory); if (!Directory.Exists(rootDirectory)) { Directory.CreateDirectory(rootDirectory); } return(rootDirectory); }
internal void UploadJson(CloudStorageAccount cloudStorageAccount, FeedsMetadata feedsMeta, ProgramArgs args) { var root = feedsMeta.ToRootDirectory(args); var rootInfo = new DirectoryInfo(root); var container = cloudStorageAccount.GetContainerReference("studio-dash"); var tasks = feedsMeta.Feeds.Keys.Select(i => { var jsonFile = rootInfo.ToCombinedPath($"{i}.json"); if (!File.Exists(jsonFile)) { traceSource?.TraceWarning($"The expected file, `{jsonFile}`, is not here."); return(Task.FromResult(0)); } traceSource?.TraceVerbose($"uploading {jsonFile}..."); return(container.UploadBlobAsync(jsonFile, string.Empty)); }).ToArray(); Task.WaitAll(tasks); }