public static async Task CompareAndSync(string folder, Dictionary <string, Tag> tags, Dictionary <string, Tag> authoritiveTags) { var newTags = authoritiveTags.Keys.Except(tags.Keys); foreach (var tag in newTags) { var t = authoritiveTags[tag]; //Add New Tag to Existing var folderPath = $"{folder}\\{_tagsFolder}\\{tag}"; Directory.CreateDirectory(folderPath); var json = JsonSerialisation.Serialise(t); var filePath = $"{folderPath}\\{ApimUtils.ConfigurationFileName}"; System.Console.WriteLine($"Writing {filePath}"); await File.WriteAllTextAsync(filePath, json); } var oldTags = tags.Keys.Except(authoritiveTags.Keys); foreach (var tag in oldTags) { //Remove Products var t = tags[tag]; var folderPath = Path.Combine($"{folder}\\{_tagsFolder}\\", tag); File.Delete(Path.Combine(folderPath, ApimUtils.ConfigurationFileName)); Directory.Delete(folderPath, true); tags.Remove(tag); } foreach (var tag in tags) { if (!IsInSync(tag.Value, authoritiveTags[tag.Key])) { System.Console.WriteLine($"OUT OF SYNC: {tag.Value.Id}"); //Ensure it needs to be Sync'd var updatedTag = Sync(tag.Value, authoritiveTags[tag.Key]); //Now Save var json = JsonSerialisation.Serialise(updatedTag); var filePath = $"{folder}\\{_tagsFolder}\\{tag.Key}\\{ApimUtils.ConfigurationFileName}"; //Path.Combine(folder1, @"\api-management\products", product.Key, ApimUtils.ConfigurationFileName); await File.WriteAllTextAsync(filePath, json); } else { System.Console.WriteLine($"Tag {tag.Value.Id} Is in sync"); } } }
public static async Task CompareAndSync(string folder, Dictionary <string, ApiRelease> entities, Dictionary <string, ApiRelease> authoritive) { var newEntities = authoritive.Keys.Except(entities.Keys); foreach (var release in newEntities) { var t = authoritive[release]; //Add New Tag to Existing var folderPath = $"{folder}\\{_folderPart}\\{release}"; Directory.CreateDirectory(folderPath); var json = JsonSerialisation.Serialise(t); var filePath = $"{folderPath}\\{ApimUtils.ConfigurationFileName}"; System.Console.WriteLine($"Writing {filePath}"); await File.WriteAllTextAsync(filePath, json); } var oldEntities = entities.Keys.Except(authoritive.Keys); foreach (var release in oldEntities) { //Remove Products var folderPath = Path.Combine($"{folder}\\{_folderPart}\\", release); File.Delete(Path.Combine(folderPath, ApimUtils.ConfigurationFileName)); Directory.Delete(folderPath, true); entities.Remove(release); } foreach (var entity in entities) { if (!IsInSync(entity.Value, authoritive[entity.Key])) { System.Console.WriteLine($"OUT OF SYNC: {entity.Value.Id}"); //Ensure it needs to be Sync'd var updatedTag = Sync(entity.Value, authoritive[entity.Key]); //Now Save var json = JsonSerialisation.Serialise(updatedTag); var filePath = $"{folder}\\{_folderPart}\\{entity.Key}\\{ApimUtils.ConfigurationFileName}"; //Path.Combine(folder1, @"\api-management\products", product.Key, ApimUtils.ConfigurationFileName); await File.WriteAllTextAsync(filePath, json); } else { System.Console.WriteLine($"{entity.Value.Id} Is in sync"); } } }
public static async Task CompareAndSyncProducts(string folder, Dictionary <string, Product> products, Dictionary <string, Product> authoritiveProducts) { var newProducts = authoritiveProducts.Keys.Except(products.Keys); foreach (var product in newProducts) { var p = authoritiveProducts[product]; p.RefsGroups = new List <string>(); // Clear groups //Add New Product to Existing var folderPath = $"{folder}\\api-management\\products\\{product}"; Directory.CreateDirectory(folderPath); var json = JsonSerialisation.Serialise(p); var filePath = $"{folderPath}\\{ApimUtils.ConfigurationFileName}"; System.Console.WriteLine($"Writing {filePath}"); await File.WriteAllTextAsync(filePath, json); if (!string.IsNullOrEmpty(p.RefDescription)) { System.Console.WriteLine("Writing Ref File"); await File.WriteAllTextAsync(Path.Combine(folder, p.RefDescription), p.Description); } } var oldProducts = products.Keys.Except(authoritiveProducts.Keys); foreach (var product in oldProducts) { //Remove Products var p = products[product]; if (!string.IsNullOrEmpty(p.RefDescription)) { var filePath = Path.Combine(folder, p.RefDescription); System.Console.WriteLine($"Deleting {filePath}"); File.Delete(filePath); } var folderPath = Path.Combine($"{folder}\\api-management\\products\\", product); File.Delete(Path.Combine(folderPath, ApimUtils.ConfigurationFileName)); Directory.Delete(folderPath); products.Remove(product); } foreach (var product in products) { if (!ProductSync.IsInSync(product.Value, authoritiveProducts[product.Key], false)) { System.Console.WriteLine($"OUT OF SYNC: {product.Value.Id}"); //Ensure it needs to be Sync'd var updatedPropduct = ProductSync.Sync(product.Value, authoritiveProducts[product.Key], false); //Now Save var json = JsonSerialisation.Serialise(updatedPropduct); var filePath = $"{folder}\\api-management\\products\\{product.Key}\\{ApimUtils.ConfigurationFileName}"; //Path.Combine(folder1, @"\api-management\products", product.Key, "configuration.json"); await File.WriteAllTextAsync(filePath, json); } else { System.Console.WriteLine($"Product {product.Value.Id} Is in sync"); } //Check Ref if (product.Value.Description != authoritiveProducts[product.Key].Description) { System.Console.WriteLine($"Definition Out of date"); var filePath = Path.Combine(folder, product.Value.RefDescription); await File.WriteAllTextAsync(filePath, authoritiveProducts[product.Key].Description); } } }
public static async Task CompareAndSync(string folder, Dictionary <string, Api> entities, string authoritiveFolder, Dictionary <string, Api> authoritive) { var newEntities = authoritive.Keys.Except(entities.Keys); foreach (var entity in newEntities) { var t = authoritive[entity]; //Add New Tag to Existing var folderPath = $"{folder}\\{_folderPart}\\{entity}"; Directory.CreateDirectory(folderPath); var json = JsonSerialisation.Serialise(t); var filePath = $"{folderPath}\\{ApimUtils.ConfigurationFileName}"; System.Console.WriteLine($"Writing {filePath}"); await File.WriteAllTextAsync(filePath, json); //Check Refs if (!string.IsNullOrWhiteSpace(t.RefDescription)) { //Check Description await CreateRef(t.RefDescription, folder, authoritiveFolder); } //Operations foreach (var o in t.Operations) { if (!string.IsNullOrWhiteSpace(o.RefDescription)) { // Check Operation Description await CreateRef(o.RefDescription, folder, authoritiveFolder); } if (!string.IsNullOrWhiteSpace(o.RefPolicy)) { // Check Operation Policy await CreateRef(o.RefPolicy, folder, authoritiveFolder); } if (!string.IsNullOrWhiteSpace(o.Request.RefDescription)) { // Check Operation Request Desicription await CreateRef(o.Request.RefDescription, folder, authoritiveFolder); } foreach (var r in o.Request.Representations) { if (!string.IsNullOrEmpty(r.RefSample)) { // Check Operation Request Representation Samples await CreateRef(r.RefSample, folder, authoritiveFolder); } } foreach (var response in o.Responses) { if (!string.IsNullOrEmpty(response.RefDescription)) { //Check Operation Response Description await CreateRef(response.RefDescription, folder, authoritiveFolder); } foreach (var r in response.Representations) { if (!string.IsNullOrEmpty(r.RefSample)) { // Check Operation Response Representation Samples await CreateRef(r.RefSample, folder, authoritiveFolder); } } } } //Check Api Scheamas foreach (var s in t.ApiSchemas) { if (!string.IsNullOrEmpty(s.RefDocumentValue)) { //Check Api Schema Document Value await CreateRef(s.RefDocumentValue, folder, authoritiveFolder); } } } var oldEntities = entities.Keys.Except(authoritive.Keys); foreach (var release in oldEntities) { //Remove Products var folderPath = Path.Combine($"{folder}\\{_folderPart}\\", release); File.Delete(Path.Combine(folderPath, ApimUtils.ConfigurationFileName)); Directory.Delete(folderPath, true); entities.Remove(release); } foreach (var entity in entities) { var a = authoritive[entity.Key]; var e = entity.Value; if (!entity.Value.Equals(a)) { System.Console.WriteLine($"OUT OF SYNC: {entity.Value.Id}"); //Ensure it needs to be Sync'd //Todo Check for Removed Entities var updatedApi = Sync(e, a); //Now Save var json = JsonSerialisation.Serialise(updatedApi); var filePath = $"{folder}\\{_folderPart}\\{entity.Key}\\{ApimUtils.ConfigurationFileName}"; //Path.Combine(folder1, @"\api-management\products", product.Key, ApimUtils.ConfigurationFileName); await File.WriteAllTextAsync(filePath, json); e = updatedApi; } else { System.Console.WriteLine($"{entity.Value.Id} Is in sync"); } //Check Refs if (!string.IsNullOrWhiteSpace(e.RefDescription)) { //Check Description await SyncRef(e.RefDescription, folder, authoritiveFolder); } //Operations foreach (var o in e.Operations) { if (!string.IsNullOrWhiteSpace(o.RefDescription)) { // Check Operation Description await SyncRef(o.RefDescription, folder, authoritiveFolder); } if (!string.IsNullOrWhiteSpace(o.RefPolicy)) { // Check Operation Policy await SyncRef(o.RefPolicy, folder, authoritiveFolder); } if (!string.IsNullOrWhiteSpace(o.Request.RefDescription)) { // Check Operation Request Desicription await SyncRef(o.Request.RefDescription, folder, authoritiveFolder); } foreach (var r in o.Request.Representations) { if (!string.IsNullOrEmpty(r.RefSample)) { // Check Operation Request Representation Samples await SyncRef(r.RefSample, folder, authoritiveFolder); } } foreach (var response in o.Responses) { if (!string.IsNullOrEmpty(response.RefDescription)) { //Check Operation Response Description await SyncRef(response.RefDescription, folder, authoritiveFolder); } foreach (var r in response.Representations) { if (!string.IsNullOrEmpty(r.RefSample)) { // Check Operation Response Representation Samples await SyncRef(r.RefSample, folder, authoritiveFolder); } } } } //Check Api Scheamas foreach (var s in e.ApiSchemas) { if (!string.IsNullOrEmpty(s.RefDocumentValue)) { //Check Api Schema Document Value await SyncRef(s.RefDocumentValue, folder, authoritiveFolder); } } } }