AzureDevOpsRepository Markdown links Ticks bug fix, default to *.wc files and formatting
82 lines
3.1 KiB
C#
82 lines
3.1 KiB
C#
using OI.Metrology.Shared.Models;
|
|
using System.Collections.Specialized;
|
|
using System.Net;
|
|
using System.Text.Json;
|
|
using System.Web;
|
|
|
|
namespace OI.Metrology.Wafer.Counter.Helper;
|
|
|
|
public class ParameterHelper
|
|
{
|
|
|
|
private static Dictionary<string, string?> GetKeyValuePairs(QueryString queryString)
|
|
{
|
|
Dictionary<string, string?> results = [];
|
|
if (queryString.HasValue)
|
|
{
|
|
NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(queryString.Value);
|
|
foreach (string? key in nameValueCollection.AllKeys)
|
|
{
|
|
if (key is null)
|
|
continue;
|
|
results.Add(key, nameValueCollection[key]);
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
internal static CharacterizationParameters? GetCharacterizationParameters(QueryString queryString)
|
|
{
|
|
CharacterizationParameters? result;
|
|
Dictionary<string, string?> keyValuePairs = GetKeyValuePairs(queryString);
|
|
string json = JsonSerializer.Serialize(keyValuePairs, new JsonSerializerOptions() { WriteIndented = true });
|
|
result = string.IsNullOrEmpty(json) ? null : JsonSerializer.Deserialize(json, CharacterizationParametersSourceGenerationContext.Default.CharacterizationParameters);
|
|
return result;
|
|
}
|
|
|
|
private static string? GetQueryString(Stream stream)
|
|
{
|
|
string? result;
|
|
if (!stream.CanRead)
|
|
result = null;
|
|
else
|
|
{
|
|
Task<string> task = new StreamReader(stream).ReadToEndAsync();
|
|
result = task.Result;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private static Dictionary<string, string?> GetKeyValuePairs(string? queryString)
|
|
{
|
|
Dictionary<string, string?> results = [];
|
|
if (!string.IsNullOrEmpty(queryString))
|
|
{
|
|
NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(queryString);
|
|
foreach (string? key in nameValueCollection.AllKeys)
|
|
{
|
|
if (key is null)
|
|
continue;
|
|
results.Add(key, nameValueCollection[key]);
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
internal static PollValue? GetPollValue(IPAddress? remoteIpAddress, Stream stream)
|
|
{
|
|
PollValue? result;
|
|
string? queryString = GetQueryString(stream);
|
|
Dictionary<string, string?> keyValuePairs = GetKeyValuePairs(queryString);
|
|
string json = JsonSerializer.Serialize(keyValuePairs, new JsonSerializerOptions() { WriteIndented = true });
|
|
result = string.IsNullOrEmpty(json) ? null : JsonSerializer.Deserialize(json, PollValueSourceGenerationContext.Default.PollValue);
|
|
if (result is not null)
|
|
{
|
|
result = new(null, result.Id, result.Page, queryString, remoteIpAddress is null ? string.Empty : remoteIpAddress.ToString(), result.Time, result.Value);
|
|
json = JsonSerializer.Serialize(result, PollValueSourceGenerationContext.Default.PollValue);
|
|
result = new(json, result.Id, result.Page, queryString, remoteIpAddress is null ? string.Empty : remoteIpAddress.ToString(), result.Time, result.Value);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
} |