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,43 @@
|
||||
using Newtonsoft.Json;
|
||||
using OnlineUserPool.Unility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OnlineUserPool.Api
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using OnlineUserPool.Model;
|
||||
using OnlineUserPool.Unility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OnlineUserPool.Api.Model
|
||||
{
|
||||
public class MultiUserModel
|
||||
{
|
||||
public List<User> users { get; set; }
|
||||
|
||||
public MapDataModel route { get; set; }
|
||||
|
||||
|
||||
public class User
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string NickName { get; set; }
|
||||
|
||||
public string WxHeadImg { get; set; }
|
||||
|
||||
public double Weight { get; set; }
|
||||
|
||||
public User()
|
||||
{
|
||||
Speed = CommonHelper.GenerateRandomInteger(0, 30);
|
||||
|
||||
//Distance = CommonHelper.GenerateRandomInteger(0, 30)/1000D;
|
||||
}
|
||||
|
||||
|
||||
public double Speed {
|
||||
get;set;
|
||||
}
|
||||
|
||||
public double Distance { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
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.Api
|
||||
{
|
||||
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