forked from powerfun/udpservice
一些功能调整
增加tcp协议支持; 增加模拟多用户的功能;
This commit is contained in:
1 parent
e8b6418aa6
commit
0e931a3ac9
21 files changed
+890
-174
No files matched your search
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using TurfCS;
|
||||
|
||||
namespace OnlineUserPool.Unility
|
||||
{
|
||||
public class CommonHelper
|
||||
{
|
||||
public static double GetDistances(double lon, double lat, double lon1, double lat1)
|
||||
{
|
||||
var pt1 = Turf.Point(new double[] { lon, lat });
|
||||
var pt2 = Turf.Point(new double[] { lon1, lat1 });
|
||||
|
||||
var value = Turf.Distance(pt1, pt2, "kilometers") * 1000;
|
||||
return Math.Round(value, 2);
|
||||
}
|
||||
|
||||
public static int GenerateRandomInteger(int min = 0, int max = int.MaxValue)
|
||||
{
|
||||
var randomNumberBuffer = new byte[10];
|
||||
new RNGCryptoServiceProvider().GetBytes(randomNumberBuffer);
|
||||
return new Random(BitConverter.ToInt32(randomNumberBuffer, 0)).Next(min, max);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-5
@@ -7,20 +7,26 @@ namespace OnlineUserPool.Unility
|
||||
class ConfigHelp
|
||||
{
|
||||
public static string Host { get; set; }
|
||||
public static int Top { get; private set; }
|
||||
public static int Top
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Top"]);
|
||||
}
|
||||
}
|
||||
public static bool ShowVirtualUser { get; set; }
|
||||
|
||||
public static string Ip { get; set; }
|
||||
//public static string Ip { get; private set; }
|
||||
|
||||
public static int Port { get; set; }
|
||||
public static int Port { get; private set; }
|
||||
|
||||
|
||||
static ConfigHelp()
|
||||
{
|
||||
Host = System.Configuration.ConfigurationManager.AppSettings["Host"];
|
||||
Top = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Top"]);
|
||||
//Top = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Top"]);
|
||||
ShowVirtualUser = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["ShowVirtualUser"]);
|
||||
Ip = System.Configuration.ConfigurationManager.AppSettings["Ip"];
|
||||
//Ip = System.Configuration.ConfigurationManager.AppSettings["Ip"];
|
||||
Port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using GeoJSON.Net.Geometry;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using TurfCS;
|
||||
using System.Linq;
|
||||
|
||||
namespace OnlineUserPool.Unility
|
||||
{
|
||||
public class TurfHelper
|
||||
{
|
||||
private LineString _line;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="points">坐标(lat,lon)</param>
|
||||
public TurfHelper(IEnumerable<double[]> points)
|
||||
{
|
||||
//var list = new GeoJSON.Net.Geometry.GeographicPosition();
|
||||
var list = points.Select(p => new GeoJSON.Net.Geometry.GeographicPosition(p[0], p[1]));
|
||||
|
||||
_line = new LineString(list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="distance">km</param>
|
||||
public GeographicPosition Along(double distance)
|
||||
{
|
||||
var pt1 = Turf.Along(_line, distance);
|
||||
return ((GeographicPosition)((GeoJSON.Net.Geometry.Point)pt1.Geometry).Coordinates);
|
||||
//new LineString()
|
||||
//new GeoJSON.Net.Geometry.Point(new GeoJSON.Net.Geometry.GeographicPosition())
|
||||
//pt1.BoundingBoxes
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using OnlineUserPool.Model;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OnlineUserPool.Unility
|
||||
{
|
||||
public class BaseApi
|
||||
{
|
||||
internal static System.Net.Http.HttpClient httpClient;
|
||||
static BaseApi()
|
||||
{
|
||||
httpClient = new System.Net.Http.HttpClient();
|
||||
httpClient.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("OnlineUserPool", "1.0.0"));
|
||||
}
|
||||
|
||||
protected static async Task<T> PostAsync<T>(string url, object data)
|
||||
{
|
||||
StringContent stringContent;
|
||||
if (data != null)
|
||||
{
|
||||
stringContent = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
|
||||
}
|
||||
else
|
||||
{
|
||||
stringContent = new StringContent("", Encoding.UTF8);
|
||||
}
|
||||
var response = await httpClient.PostAsync(ConfigHelp.Host + url, stringContent).ConfigureAwait(false);
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<T>(result);
|
||||
}
|
||||
|
||||
protected static async Task<T> GetAsync<T>(string url)
|
||||
{
|
||||
var response = await httpClient.GetAsync(ConfigHelp.Host + url, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false);
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<T>(result);
|
||||
}
|
||||
}
|
||||
public class WebService : BaseApi
|
||||
{
|
||||
/// <summary>
|
||||
/// 从服务端获取记录信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<MapRecordRanking> GetRecordFileFromServer(List<long> id)
|
||||
{
|
||||
if (!id.Any())
|
||||
{
|
||||
return new List<MapRecordRanking>();
|
||||
}
|
||||
return PostAsync<JsonResult<List<MapRecordRanking>>>("MapRecord/GetRandomList", id).ConfigureAwait(false).GetAwaiter().GetResult().data;
|
||||
}
|
||||
|
||||
public static List<MapRouteAndUserQueryVM> GetMapRouteRandomRecord(int top, IEnumerable<int> routeIds)
|
||||
{
|
||||
var routeIdsStr = "";
|
||||
if(routeIds != null)
|
||||
{
|
||||
routeIdsStr = string.Join(",", routeIds);
|
||||
}
|
||||
return GetAsync<JsonResult<List<MapRouteAndUserQueryVM>>>($"MapRecord/GetRandomRankingUserRecord?top={ top }&routeIds={ routeIdsStr }").ConfigureAwait(false).GetAwaiter().GetResult().data;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user