Skip to content

Commit

Permalink
ENH: Implement async in all public functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kayqueGovetri committed Jun 8, 2024
1 parent a6a8a58 commit 961edcd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions BotCity.Maestro.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<OutputType>Library</OutputType>
<Version>1.0.8</Version>
<PackageVersion>1.0.8</PackageVersion>
<Version>1.0.9</Version>
<PackageVersion>1.0.9</PackageVersion>
<PackageId>BotCity.Maestro.SDK</PackageId>
<PackageTags>botcity sdk automation automation desktop</PackageTags>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
32 changes: 16 additions & 16 deletions botcity/maestro/BotMaestroSDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private Dictionary<string, object> ToDictionary(dynamic item)
return dictionary;
}

public async Task Login(string server = "", string login = "", string key = "") {
public async Task LoginAsync(string server = "", string login = "", string key = "") {
using (HttpClient client = new HttpClient()) {
try {
var data = new { login = _login, key = _key };
Expand Down Expand Up @@ -262,7 +262,7 @@ public async Task<AutomationTask> FinishTaskAsync(string taskId, FinishStatusEnu
}
}

public async Task<AutomationTask> InterruptTask(string taskId) {
public async Task<AutomationTask> InterruptTaskAsync(string taskId) {
string url = $"{_server}/api/v2/task/{taskId}";
var data = new Dictionary<string, object>
{
Expand All @@ -284,7 +284,7 @@ public async Task<AutomationTask> InterruptTask(string taskId) {
}
}

public async Task<AutomationTask> RestartTask(string taskId) {
public async Task<AutomationTask> RestartTaskAsync(string taskId) {
string url = $"{_server}/api/v2/task/{taskId}";
var data = new Dictionary<string, object>
{
Expand All @@ -306,7 +306,7 @@ public async Task<AutomationTask> RestartTask(string taskId) {
}
}

public async Task<Alert> CreateAlert(string taskId, string title, string message, AlertTypeEnum alertType)
public async Task<Alert> CreateAlertAsync(string taskId, string title, string message, AlertTypeEnum alertType)
{
string url = $"{_server}/api/v2/alerts";
var data = new Dictionary<string, object>
Expand All @@ -332,7 +332,7 @@ public async Task<Alert> CreateAlert(string taskId, string title, string message
}
}

public async Task SendMessage(List<string> emails, List<string> logins, string subject, string body, MessageTypeEnum messageType, List<string> groups = null)
public async Task SendMessageAsync(List<string> emails, List<string> logins, string subject, string body, MessageTypeEnum messageType, List<string> groups = null)
{
string url = $"{_server}/api/v2/message";
var data = new Dictionary<string, object>
Expand All @@ -357,7 +357,7 @@ public async Task SendMessage(List<string> emails, List<string> logins, string s
}
}

public async Task<string> GetCredential(string label, string key) {
public async Task<string> GetCredentialAsync(string label, string key) {
string url = $"{_server}/api/v2/credential/{label}/key/{key}";

using (var client = new HttpClient())
Expand Down Expand Up @@ -415,7 +415,7 @@ private async Task<bool> GetCredentialByLabel(string label) {
}
}

public async Task CreateCredential(string label, string key, string value) {
public async Task CreateCredentialAsync(string label, string key, string value) {
string url = $"{_server}/api/v2/credential/{label}/key";
bool existCredential = await this.GetCredentialByLabel(label);
if (!existCredential) {
Expand Down Expand Up @@ -451,7 +451,7 @@ private Dictionary<string, string> MergeDictionaries(Dictionary<string, string>
return result;
}

public async Task CreateError(Exception exception, string taskId, string screenshotPath = "", Dictionary<string, object> tags = null, List<string> attachments = null) {
public async Task CreateErrorAsync(Exception exception, string taskId, string screenshotPath = "", Dictionary<string, object> tags = null, List<string> attachments = null) {
string url = $"{_server}/api/v2/error";
Dictionary<string, string> defaultTags = this.GetDefaultErrorTags();
if (tags != null) {
Expand Down Expand Up @@ -620,7 +620,7 @@ public async Task NewLogEntryAsync(string label, Dictionary<string, object> valu
}
}

public async Task<List<Entry>> GetLog(string label, string date = null) {
public async Task<List<Entry>> GetLogAsync(string label, string date = null) {
string url = $"{_server}/api/v2/log/{label}";
int days = 365;
if (!string.IsNullOrEmpty(date)) {
Expand Down Expand Up @@ -665,8 +665,8 @@ public async Task DeleteLogAsync(string label) {
}
}

public async Task PostArtifact(string taskId, string name, string filepath) {
string artifact_id = await this.CreateArtifact(taskId, name, filepath);
public async Task PostArtifactAsync(string taskId, string name, string filepath) {
string artifact_id = await this.CreateArtifactAsync(taskId, name, filepath);
string url = $"{_server}/api/v2/artifact/log/{artifact_id}";
filepath = Environment.ExpandEnvironmentVariables(filepath);
filepath = Path.GetFullPath(filepath);
Expand Down Expand Up @@ -704,7 +704,7 @@ public async Task PostArtifact(string taskId, string name, string filepath) {
}
}

private async Task<string> CreateArtifact(string taskId, string name, string filename) {
private async Task<string> CreateArtifactAsync(string taskId, string name, string filename) {
string url = $"{_server}/api/v2/artifact";
var data = new Dictionary<string, object>
{
Expand All @@ -726,7 +726,7 @@ private async Task<string> CreateArtifact(string taskId, string name, string fil
return artifactId;
}

public async Task<(string filename, byte[] fileContent)> GetArtifact(string artifactId) {
public async Task<(string filename, byte[] fileContent)> GetArtifactAsync(string artifactId) {
string url = $"{_server}/api/v2/artifact/{artifactId}";

using (var client = new HttpClient())
Expand All @@ -747,7 +747,7 @@ private async Task<string> CreateArtifact(string taskId, string name, string fil
}
}

public async Task<List<Artifact>> ListArtifact(int days = 7) {
public async Task<List<Artifact>> ListArtifactAsync(int days = 7) {
string url = $"{_server}/api/v2/artifact?size=5&page=0&sort=dateCreation,desc&days={days}";
var artifacts = new List<Artifact>();

Expand Down Expand Up @@ -776,7 +776,7 @@ public async Task<List<Artifact>> ListArtifact(int days = 7) {
}
}

public async Task<Datapool> CreateDatapool(Datapool pool)
public async Task<Datapool> CreateDatapoolAsync(Datapool pool)
{
string url = $"{_server}/api/v2/datapool";

Expand All @@ -793,7 +793,7 @@ public async Task<Datapool> CreateDatapool(Datapool pool)
}
}

public async Task<Datapool> GetDatapool(string label)
public async Task<Datapool> GetDatapoolAsync(string label)
{
string url = $"{_server}/api/v2/datapool/{label}";

Expand Down
16 changes: 8 additions & 8 deletions botcity/maestro/datapool/Datapool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public async Task<bool> DeactivateAsync() {
return await this.ActiveAsync(false);
}

public async Task<bool> IsActive() {
public async Task<bool> IsActiveAsync() {
string url = $"{this.Maestro.GetServer()}/api/v2/datapool/{this.Label}";

using (var client = new HttpClient()) {
Expand All @@ -175,7 +175,7 @@ public async Task<bool> IsActive() {
}
}

public async Task<Summary> GetSummary() {
public async Task<Summary> GetSummaryAsync() {
string url = $"{this.Maestro.GetServer()}/api/v2/datapool/{this.Label}/summary";

using (var client = new HttpClient()) {
Expand All @@ -189,16 +189,16 @@ public async Task<Summary> GetSummary() {
}
}

public async Task<bool> IsEmpty() {
Summary summary = await this.GetSummary();
public async Task<bool> IsEmptyAsync() {
Summary summary = await this.GetSummaryAsync();
if(summary.CountPending == 0) {
return true;
}
return false;
}

public async Task<bool> HasNext() {
return !(await this.IsEmpty());
public async Task<bool> HasNextAsync() {
return !(await this.IsEmptyAsync());
}

private async void verifyResponse(HttpResponseMessage data, string error) {
Expand Down Expand Up @@ -253,7 +253,7 @@ public async Task<DatapoolEntry> NextAsync(string? taskId = null) {
}
}

public async Task<DatapoolEntry> GetEntry(string entryId) {
public async Task<DatapoolEntry> GetEntryAsync(string entryId) {
string url = $"{this.Maestro.GetServer()}/api/v2/datapool/{this.Label}/entry/{entryId}";

using (var client = new HttpClient()) {
Expand All @@ -271,7 +271,7 @@ public async Task<DatapoolEntry> GetEntry(string entryId) {
return entry;
}
}
public async Task<DatapoolEntry> CreateEntry(DatapoolEntry entry) {
public async Task<DatapoolEntry> CreateEntryAsync(DatapoolEntry entry) {
string url = $"{this.Maestro.GetServer()}/api/v2/datapool/{this.Label}/push";
var data = JsonConvert.SerializeObject(entry.ToJson());
using (var client = new HttpClient()) {
Expand Down
8 changes: 4 additions & 4 deletions botcity/maestro/datapool/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Dictionary<string, object> JsonToUpdate() {
return data;
}

public async Task<DatapoolEntry> Save(string? taskId = null) {
public async Task<DatapoolEntry> SaveAsync(string? taskId = null) {
string url = $"{this.Maestro.GetServer()}/api/v2/datapool/{this.DatapoolLabel}/entry/{this.EntryId}";
var data = JsonConvert.SerializeObject(this.JsonToUpdate());
var dataDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(data);
Expand All @@ -160,13 +160,13 @@ public async Task<DatapoolEntry> Save(string? taskId = null) {

private async Task Report(StateEntryEnum state) {
this.State = state;
await this.Save();
await this.SaveAsync();
}
public async Task ReportDone() {
public async Task ReportDoneAsync() {
await this.Report(StateEntryEnum.DONE);
}

public async Task ReportError() {
public async Task ReportErrorAsync() {
await this.Report(StateEntryEnum.ERROR);
}

Expand Down

0 comments on commit 961edcd

Please sign in to comment.