public override Task <CommandResult> ExecuteAsync(CancellationToken cancel) { // TODO: Do something here. Console.WriteLine($"operation {operationName}, params {String.Join(", ", this.parameters.ToArray())} ({this.parameters.Count})"); IQueryJson parameters = this.PrepareQueryJson(); try { string result = this.Api.InvokeMethod(parameters, this.timeoutForLongOperation).ConfigureAwait(false).GetAwaiter().GetResult(); if (!string.IsNullOrWhiteSpace(result)) { NLog.Default.Information(result); Console.WriteLine(result); } else { NLog.Default.Information("returned"); } } catch (Exception ex) { NLog.Default.Error(ex, "Failed to query method."); return(Task.FromResult(CommandResult.RuntimeFailure)); } return(Task.FromResult(CommandResult.Success)); }
private IQueryJson PrepareQueryJson() { if (!string.IsNullOrWhiteSpace(this.Arguments.ConfigurationFile)) { if (!File.Exists(this.Arguments.ConfigurationFile)) { throw new ApplicationException("Configuration file does not exist."); } string json = File.ReadAllText(this.Arguments.ConfigurationFile); return(JsonSerializer.Deserialize <QueryJsonNamed>(json)); } IQueryJson result = null; if (!string.IsNullOrWhiteSpace(this.jParameters)) { result = new QueryJsonNamed(); ((QueryJsonNamed)result).Parameters = JsonSerializer.Deserialize <List <QueryJsonNamed.NamedOperationParameters> >(this.jParameters); } else if (this.parameters.Any()) { result = new QueryJsonIndexed(); List <string> list = this.parameters.ToList(); for (int i = 0; i < this.parameters.Count(); i++) { ((QueryJsonIndexed)result).Parameters.Add(new QueryJsonIndexed.IndexedOperationParameters(i, list[i])); } } else { result = new QueryJsonIndexed(); } if (!string.IsNullOrWhiteSpace(this.operationName)) { result.Operation = this.operationName; } return(result); }
public override Task <CommandResult> ExecuteAsync(CancellationToken cancel) { string call = $"operation {operationName}, {this.parameters.Count} param(s): [{String.Join(", ", this.parameters.ToArray())}]"; Console.WriteLine(call); NLog.Default.Information(call); if (!this.Api.IsConnected()) { NLog.Default.Error($"Not Connected while calling {call}"); Console.WriteLine("Not connected to host (hint: make sure your node is started, or, if not running local, try with --host='your.node.ip')"); return(Task.FromResult(CommandResult.RuntimeFailure)); } try { IQueryJson parameters = this.PrepareQueryJson(); string result = this.Api.InvokeMethod(parameters, this.timeoutForLongOperation).ConfigureAwait(false) .GetAwaiter().GetResult(); if (!string.IsNullOrWhiteSpace(result)) { NLog.Default.Information(result); Console.WriteLine(result); } else { NLog.Default.Information("(empty string)"); Console.WriteLine("(empty string)"); } } catch (Exception ex) { NLog.Default.Error(ex, "Failed to query method."); Console.WriteLine("Failed to query method. Look at the log for more information."); return(Task.FromResult(CommandResult.RuntimeFailure)); } return(Task.FromResult(CommandResult.Success)); }