Alignment
This commit is contained in:
parent
d05e56847b
commit
f1b0f15342
@ -100,6 +100,7 @@ dotnet_diagnostic.CA1846.severity = none # CA1846: Prefer AsSpan over Substring
|
||||
dotnet_diagnostic.CA1847.severity = none # CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters
|
||||
dotnet_diagnostic.CA1854.severity = warning # CA1854: Prefer a 'TryGetValue' call over a Dictionary indexer access guarded by a 'ContainsKey' check to avoid double lookup
|
||||
dotnet_diagnostic.CA1860.severity = error # CA1860: Prefer comparing 'Count' to 0 rather than using 'Any()', both for clarity and for performance
|
||||
dotnet_diagnostic.CA1861.severity = none # CA1861: Prefer 'static readonly' fields over constant array arguments
|
||||
dotnet_diagnostic.CA1862.severity = none # CA1862: Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase'
|
||||
dotnet_diagnostic.CA1864.severity = none # CA1864: To avoid double lookup, call 'TryAdd' instead of calling 'Add' with a 'ContainsKey' guard
|
||||
dotnet_diagnostic.CA1866.severity = none # CA1866: Use 'string.EndsWith(char)' instead of 'string.EndsWith(string)' when you have a string with a single char
|
||||
|
@ -55,24 +55,20 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
|
||||
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="8.0.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
|
||||
<PackageReference Include="Pdfbox" Version="1.1.1"><NoWarn>NU1701</NoWarn></PackageReference>
|
||||
<PackageReference Include="RoboSharp" Version="1.5.1" />
|
||||
<PackageReference Include="RoboSharp" Version="1.5.3" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
|
||||
<PackageReference Include="System.Data.OleDb" Version="8.0.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.5" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.6" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.3" />
|
||||
<PackageReference Include="Tesseract" Version="5.2.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.SelfHost" Version="5.2.9" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.205.1" />
|
||||
<PackageReference Include="Tibco.Rendezvous.DotNetCore" Version="8.5.0" />
|
||||
<PackageReference Include="Infineon.Yoda.DotNetCore" Version="5.4.1" />
|
||||
</ItemGroup>
|
||||
|
@ -2,18 +2,27 @@
|
||||
|
||||
public partial class WS
|
||||
{
|
||||
|
||||
public class Attachment
|
||||
{
|
||||
|
||||
public string SubGroupId { get; set; }
|
||||
public long HeaderId { get; set; }
|
||||
public string HeaderIdDirectory { get; set; }
|
||||
public string UniqueId { get; set; }
|
||||
public string DestinationFileName { get; set; }
|
||||
public string SourceFileName { get; set; }
|
||||
public string AttachmentId { get; set; }
|
||||
|
||||
public Attachment(string uniqueId, string destinationFileName, string sourceFileName)
|
||||
public Attachment(string subGroupId, long headerId, string headerIdDirectory, string uniqueId, string destinationFileName, string sourceFileName)
|
||||
{
|
||||
SubGroupId = subGroupId;
|
||||
HeaderId = headerId;
|
||||
HeaderIdDirectory = headerIdDirectory;
|
||||
UniqueId = uniqueId;
|
||||
DestinationFileName = destinationFileName;
|
||||
SourceFileName = sourceFileName;
|
||||
AttachmentId = System.Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace Adaptation.Shared.Metrology;
|
||||
public partial class WS
|
||||
{
|
||||
|
||||
public static (string, Results) SendData(string url, object payload, int timeoutSeconds = 120)
|
||||
public static (string, Results) SendData(string url, long sequence, string directory, object payload, int timeoutSeconds = 120)
|
||||
{
|
||||
Results results = new();
|
||||
string resultsJson = string.Empty;
|
||||
@ -31,6 +31,10 @@ public partial class WS
|
||||
HttpResponseMessage httpResponseMessage = httpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseContentRead).Result;
|
||||
resultsJson = httpResponseMessage.Content.ReadAsStringAsync().Result;
|
||||
results = JsonSerializer.Deserialize<Results>(resultsJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
string checkDirectory = Path.Combine(directory, $"-{results.HeaderID}");
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
File.WriteAllText(Path.Combine(checkDirectory, $"{sequence}.json"), json);
|
||||
}
|
||||
if (!results.Success)
|
||||
results.Errors.Add(results.ToString());
|
||||
@ -51,58 +55,54 @@ public partial class WS
|
||||
return new(resultsJson, results);
|
||||
}
|
||||
|
||||
// this method is a wrapper for attaching a file to either a header or data record
|
||||
// URL is the same URL used for SendData, ex: http://localhost/api/inbound/CDE
|
||||
// attachToHeaderId is the ID returned by SendData
|
||||
// attachToDataUniqueId is the string unique ID for the data record, aka the Title of the Sharepoint list entry
|
||||
// fileContents is a byte array with the contents of the file
|
||||
// fileName is which attachment this is, image.pdf, data.pdf, data.txt, header.pdf, etc
|
||||
// timeoutSeconds is configured as the request timeout
|
||||
// this method will either succeed or throw an exception
|
||||
// also, this has been made synchronous
|
||||
public static void AttachFile(string url, long attachToHeaderId, string attachToDataUniqueId, byte[] fileContents, string fileName, int timeoutSeconds = 60)
|
||||
public static void AttachFile(string url, Attachment attachment, int timeoutSeconds = 60)
|
||||
{
|
||||
using HttpClient httpClient = new();
|
||||
string requestUrl = url + "/attachment?headerid=" + attachToHeaderId.ToString();
|
||||
if (!string.IsNullOrWhiteSpace(attachToDataUniqueId))
|
||||
{
|
||||
requestUrl += "&datauniqueid=";
|
||||
requestUrl += System.Net.WebUtility.UrlEncode(attachToDataUniqueId);
|
||||
}
|
||||
requestUrl += "&filename="; // this is just so the web server log shows the filename
|
||||
requestUrl += System.Net.WebUtility.UrlEncode(fileName);
|
||||
|
||||
string json = JsonSerializer.Serialize(attachment);
|
||||
httpClient.Timeout = new TimeSpan(0, 0, 0, timeoutSeconds, 0);
|
||||
|
||||
MultipartFormDataContent multipartFormDataContent = new();
|
||||
ByteArrayContent byteArrayContent = new(fileContents);
|
||||
byteArrayContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
|
||||
|
||||
multipartFormDataContent.Add(byteArrayContent, "attachment", fileName);
|
||||
|
||||
HttpResponseMessage httpResponseMessage = httpClient.PostAsync(requestUrl, multipartFormDataContent).Result;
|
||||
|
||||
if (httpResponseMessage.IsSuccessStatusCode)
|
||||
return;
|
||||
|
||||
string resultBody = httpResponseMessage.Content.ReadAsStringAsync().Result;
|
||||
|
||||
throw new Exception("Attachment failed: " + resultBody);
|
||||
StringContent httpContent = new(json, Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage httpResponseMessage = httpClient.PostAsync($"{url}/attachment", httpContent).Result;
|
||||
if (!httpResponseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
string resultBody = httpResponseMessage.Content.ReadAsStringAsync().Result;
|
||||
throw new Exception($"Attachment failed: {resultBody}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void AttachFiles(string url, long headerID, List<Attachment> headerAttachments = null, List<Attachment> dataAttachments = null)
|
||||
public static void AttachFiles(string url, List<Attachment> headerAttachments = null, List<Attachment> dataAttachments = null)
|
||||
{
|
||||
string directory;
|
||||
try
|
||||
{
|
||||
if (headerAttachments is not null)
|
||||
{
|
||||
foreach (Attachment attachment in headerAttachments)
|
||||
AttachFile(url, headerID, "", File.ReadAllBytes(attachment.SourceFileName), attachment.DestinationFileName);
|
||||
{
|
||||
directory = Path.Combine(Path.GetDirectoryName(attachment.HeaderIdDirectory), attachment.AttachmentId) ?? throw new Exception();
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
File.Copy(attachment.SourceFileName, Path.Combine(directory, attachment.DestinationFileName), overwrite: true);
|
||||
}
|
||||
}
|
||||
if (dataAttachments is not null)
|
||||
{
|
||||
foreach (Attachment attachment in dataAttachments)
|
||||
AttachFile(url, headerID, attachment.UniqueId, File.ReadAllBytes(attachment.SourceFileName), attachment.DestinationFileName);
|
||||
{
|
||||
directory = Path.Combine(Path.GetDirectoryName(attachment.HeaderIdDirectory.Replace("Header", "Data")), attachment.AttachmentId) ?? throw new Exception();
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
File.Copy(attachment.SourceFileName, Path.Combine(directory, attachment.DestinationFileName), overwrite: true);
|
||||
}
|
||||
}
|
||||
if (headerAttachments is not null)
|
||||
{
|
||||
foreach (Attachment attachment in headerAttachments)
|
||||
AttachFile(url, attachment);
|
||||
}
|
||||
if (dataAttachments is not null)
|
||||
{
|
||||
foreach (Attachment attachment in dataAttachments)
|
||||
AttachFile(url, attachment);
|
||||
}
|
||||
//MessageBox.Show(r.ToString());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user