forked from powerfun/udpservice
上传UPD项目文件
This commit is contained in:
commit
fd3e84b18d
67 files changed
+3611
No files matched your search
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OnlineUserPool.Unility
|
||||
{
|
||||
class ConfigHelp
|
||||
{
|
||||
public static string Host { get; set; }
|
||||
public static string Top { get; set; }
|
||||
public static bool ShowVirtualUser { get; set; }
|
||||
|
||||
public static string Ip { get; set; }
|
||||
|
||||
public static int Port { get; set; }
|
||||
|
||||
|
||||
static ConfigHelp()
|
||||
{
|
||||
Host = System.Configuration.ConfigurationManager.AppSettings["Host"];
|
||||
Top = System.Configuration.ConfigurationManager.AppSettings["Top"];
|
||||
ShowVirtualUser = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["ShowVirtualUser"]);
|
||||
Ip = System.Configuration.ConfigurationManager.AppSettings["Ip"];
|
||||
Port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Serilog;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OnlineUserPool.Unility
|
||||
{
|
||||
public class LogHelper
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
string path = AppDomain.CurrentDomain.BaseDirectory+ "\\logs\\log.txt";
|
||||
Console.WriteLine(path);
|
||||
Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Console().WriteTo.File(path, rollingInterval: RollingInterval.Day).CreateLogger();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using OnlineUserPool.Model;
|
||||
|
||||
using System.Collections.Generic;
|
||||
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();
|
||||
}
|
||||
|
||||
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<string> id)
|
||||
{
|
||||
return PostAsync<JsonResult<List<MapRecordRanking>>>("Map/GetCyclingRecordsById", id).ConfigureAwait(false).GetAwaiter().GetResult().data;
|
||||
}
|
||||
|
||||
public static List<MapRouteAndUserQueryVM> GetMapRouteRandomUser(RandomRankingUserRequestVM requestVM)
|
||||
{
|
||||
return PostAsync<JsonResult<List<MapRouteAndUserQueryVM>>>($"Map/GetRandomRankingUserRecord", requestVM).ConfigureAwait(false).GetAwaiter().GetResult().data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user