|
@@ -5,7 +5,9 @@ using System.IO.Compression;
|
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
|
using System.Net.Http;
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
using InABox.Core;
|
|
|
using InABox.Remote.Shared;
|
|
|
using RestSharp;
|
|
@@ -36,20 +38,42 @@ namespace InABox.Clients
|
|
|
|
|
|
private BinarySerializationSettings BinarySerializationSettings;
|
|
|
|
|
|
- public JsonClient(string url, int port, bool useSimpleEncryption, bool compression, BinarySerializationSettings binarySerializationSettings) : base(url, port, useSimpleEncryption)
|
|
|
+ public JsonClient(string url, bool useSimpleEncryption, bool compression, BinarySerializationSettings binarySerializationSettings) : base(url, useSimpleEncryption)
|
|
|
{
|
|
|
_compression = compression;
|
|
|
BinarySerializationSettings = binarySerializationSettings;
|
|
|
}
|
|
|
|
|
|
- public JsonClient(string url, int port, bool useSimpleEncryption) : this(url, port, useSimpleEncryption, true, BinarySerializationSettings.Latest)
|
|
|
+ public JsonClient(string url, bool useSimpleEncryption) : this(url, useSimpleEncryption, true, BinarySerializationSettings.Latest)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- public JsonClient(string url, int port) : this(url, port, false, true, BinarySerializationSettings.Latest)
|
|
|
+ public JsonClient(string url) : this(url, false, true, BinarySerializationSettings.Latest)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+ public static string Ping(String[] urls, out DatabaseInfo info)
|
|
|
+ {
|
|
|
+ String result = "";
|
|
|
+ info = new DatabaseInfo();
|
|
|
+ List<Task<Tuple<String,DatabaseInfo>>> pings = urls.Select(x => Task.Run(
|
|
|
+ () => new Tuple<String,DatabaseInfo>(x,new JsonClient<User>(x).Info())
|
|
|
+ )).ToList();
|
|
|
+ while (pings.Count > 0)
|
|
|
+ {
|
|
|
+ var ping = Task.WhenAny(pings).Result;
|
|
|
+ if (ping.Status == TaskStatus.RanToCompletion && !String.IsNullOrWhiteSpace(ping.Result.Item2.Version))
|
|
|
+ {
|
|
|
+ result = ping.Result.Item1;
|
|
|
+ info = ping.Result.Item2;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ pings.Remove(ping);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//private static void CheckSecuritySettings()
|
|
|
//{
|
|
@@ -88,7 +112,7 @@ namespace InABox.Clients
|
|
|
//Log(" * {0}{1}() Serializing data took {2}ms ({3} bytes)", Action, typeof(TEntity).Name, sw.ElapsedMilliseconds, json.Length);
|
|
|
//sw.Restart();
|
|
|
|
|
|
- var uri = new Uri(string.Format("{0}:{1}", URL, Port));
|
|
|
+ var uri = new Uri(URL);
|
|
|
var cli = new RestClient(uri);
|
|
|
var cmd = string.Format(
|
|
|
"{0}{1}?format={2}&responseFormat={3}&serializationVersion={4}",
|
|
@@ -251,7 +275,7 @@ namespace InABox.Clients
|
|
|
public override IEnumerable<string> SupportedTypes()
|
|
|
{
|
|
|
var result = new List<string>();
|
|
|
- var uri = new Uri(string.Format("{0}:{1}", URL, Port));
|
|
|
+ var uri = new Uri(URL);
|
|
|
var cli = new RestClient(uri);
|
|
|
var req = new RestRequest("/classes", Method.GET) { Timeout = 20000 };
|
|
|
|
|
@@ -285,7 +309,7 @@ namespace InABox.Clients
|
|
|
|
|
|
public override DatabaseInfo Info()
|
|
|
{
|
|
|
- var uri = new Uri(string.Format("{0}:{1}", URL, Port));
|
|
|
+ var uri = new Uri(URL);
|
|
|
var cli = new RestClient(uri);
|
|
|
var req = new RestRequest("/info", Method.GET) { Timeout = 20000 };
|
|
|
|