Add Transmission Control Protocol file handling and update PCL serialization
- Introduced FileRead and Record classes for handling file reading in the Transmission Control Protocol. - Enhanced Description, Detail, and other related classes with JSON serialization attributes for improved data handling. - Implemented methods for reading and processing files, including network stream management. - Updated unit tests to cover new functionality and ensure robust testing. - Added new PDSF file handling classes and integrated them into the project structure. - Refactored existing code to utilize source generation for JSON serialization, improving performance and maintainability.
This commit is contained in:
143
Adaptation/FileHandlers/pdsf/Point.cs
Normal file
143
Adaptation/FileHandlers/pdsf/Point.cs
Normal file
@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Adaptation.FileHandlers.pdsf;
|
||||
|
||||
#nullable enable
|
||||
|
||||
internal class Point
|
||||
{
|
||||
|
||||
public Point(string site, string x, string y, string nAvg, string rhoAvg, string nsl, string rhosl, string vd, string phase, string flatZ, string grade, string xLeft, string xRight, string bottomY, string topY)
|
||||
{
|
||||
Site = site;
|
||||
X = x;
|
||||
Y = y;
|
||||
NAvg = nAvg;
|
||||
RhoAvg = rhoAvg;
|
||||
Nsl = nsl;
|
||||
Rhosl = rhosl;
|
||||
Vd = vd;
|
||||
Phase = phase;
|
||||
FlatZ = flatZ;
|
||||
Grade = grade;
|
||||
XLeft = xLeft;
|
||||
XRight = xRight;
|
||||
BottomY = bottomY;
|
||||
TopY = topY;
|
||||
}
|
||||
|
||||
[JsonPropertyName("Site")] public string Site { get; }
|
||||
[JsonPropertyName("X")] public string X { get; }
|
||||
[JsonPropertyName("Y")] public string Y { get; }
|
||||
[JsonPropertyName("Navg")] public string NAvg { get; }
|
||||
[JsonPropertyName("Rhoavg")] public string RhoAvg { get; }
|
||||
[JsonPropertyName("Nsl")] public string Nsl { get; }
|
||||
[JsonPropertyName("Rhosl")] public string Rhosl { get; }
|
||||
[JsonPropertyName("Vd")] public string Vd { get; }
|
||||
[JsonPropertyName("Phase")] public string Phase { get; }
|
||||
[JsonPropertyName("Flat Z")] public string FlatZ { get; }
|
||||
[JsonPropertyName("Grade")] public string Grade { get; }
|
||||
[JsonPropertyName("X Left")] public string XLeft { get; }
|
||||
[JsonPropertyName("X Right")] public string XRight { get; }
|
||||
[JsonPropertyName("Bottom Y")] public string BottomY { get; }
|
||||
[JsonPropertyName("Top Y")] public string TopY { get; }
|
||||
|
||||
public static Point Get() =>
|
||||
new(string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
string.Empty);
|
||||
|
||||
public static ReadOnlyCollection<Point> GetCollection(Constant constant, ReadOnlyCollection<string> lines)
|
||||
{
|
||||
List<Point> results = new();
|
||||
string s;
|
||||
string line;
|
||||
Point point;
|
||||
string[] segments;
|
||||
string[] segmentsB;
|
||||
bool found = false;
|
||||
string[] segmentsC;
|
||||
bool foundB = false;
|
||||
int x = constant.Take - 2;
|
||||
List<string> sites = new();
|
||||
for (int i = 0; i < lines.Count; i++)
|
||||
{
|
||||
line = lines[i];
|
||||
segmentsC = line.Split(new string[] { constant.Site }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (segmentsC.Length > 1)
|
||||
{
|
||||
foreach (string segment in segmentsC)
|
||||
sites.Add(segment.Trim());
|
||||
}
|
||||
if (line == constant.SummaryLine)
|
||||
{
|
||||
sites.RemoveAt(0);
|
||||
found = true;
|
||||
}
|
||||
if (!found)
|
||||
continue;
|
||||
if (!foundB && line.Contains(constant.Multiple))
|
||||
foundB = true;
|
||||
if (line != constant.LastUnitsB)
|
||||
continue;
|
||||
if (foundB)
|
||||
{
|
||||
foundB = false;
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < sites.Count; j++)
|
||||
{
|
||||
s = sites[j];
|
||||
if (i + constant.Take > lines.Count)
|
||||
break;
|
||||
segments = s.Split(new string[] { "(", ",", ")" }, StringSplitOptions.None);
|
||||
if (segments.Length < 2)
|
||||
break;
|
||||
segmentsB = lines[i + x].Split(' ');
|
||||
if (segmentsB.Length < 2)
|
||||
break;
|
||||
point = new(site: segments[0].Trim(),
|
||||
x: segments[1].Trim(),
|
||||
y: segments[2].Trim(),
|
||||
nAvg: lines[i + 1].Trim(),
|
||||
nsl: lines[i + 2].Trim(),
|
||||
vd: lines[i + 3].Trim(),
|
||||
flatZ: lines[i + 4].Trim(),
|
||||
rhoAvg: lines[i + 5].Trim(),
|
||||
rhosl: lines[i + 6].Trim(),
|
||||
phase: lines[i + 7].Trim(),
|
||||
grade: lines[i + 8].Trim(),
|
||||
xLeft: segmentsB[0],
|
||||
xRight: segmentsB[1],
|
||||
bottomY: lines[i + 10].Trim(),
|
||||
topY: lines[i + 11].Trim());
|
||||
results.Add(point);
|
||||
i += constant.Take;
|
||||
}
|
||||
sites.Clear();
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Point))]
|
||||
internal partial class PointSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user