OMNI+: AlarmsStates updated
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>CommonConsole</RootNamespace>
|
||||
<AssemblyName>CommonConsole</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
|
||||
@@ -1,110 +1,18 @@
|
||||
namespace CommonConsole
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using OmniPlus;
|
||||
|
||||
public class Program
|
||||
public static class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var uri = new URIHelper("/CSR?key=asdasdasd")
|
||||
.AddQuery(new { A = 123, B = "asd" });
|
||||
var connection = new OmniIrdaConnection("COM36");
|
||||
|
||||
Console.WriteLine(uri);
|
||||
}
|
||||
}
|
||||
connection.Open();
|
||||
|
||||
public class URIHelper
|
||||
{
|
||||
private readonly string path;
|
||||
private readonly IDictionary<string, string> query;
|
||||
var alarmState = connection.ViewAlarmsState();
|
||||
|
||||
public URIHelper(string value)
|
||||
{
|
||||
this.query = new Dictionary<string, string>();
|
||||
this.path = this.ParsePathAndQuery(value);
|
||||
}
|
||||
|
||||
public URIHelper AddQuery(object query)
|
||||
{
|
||||
if (query != null)
|
||||
{
|
||||
if (query is string queryString)
|
||||
{
|
||||
var queryTokens = queryString.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var token in queryTokens)
|
||||
{
|
||||
var kvpTokens = token.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (kvpTokens.Length == 2)
|
||||
{
|
||||
this.query[kvpTokens[0]] = kvpTokens[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (query is IDictionary<string, string> parameters)
|
||||
{
|
||||
foreach (var kvp in parameters)
|
||||
{
|
||||
this.query[kvp.Key] = kvp.Value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var properties = query
|
||||
.GetType()
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
var key = property.Name.ToLower();
|
||||
var value = property.GetValue(query);
|
||||
|
||||
this.query[key] = HttpUtility.UrlEncode($"{value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
=> $"{this.path}?{string.Join("&", this.query.Select(x => $"{x.Key}={x.Value}"))}";
|
||||
|
||||
private string ParsePathAndQuery(String value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
var routeTokens = value.Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (routeTokens.Length >= 2)
|
||||
{
|
||||
var queryTokens = routeTokens[1].Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var token in queryTokens)
|
||||
{
|
||||
var kvpTokens = token.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (kvpTokens.Length == 2)
|
||||
{
|
||||
this.query[kvpTokens[0]] = kvpTokens[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (routeTokens.Length >= 1)
|
||||
{
|
||||
return routeTokens[0];
|
||||
}
|
||||
|
||||
return "/";
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,4 @@
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup></configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup></configuration>
|
||||
|
||||
Reference in New Issue
Block a user