mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Fix WCF
This commit is contained in:
@@ -42,7 +42,7 @@ namespace ArchiSteamFarm {
|
||||
|
||||
private static readonly object ConsoleLock = new object();
|
||||
private static readonly ManualResetEventSlim ShutdownResetEvent = new ManualResetEventSlim(false);
|
||||
private static readonly WCF WCF = new WCF(ASF.ArchiLogger);
|
||||
private static readonly WCF WCF = new WCF();
|
||||
|
||||
internal static bool IsRunningAsService { get; private set; }
|
||||
internal static EMode Mode { get; private set; } = EMode.Normal;
|
||||
|
||||
@@ -41,21 +41,11 @@ namespace ArchiSteamFarm {
|
||||
internal sealed class WCF : IWCF, IDisposable {
|
||||
private static string URL = "http://localhost:1242/ASF";
|
||||
|
||||
private readonly ArchiLogger ArchiLogger;
|
||||
|
||||
private ServiceHost ServiceHost;
|
||||
private Client Client;
|
||||
|
||||
internal bool IsServerRunning => ServiceHost != null;
|
||||
|
||||
internal WCF(ArchiLogger archiLogger) {
|
||||
if (archiLogger == null) {
|
||||
throw new ArgumentNullException(nameof(archiLogger));
|
||||
}
|
||||
|
||||
ArchiLogger = archiLogger;
|
||||
}
|
||||
|
||||
internal static void Init() {
|
||||
if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHostname)) {
|
||||
Program.GlobalConfig.WCFHostname = Program.GetUserInput(SharedInfo.EUserInputType.WCFHostname);
|
||||
@@ -69,7 +59,7 @@ namespace ArchiSteamFarm {
|
||||
|
||||
public string HandleCommand(string input) {
|
||||
if (string.IsNullOrEmpty(input)) {
|
||||
ArchiLogger.LogNullError(nameof(input));
|
||||
ASF.ArchiLogger.LogNullError(nameof(input));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -85,7 +75,7 @@ namespace ArchiSteamFarm {
|
||||
string command = "!" + input;
|
||||
string output = bot.Response(Program.GlobalConfig.SteamOwnerID, command).Result; // TODO: This should be asynchronous
|
||||
|
||||
ArchiLogger.LogGenericInfo("Answered to command: " + input + " with: " + output);
|
||||
ASF.ArchiLogger.LogGenericInfo("Answered to command: " + input + " with: " + output);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -101,7 +91,7 @@ namespace ArchiSteamFarm {
|
||||
return;
|
||||
}
|
||||
|
||||
ArchiLogger.LogGenericInfo("Starting WCF server...");
|
||||
ASF.ArchiLogger.LogGenericInfo("Starting WCF server...");
|
||||
|
||||
try {
|
||||
ServiceHost = new ServiceHost(typeof(WCF), new Uri(URL));
|
||||
@@ -115,11 +105,11 @@ namespace ArchiSteamFarm {
|
||||
|
||||
ServiceHost.Open();
|
||||
} catch (Exception e) {
|
||||
ArchiLogger.LogGenericException(e);
|
||||
ASF.ArchiLogger.LogGenericException(e);
|
||||
return;
|
||||
}
|
||||
|
||||
ArchiLogger.LogGenericInfo("WCF server ready!");
|
||||
ASF.ArchiLogger.LogGenericInfo("WCF server ready!");
|
||||
}
|
||||
|
||||
internal void StopServer() {
|
||||
@@ -131,7 +121,7 @@ namespace ArchiSteamFarm {
|
||||
try {
|
||||
ServiceHost.Close();
|
||||
} catch (Exception e) {
|
||||
ArchiLogger.LogGenericException(e);
|
||||
ASF.ArchiLogger.LogGenericException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,12 +130,12 @@ namespace ArchiSteamFarm {
|
||||
|
||||
internal string SendCommand(string input) {
|
||||
if (string.IsNullOrEmpty(input)) {
|
||||
ArchiLogger.LogNullError(nameof(input));
|
||||
ASF.ArchiLogger.LogNullError(nameof(input));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Client == null) {
|
||||
Client = new Client(new BasicHttpBinding(), new EndpointAddress(URL), ArchiLogger);
|
||||
Client = new Client(new BasicHttpBinding(), new EndpointAddress(URL));
|
||||
}
|
||||
|
||||
return Client.HandleCommand(input);
|
||||
@@ -165,26 +155,18 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
internal sealed class Client : ClientBase<IWCF> {
|
||||
private readonly ArchiLogger ArchiLogger;
|
||||
|
||||
internal Client(Binding binding, EndpointAddress address, ArchiLogger archiLogger) : base(binding, address) {
|
||||
if (archiLogger == null) {
|
||||
throw new ArgumentNullException(nameof(archiLogger));
|
||||
}
|
||||
|
||||
ArchiLogger = archiLogger;
|
||||
}
|
||||
internal Client(Binding binding, EndpointAddress address) : base(binding, address) { }
|
||||
|
||||
internal string HandleCommand(string input) {
|
||||
if (string.IsNullOrEmpty(input)) {
|
||||
ArchiLogger.LogNullError(nameof(input));
|
||||
ASF.ArchiLogger.LogNullError(nameof(input));
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Channel.HandleCommand(input);
|
||||
} catch (Exception e) {
|
||||
ArchiLogger.LogGenericException(e);
|
||||
ASF.ArchiLogger.LogGenericException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user