@@ -13,7 +13,7 @@ namespace ASFui
1313{
1414 internal static class Util
1515 {
16- private static readonly NetTcpBinding Binding = new NetTcpBinding { SendTimeout = new TimeSpan ( 0 , 30 , 0 ) , Security = { Mode = SecurityMode . None } } ;
16+ private static readonly NetTcpBinding Binding = new NetTcpBinding { SendTimeout = new TimeSpan ( 0 , 30 , 0 ) , Security = { Mode = SecurityMode . None } } ;
1717
1818 public static bool CheckBinary ( )
1919 {
@@ -22,11 +22,17 @@ public static bool CheckBinary()
2222
2323 public static string SendCommand ( string command )
2424 {
25- using ( var asfClient = new Client ( Binding , new EndpointAddress ( GetEndpointAddress ( ) ) ) )
26- {
27- return asfClient . HandleCommand ( command ) ;
28- }
29- }
25+ string adress ;
26+ if ( ( adress = GetEndpointAddress ( ) ) . StartsWith ( "net" ) ) {
27+ using ( var asfClient = new Client ( Binding , new EndpointAddress ( adress ) ) ) {
28+ return asfClient . HandleCommand ( command ) ;
29+ }
30+ }
31+
32+ using ( WebClient webclient = new WebClient ( ) ) {
33+ return webclient . DownloadString ( adress + "?command=" + command ) ;
34+ }
35+ }
3036
3137 public static string GenerateCommand ( string command , string user , string args = "" )
3238 {
@@ -49,21 +55,22 @@ public static string GetEndpointAddress()
4955 JObject . Parse (
5056 File . ReadAllText ( Path . GetDirectoryName ( Settings . Default . ASFBinary ) + @"/config/ASF.json" ) ) ;
5157
52- var hostname = "127.0.0.1" ;
53- var port = "1242" ;
54- try
55- {
56- hostname = json [ "WCFHost" ] . ToString ( ) ;
57- }
58- catch
59- {
60- try {
61- hostname = json [ "WCFHostname" ] . ToString ( ) ;
62- } catch { /* Ignore */ }
63- }
64- try {
65- port = json [ "WCFPort" ] . ToString ( ) ;
66- } catch { /* Ignore */ }
58+ var hostname = "127.0.0.1" ;
59+ var port = "1242" ;
60+ //newversion:
61+ if ( null == json [ "WCFHost" ] && json [ "WCFPort" ] == null && json [ "WCFHostname" ] == null ) {
62+ if ( null != json [ "IPCHostname" ] )
63+ hostname = json [ "IPCHostname" ] . ToString ( ) ;
64+ if ( null != json [ "IPCPort" ] )
65+ port = json [ "IPCPort" ] . ToString ( ) ;
66+ return "http://" + hostname + ":" + port + "/IPC" ;
67+ }
68+ if ( null != json [ "WCFHost" ] )
69+ hostname = json [ "WCFHost" ] . ToString ( ) ;
70+ if ( null != json [ "WCFHostname" ] )
71+ hostname = json [ "WCFHostname" ] . ToString ( ) ;
72+ if ( null != json [ "WCFPort" ] )
73+ port = json [ "WCFPort" ] . ToString ( ) ;
6774
6875 return "net.tcp://" + hostname + ":" + port + "/ASF" ;
6976 }
0 commit comments