Browse Source

提交客户端模拟http请求

pull/1/head
fajiao 3 years ago
parent
commit
2144c82e72
  1. 12
      BaseModule/EC.Helper/EC.Helper.csproj
  2. 16
      BaseModule/EC.Helper/FileExt/JsonHelper.cs
  3. 17
      OnvifServer-CSharp.sln
  4. 52
      OnvifSocketServer/Manager/AppConfig.cs
  5. 14
      OnvifSocketServer/OnvifSocketServer.csproj
  6. 21
      OnvifSocketServer/Program.cs
  7. 6
      OnvifSocketServer/appsettings.json
  8. 4
      OnvifWebServer/OnvifWebServer.csproj

12
BaseModule/EC.Helper/EC.Helper.csproj

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
</ItemGroup>
</Project>

16
BaseModule/EC.Helper/FileExt/JsonHelper.cs

@ -0,0 +1,16 @@
using Microsoft.Extensions.Configuration;
using System.IO;
namespace EC.Helper.FileExt
{
public class JsonHelper
{
public static IConfiguration ReadConfiguration(string configPath)
{
ConfigurationBuilder builder = new();
if (!File.Exists(configPath)) { return builder.Build(); }
builder.AddJsonFile(configPath);
return builder.Build();
}
}
}

17
OnvifServer-CSharp.sln

@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OnvifWebServer", "OnvifWebServer\OnvifWebServer.csproj", "{6932E7F3-56E3-4AA5-898C-1C814D53C5F6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OnvifWebServer", "OnvifWebServer\OnvifWebServer.csproj", "{6932E7F3-56E3-4AA5-898C-1C814D53C5F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OnvifSocketServer", "OnvifSocketServer\OnvifSocketServer.csproj", "{2CC43390-1870-475A-B2F1-5F66C17E27B5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OnvifSocketServer", "OnvifSocketServer\OnvifSocketServer.csproj", "{2CC43390-1870-475A-B2F1-5F66C17E27B5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BaseModule", "BaseModule", "{8D6DAF0C-45FB-4650-8F4F-A63283D32F75}"
EndProject
@ -13,14 +13,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BusinessModule", "BusinessM
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.Onvif", "BaseModule\EC.Onvif\EC.Onvif.csproj", "{94728605-7159-40DD-861C-4D1B9E8DEA00}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EC.App.Entity", "BusinessModule\EC.App.Entity\EC.App.Entity.csproj", "{2B89CB02-BA09-4140-A3BF-5A02109C080C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.App.Entity", "BusinessModule\EC.App.Entity\EC.App.Entity.csproj", "{2B89CB02-BA09-4140-A3BF-5A02109C080C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EC.App", "BaseModule\EC.App\EC.App.csproj", "{7AE950D5-1982-4D76-94F5-A38347AE8263}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.App", "BaseModule\EC.App\EC.App.csproj", "{7AE950D5-1982-4D76-94F5-A38347AE8263}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EC.App.ThatBLL", "BusinessModule\EC.App.ThatBLL\EC.App.ThatBLL.csproj", "{D1528FA0-E88B-483A-932C-A682BDD4FF98}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.App.ThatBLL", "BusinessModule\EC.App.ThatBLL\EC.App.ThatBLL.csproj", "{D1528FA0-E88B-483A-932C-A682BDD4FF98}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC.App.ThatService", "BusinessModule\EC.App.ThatService\EC.App.ThatService.csproj", "{EE03CCDB-A280-477B-86FF-B6918169FCDA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EC.Helper", "BaseModule\EC.Helper\EC.Helper.csproj", "{C0AADD2D-7E01-41B3-BE81-433E49D4CA4B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -55,6 +57,10 @@ Global
{EE03CCDB-A280-477B-86FF-B6918169FCDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE03CCDB-A280-477B-86FF-B6918169FCDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE03CCDB-A280-477B-86FF-B6918169FCDA}.Release|Any CPU.Build.0 = Release|Any CPU
{C0AADD2D-7E01-41B3-BE81-433E49D4CA4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0AADD2D-7E01-41B3-BE81-433E49D4CA4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0AADD2D-7E01-41B3-BE81-433E49D4CA4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0AADD2D-7E01-41B3-BE81-433E49D4CA4B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -65,6 +71,7 @@ Global
{7AE950D5-1982-4D76-94F5-A38347AE8263} = {8D6DAF0C-45FB-4650-8F4F-A63283D32F75}
{D1528FA0-E88B-483A-932C-A682BDD4FF98} = {BE926C07-70B6-48E6-9A09-8089AC72DB52}
{EE03CCDB-A280-477B-86FF-B6918169FCDA} = {BE926C07-70B6-48E6-9A09-8089AC72DB52}
{C0AADD2D-7E01-41B3-BE81-433E49D4CA4B} = {8D6DAF0C-45FB-4650-8F4F-A63283D32F75}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94E890EB-BBFB-4C67-9A75-EF7217F2E82B}

52
OnvifSocketServer/Manager/AppConfig.cs

@ -0,0 +1,52 @@
using EC.Helper.FileExt;
using Microsoft.Extensions.Configuration;
using System.IO;
namespace OnvifSocketServer
{
public class AppConfig
{
#region Attr
private static IConfiguration config;
private static IConfiguration Config
{
get
{
if (config == null)
{
string configPath = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json");
config = JsonHelper.ReadConfiguration(configPath);
}
return config;
}
}
public static T Get<T>(string key)
{
return Config.GetValue<T>(key);
}
#endregion Attr
#region Apis
public static string GetApi(string key)
{
return Get<string>($"Apis:{key}");
}
public static string GetOnvifHttpUrl()
{
return GetApi("onvif_http_url");
}
public static string GetOnvifHttpsUrl()
{
return GetApi("onvif_https_url");
}
#endregion Apis
}
}

14
OnvifSocketServer/OnvifSocketServer.csproj

@ -5,4 +5,18 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Flurl.Http" Version="3.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BaseModule\EC.Helper\EC.Helper.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

21
OnvifSocketServer/Program.cs

@ -1,12 +1,25 @@
using System;
using Flurl;
using Flurl.Http;
using Newtonsoft.Json.Linq;
using System;
namespace OnvifSocketServer
{
internal class Program
public class Program
{
static void Main(string[] args)
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string onvifHttpUrl = AppConfig.GetOnvifHttpUrl();
string onvifHttpsUrl = AppConfig.GetOnvifHttpsUrl();
Console.WriteLine(onvifHttpUrl, onvifHttpsUrl);
var baseUri = new Uri(onvifHttpUrl);
var absoluteUri = new Uri(baseUri, "onvif/Curd/IsExist");
JObject result = absoluteUri.AbsoluteUri
.SetQueryParams(new { ip = "192.168.1.105" })
.GetJsonAsync<JObject>().Result;
Console.WriteLine(result);
}
}
}
}

6
OnvifSocketServer/appsettings.json

@ -0,0 +1,6 @@
{
"Apis": {
"onvif_http_url": "http://localhost:5000",
"onvif_https_url": "https://localhost:5001"
}
}

4
OnvifWebServer/OnvifWebServer.csproj

@ -7,10 +7,6 @@
<AnalysisLevel>6.0</AnalysisLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Furion" Version="2.20.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BaseModule\EC.App\EC.App.csproj" />
<ProjectReference Include="..\BusinessModule\EC.App.ThatBLL\EC.App.ThatBLL.csproj" />

Loading…
Cancel
Save