/// <summary> /// Retrieves metadata about the dataElement /// </summary> protected override async Task OnExecuteAsync(CommandLineApplication app) { if (string.IsNullOrEmpty(Program.Environment)) { Console.WriteLine("Please set the environment context before using this command."); Console.WriteLine("Update environment using cmd: settings update -e [environment] \n "); return; } string instanceGuid = string.Empty; if (!string.IsNullOrEmpty(InstanceGuid) || !string.IsNullOrEmpty(InstanceId)) { instanceGuid = InstanceGuid ?? InstanceId.Split('/')[1]; } if (ListVersions && (string.IsNullOrEmpty(Org) || string.IsNullOrEmpty(App) || string.IsNullOrEmpty(instanceGuid))) { Console.WriteLine("Please provide org, app and instanceGuid to retrieve previous versions when listing deleted data elements."); return; } if (!ExcludeMetadata) { string metadata = await GetMetadata(DataGuid, instanceGuid); metadata = string.IsNullOrEmpty(metadata) ? "No metadata found." : metadata; Console.WriteLine("-----------------------------------------------------------------------"); Console.WriteLine($"Metadata for data element: {instanceGuid}/{DataGuid}"); Console.WriteLine("-----------------------------------------------------------------------"); Console.WriteLine(metadata); Console.WriteLine(string.Empty); } if (ListVersions) { List <string> versions = await GetVersions(Org, App, instanceGuid, DataGuid); Console.WriteLine("-----------------------------------------------------------------------"); Console.WriteLine($"Versions of data element: {instanceGuid}/{DataGuid}"); Console.WriteLine("-----------------------------------------------------------------------"); if (versions.Count == 0) { Console.WriteLine($"No version history found."); } else { foreach (string version in versions) { Console.WriteLine(version); } } Console.WriteLine(string.Empty); } CleanUp(); }
/// <summary> /// Undeletes the given data element /// </summary> protected override async Task OnExecuteAsync(CommandLineApplication app) { if (string.IsNullOrEmpty(Program.Environment)) { Console.WriteLine("Please set the environment context before using this command."); Console.WriteLine("Update environment using cmd: settings update -e [environment] \n "); CleanUp(); return; } string instanceGuid = string.Empty; if (!string.IsNullOrEmpty(InstanceGuid) || !string.IsNullOrEmpty(InstanceId)) { instanceGuid = InstanceGuid ?? InstanceId.Split('/')[1]; } if (string.IsNullOrEmpty(instanceGuid)) { Console.WriteLine("One of the fields --instanceGuid or --instanceId are required."); CleanUp(); return; } if (await _blobService.UndeleteBlob(Org, App, instanceGuid, DataGuid)) { DataElement backup = await _blobService.GetDataElementBackup(instanceGuid, DataGuid); if (backup != null && await _cosmosService.SaveDataElement(backup)) { Console.WriteLine("-----------------------------------------------------------------------"); Console.WriteLine($"Undelete successful. Data element restored."); Console.WriteLine(JsonConvert.SerializeObject(backup, Formatting.Indented)); Console.WriteLine("-----------------------------------------------------------------------"); } else { Console.WriteLine("-----------------------------------------------------------------------"); Console.WriteLine($"Undelete unsuccessful. Data element was not fully restored."); Console.WriteLine($"Error occured when retrieving backup and writing metadata to cosmos for"); Console.WriteLine($"Please check state manually for: {Org}/{App}/{instanceGuid}/{DataGuid}. "); Console.WriteLine("-----------------------------------------------------------------------"); } } else { Console.WriteLine("-----------------------------------------------------------------------"); Console.WriteLine($"Undelete unsuccessful. Data element was not restored."); Console.WriteLine($"Error occured when undeleting data element in blob storage."); Console.WriteLine($"Please check state manually for: {Org}/{App}/{instanceGuid}/{DataGuid}. "); Console.WriteLine("-----------------------------------------------------------------------"); } CleanUp(); }
/// <inheritdoc/> protected override async Task OnExecuteAsync(CommandLineApplication app) { if (string.IsNullOrEmpty(Program.Environment)) { Console.WriteLine("Please set the environment context before using this command."); Console.WriteLine("Update environment using cmd: settings update -e [environment] \n "); return; } if (string.IsNullOrEmpty(InstanceId) && string.IsNullOrEmpty(InstanceGuid)) { Console.WriteLine("Please provide an instanceId or instanceGuid"); return; } string instanceGuid = InstanceGuid ?? InstanceId.Split('/')[1]; try { if (await _blobService.RestoreBlob(Org, App, instanceGuid, DataGuid, RestoreTimestamp)) { DataElement backup = await _blobService.GetDataElementBackup(instanceGuid, DataGuid, RestoreTimestamp); if (backup != null && await _cosmosService.ReplaceDataElement(backup)) { Console.WriteLine("-----------------------------------------------------------------------"); Console.WriteLine($"Restore successful. Data element restored."); Console.WriteLine(JsonConvert.SerializeObject(backup, Formatting.Indented)); Console.WriteLine("-----------------------------------------------------------------------"); } else { Console.WriteLine("-----------------------------------------------------------------------"); Console.WriteLine($"Restore was unsuccessful. Data element was not fully restored."); Console.WriteLine($"Error occured when retrieving backup and writing metadata to cosmos for"); Console.WriteLine($"Please check state manually for: {Org}/{App}/{instanceGuid}/{DataGuid}. "); Console.WriteLine("-----------------------------------------------------------------------"); } } else { Console.WriteLine("-----------------------------------------------------------------------"); Console.WriteLine($"Restore was unsuccessful. Data element was not restored."); Console.WriteLine($"Error occured when retrieving snapshot of data element in blob storage."); Console.WriteLine($"Please check state manually for: {Org}/{App}/{instanceGuid}/{DataGuid}. "); Console.WriteLine("-----------------------------------------------------------------------"); } } catch (Exception e) { Console.WriteLine(e); } }
/// <inheritdoc/> protected override async Task OnExecuteAsync(CommandLineApplication app) { if (string.IsNullOrEmpty(Program.Environment)) { Console.WriteLine("Please set the environment context before using this command."); Console.WriteLine("Update environment using cmd: settings update -e [environment] \n "); return; } if (string.IsNullOrEmpty(InstanceId) && string.IsNullOrEmpty(InstanceGuid)) { Console.WriteLine("Please provide an instanceId or instanceGuid"); return; } if ((DataState.Equals("deleted") || DataState.Equals("all")) && (string.IsNullOrEmpty(Org) || string.IsNullOrEmpty(App))) { Console.WriteLine("Please provide org and app when listing deleted data elements."); return; } string instanceGuid = InstanceGuid ?? InstanceId.Split('/')[1]; switch (DataState.ToLower()) { case "deleted": await ListDataElements(Org, App, instanceGuid, ElementState.Deleted); break; case "all": await ListDataElements(Org, App, instanceGuid, ElementState.All); break; case "active": default: await ListActiveDataElements(instanceGuid); break; } CleanUp(); }