forked from fajiao/OnvifServer-CSharp
fajiao
3 years ago
8 changed files with 129 additions and 13 deletions
@ -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> |
@ -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(); |
|||
} |
|||
} |
|||
} |
@ -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
|
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,6 @@ |
|||
{ |
|||
"Apis": { |
|||
"onvif_http_url": "http://localhost:5000", |
|||
"onvif_https_url": "https://localhost:5001" |
|||
} |
|||
} |
Loading…
Reference in new issue