Make WCF interface async

This commit is contained in:
stackia
2016-07-30 11:51:00 +08:00
parent 48eae1be1a
commit fbb24506e2
2 changed files with 10 additions and 9 deletions

View File

@@ -453,7 +453,7 @@ namespace ArchiSteamFarm {
}
Logging.LogGenericInfo("Command sent: " + arg);
Logging.LogGenericInfo("Response received: " + WCF.SendCommand(arg));
Logging.LogGenericInfo("Response received: " + WCF.SendCommand(arg).Result);
break;
}
}

View File

@@ -27,12 +27,13 @@ using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Threading.Tasks;
namespace ArchiSteamFarm {
[ServiceContract]
internal interface IWCF {
[OperationContract]
string HandleCommand(string input);
Task<string> HandleCommand(string input);
}
internal sealed class WCF : IWCF, IDisposable {
@@ -53,7 +54,7 @@ namespace ArchiSteamFarm {
URL = "http://" + Program.GlobalConfig.WCFHostname + ":" + Program.GlobalConfig.WCFPort + "/ASF";
}
public string HandleCommand(string input) {
public async Task<string> HandleCommand(string input) {
if (string.IsNullOrEmpty(input)) {
Logging.LogNullError(nameof(input));
return null;
@@ -69,7 +70,7 @@ namespace ArchiSteamFarm {
}
string command = "!" + input;
string output = bot.Response(Program.GlobalConfig.SteamOwnerID, command).Result; // TODO: This should be asynchronous
string output = await bot.Response(Program.GlobalConfig.SteamOwnerID, command).ConfigureAwait(false);
Logging.LogGenericInfo("Answered to command: " + input + " with: " + output);
return output;
@@ -124,7 +125,7 @@ namespace ArchiSteamFarm {
ServiceHost = null;
}
internal string SendCommand(string input) {
internal async Task<string> SendCommand(string input) {
if (string.IsNullOrEmpty(input)) {
Logging.LogNullError(nameof(input));
return null;
@@ -134,21 +135,21 @@ namespace ArchiSteamFarm {
Client = new Client(new BasicHttpBinding(), new EndpointAddress(URL));
}
return Client.HandleCommand(input);
return await Client.HandleCommand(input).ConfigureAwait(false);
}
}
internal sealed class Client : ClientBase<IWCF>, IWCF {
internal sealed class Client : ClientBase<IWCF> {
internal Client(Binding binding, EndpointAddress address) : base(binding, address) { }
public string HandleCommand(string input) {
public async Task<string> HandleCommand(string input) {
if (string.IsNullOrEmpty(input)) {
Logging.LogNullError(nameof(input));
return null;
}
try {
return Channel.HandleCommand(input);
return await Channel.HandleCommand(input).ConfigureAwait(false);
} catch (Exception e) {
Logging.LogGenericException(e);
return null;