Builds but needs tested
This commit is contained in:
83
APC Viewer/Controllers/BackgroundController.cs
Normal file
83
APC Viewer/Controllers/BackgroundController.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using APCViewer.Models.Stateless.Methods;
|
||||
using IFX.Shared;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Serilog.Context;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace APCViewer.Controllers;
|
||||
|
||||
public class BackgroundController : Controller, Models.Properties.IBackgroundController, IBackgroundController
|
||||
{
|
||||
|
||||
protected readonly List<Exception> _Exceptions;
|
||||
protected readonly string _AppSettingsURLs;
|
||||
protected readonly string _IsEnvironmentProfile;
|
||||
protected readonly string _IsPrimaryInstance;
|
||||
protected readonly string _Message;
|
||||
protected readonly string _WorkingDirectory;
|
||||
public List<Exception> Exceptions => _Exceptions;
|
||||
public string AppSettingsURLs => _AppSettingsURLs;
|
||||
public string IsEnvironmentProfile => _IsEnvironmentProfile;
|
||||
public string IsPrimaryInstance => _IsPrimaryInstance;
|
||||
public string Message => _Message;
|
||||
public string WorkingDirectory => _WorkingDirectory;
|
||||
|
||||
private readonly Serilog.ILogger _Log;
|
||||
private readonly Models.Methods.IBackground _BackgroundMethods;
|
||||
|
||||
public BackgroundController(IsEnvironment isEnvironment, Models.AppSettings appSettings, Singleton.Background background)
|
||||
{
|
||||
_Message = background.Message;
|
||||
_BackgroundMethods = background;
|
||||
_AppSettingsURLs = appSettings.URLs;
|
||||
_Exceptions = background.Exceptions;
|
||||
_IsEnvironmentProfile = isEnvironment.Profile;
|
||||
_WorkingDirectory = background.WorkingDirectory;
|
||||
_Log = Serilog.Log.ForContext<BackgroundController>();
|
||||
Models.Methods.IBackground backgroundMethods = background;
|
||||
_IsPrimaryInstance = backgroundMethods.IsPrimaryInstance().ToString();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
public ActionResult Index(bool? message_clear = null, bool? exceptions_clear = null, bool? set_is_primary_instance = null)
|
||||
{
|
||||
string? methodName = IMethodName.GetActualAsyncMethodName();
|
||||
using (LogContext.PushProperty("MethodName", methodName))
|
||||
{
|
||||
_Log.Debug("() => ...");
|
||||
if (message_clear.HasValue && message_clear.Value)
|
||||
_BackgroundMethods.ClearMessage();
|
||||
if (exceptions_clear.HasValue && exceptions_clear.Value)
|
||||
_Exceptions.Clear();
|
||||
if (set_is_primary_instance.HasValue)
|
||||
{
|
||||
if (set_is_primary_instance.Value)
|
||||
_BackgroundMethods.SetIsPrimaryInstance();
|
||||
else
|
||||
_BackgroundMethods.ClearIsPrimaryInstance();
|
||||
}
|
||||
string message;
|
||||
if (string.IsNullOrWhiteSpace(_Message))
|
||||
message = "N/A";
|
||||
else
|
||||
message = _Message;
|
||||
List<Exception> exceptions = new();
|
||||
foreach (Exception exception in _Exceptions)
|
||||
exceptions.Add(exception);
|
||||
ViewBag.Message = message;
|
||||
ViewBag.Exceptions = exceptions;
|
||||
ViewBag.URLs = _AppSettingsURLs;
|
||||
ViewBag.Profile = _IsEnvironmentProfile;
|
||||
ViewBag.WorkingDirectory = _WorkingDirectory;
|
||||
ViewBag.IsPrimaryInstance = _IsPrimaryInstance;
|
||||
ViewBag.ExceptionsCount = string.Concat("Exception(s) - ", exceptions.Count);
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,352 +1,300 @@
|
||||
using APCViewer.Models;
|
||||
using APCViewer.Models.Methods;
|
||||
using APCViewer.Singleton;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
|
||||
namespace APCViewer.Controllers
|
||||
namespace APCViewer.Controllers;
|
||||
|
||||
public class HomeController : Controller, IHomeController
|
||||
{
|
||||
|
||||
public class HomeController : Controller, IHomeController
|
||||
private readonly Serilog.ILogger _Log;
|
||||
private readonly Background _Background;
|
||||
private readonly IBackground _BackgroundMethods;
|
||||
|
||||
public HomeController(Background background)
|
||||
{
|
||||
|
||||
private readonly Log _Log;
|
||||
private readonly Singleton.IBackground _Background;
|
||||
private readonly IHttpContextAccessor _HttpContextAccessor;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger, Singleton.IBackground background, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_Log = new Log(logger);
|
||||
_Background = background;
|
||||
_HttpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public ActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
|
||||
public ActionResult Encode(string value = null)
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
result = HttpUtility.UrlEncode(value);
|
||||
return Content(result, "text/plain");
|
||||
}
|
||||
|
||||
public ActionResult Background(bool? message_clear = null, bool? exceptions_clear = null, bool? set_is_primary_instance = null, bool? logistics_clear = null)
|
||||
{
|
||||
_Background.SendStatusOk();
|
||||
if (message_clear.HasValue && message_clear.Value)
|
||||
_Background.ClearMessage();
|
||||
if (exceptions_clear.HasValue && exceptions_clear.Value)
|
||||
_Background.Exceptions.Clear();
|
||||
if (set_is_primary_instance.HasValue)
|
||||
{
|
||||
if (set_is_primary_instance.Value)
|
||||
_Background.SetIsPrimaryInstance();
|
||||
else
|
||||
_Background.ClearIsPrimaryInstance();
|
||||
}
|
||||
if (logistics_clear.HasValue && logistics_clear.Value)
|
||||
_Background.LogisticsClear();
|
||||
string message;
|
||||
if (string.IsNullOrWhiteSpace(_Background.Message))
|
||||
message = "N/A";
|
||||
else
|
||||
message = _Background.Message;
|
||||
//Response.AppendToLog(_Background.Message);
|
||||
List<Exception> exceptions = new();
|
||||
foreach (Exception exception in _Background.Exceptions)
|
||||
exceptions.Add(exception);
|
||||
ViewBag.Message = message;
|
||||
ViewBag.Exceptions = exceptions;
|
||||
ViewBag.URLs = _Background.AppSettings.URLs;
|
||||
ViewBag.Profile = _Background.IsEnvironment.Profile;
|
||||
ViewBag.WorkingDirectory = _Background.WorkingDirectory;
|
||||
ViewBag.IsPrimaryInstance = _Background.IsPrimaryInstance();
|
||||
ViewBag.ExceptionsCount = string.Concat("Exception(s) - ", exceptions.Count);
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult PDSF(string directory = null, string filter = null, bool is_gaN = false, bool is_Si = false)
|
||||
{
|
||||
Tuple<int, object, object, string> tuple = _Background.SetViewBag(directory, filter, isGaN: is_gaN, isSi: is_Si, forPDSF: true);
|
||||
ViewBag.Files = tuple.Item1;
|
||||
ViewBag.Grouped = tuple.Item2;
|
||||
ViewBag.Sorted = tuple.Item3;
|
||||
ViewBag.Directory = tuple.Item4;
|
||||
return View();
|
||||
}
|
||||
|
||||
private StringBuilder GetPDSFHtml(string pdsfFile)
|
||||
{
|
||||
StringBuilder result = new();
|
||||
result.AppendLine("<html><body><table border = '1'>");
|
||||
if (string.IsNullOrEmpty(pdsfFile))
|
||||
throw new Exception("<tr><td>Invalid input</td></tr>");
|
||||
else if (!System.IO.File.Exists(pdsfFile))
|
||||
result.AppendLine("<tr><td>File doesn't exist!</td></tr>");
|
||||
else
|
||||
{
|
||||
bool header = true;
|
||||
bool body = false;
|
||||
bool footer = false;
|
||||
string logisticsSegment;
|
||||
List<string> logistics = new();
|
||||
string[] pdsfLines = System.IO.File.ReadAllLines(pdsfFile);
|
||||
foreach (string pdsfLine in pdsfLines)
|
||||
{
|
||||
if (pdsfLine.StartsWith("LOGISTICS_"))
|
||||
{
|
||||
logisticsSegment = pdsfLine.Split('\t')[0];
|
||||
if (!logistics.Contains(logisticsSegment))
|
||||
{
|
||||
logistics.Add(logisticsSegment);
|
||||
result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
}
|
||||
if (pdsfLine.StartsWith("NUM_DATA_ROWS") || pdsfLine.StartsWith("END_HEADER"))
|
||||
{
|
||||
body = false;
|
||||
footer = true;
|
||||
result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
if (header)
|
||||
result.Append("<tr><td>").Append(pdsfLine.Replace("\t", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else if (body)
|
||||
result.Append("<tr><td>").Append(pdsfLine.Replace("\t", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else if (footer)
|
||||
{
|
||||
if (pdsfLine.StartsWith("DELIMITER"))
|
||||
result.Append("<tr><td>").Append(pdsfLine.Replace(";", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else
|
||||
result.Append("<tr><td>").Append(pdsfLine.Replace("\t", "</td><td>").Replace("=", "</td><td>").Replace(";", "</td><td>")).AppendLine(" </td></tr>");
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
if (pdsfLine.StartsWith("END_OFFSET"))
|
||||
{
|
||||
header = false;
|
||||
body = true;
|
||||
result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
}
|
||||
}
|
||||
result.AppendLine("</table></body>");
|
||||
return result;
|
||||
}
|
||||
|
||||
public ContentResult ViewPDSF(string id = null)
|
||||
{
|
||||
string pdsfFile;
|
||||
StringBuilder result = new();
|
||||
if (!id.Contains('_'))
|
||||
result.AppendLine("<html><body><table border = '1'><tr><td>A) Error: Invalid input</td></tr></table></body>");
|
||||
else
|
||||
{
|
||||
if (!long.TryParse(id.Split('_')[1], out long sequence))
|
||||
result.AppendLine("<html><body><table border = '1'><tr><td>B) Error: Invalid input</td></tr></table></body>");
|
||||
else
|
||||
{
|
||||
pdsfFile = _Background.GetPDSF(sequence);
|
||||
result = GetPDSFHtml(pdsfFile);
|
||||
}
|
||||
}
|
||||
return Content(result.ToString(), "text/html");
|
||||
}
|
||||
|
||||
public ActionResult DownloadPDSF(string id = null)
|
||||
{
|
||||
string pdsfFile;
|
||||
if (!id.Contains('_'))
|
||||
throw new Exception("A) Error: Invalid input");
|
||||
else
|
||||
{
|
||||
if (!long.TryParse(id.Split('_')[1], out long sequence))
|
||||
throw new Exception("B) Error: Invalid input");
|
||||
else
|
||||
pdsfFile = _Background.GetPDSF(sequence);
|
||||
}
|
||||
return File(pdsfFile, "text/plain", Path.GetFileName(pdsfFile));
|
||||
}
|
||||
|
||||
public ContentResult ViewCustomPDSF(string pdsf_file = null)
|
||||
{
|
||||
StringBuilder result = GetPDSFHtml(pdsf_file);
|
||||
return Content(result.ToString(), "text/html");
|
||||
}
|
||||
|
||||
public ActionResult DownloadCustomPDSF(string pdsf_file = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pdsf_file))
|
||||
throw new Exception("Error: Invalid input");
|
||||
else if (!System.IO.File.Exists(pdsf_file))
|
||||
throw new Exception("Error: file does not exist");
|
||||
return File(pdsf_file, "text/plain", Path.GetFileName(pdsf_file));
|
||||
}
|
||||
|
||||
public ActionResult IPDSF(string directory = null, string filter = null, bool is_gaN = false, bool is_Si = false)
|
||||
{
|
||||
Tuple<int, object, object, string> tuple = _Background.SetViewBag(directory, filter, isGaN: is_gaN, isSi: is_Si, forIPDSF: true);
|
||||
ViewBag.Files = tuple.Item1;
|
||||
ViewBag.Grouped = tuple.Item2;
|
||||
ViewBag.Sorted = tuple.Item3;
|
||||
ViewBag.Directory = tuple.Item4;
|
||||
return View();
|
||||
}
|
||||
|
||||
private StringBuilder GetIPDSFHtml(string ipdsfFile)
|
||||
{
|
||||
StringBuilder result = new();
|
||||
result.AppendLine("<html><body><table border = '1'>");
|
||||
if (string.IsNullOrEmpty(ipdsfFile))
|
||||
throw new Exception("<tr><td>Invalid input</td></tr>");
|
||||
else if (!System.IO.File.Exists(ipdsfFile))
|
||||
result.AppendLine("<tr><td>File doesn't exist!</td></tr>");
|
||||
else
|
||||
{
|
||||
bool header = true;
|
||||
bool body = false;
|
||||
bool footer = false;
|
||||
string logisticsSegment;
|
||||
List<string> logistics = new();
|
||||
string[] ipdsfLines = System.IO.File.ReadAllLines(ipdsfFile);
|
||||
foreach (string ipdsfLine in ipdsfLines)
|
||||
{
|
||||
if (ipdsfLine.StartsWith("LOGISTICS_"))
|
||||
{
|
||||
logisticsSegment = ipdsfLine.Split('\t')[0];
|
||||
if (!logistics.Contains(logisticsSegment))
|
||||
{
|
||||
logistics.Add(logisticsSegment);
|
||||
result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
}
|
||||
if (ipdsfLine.StartsWith("NUM_DATA_ROWS") || ipdsfLine.StartsWith("END_HEADER"))
|
||||
{
|
||||
body = false;
|
||||
footer = true;
|
||||
result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
if (header)
|
||||
result.Append("<tr><td>").Append(ipdsfLine.Replace("\t", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else if (body)
|
||||
result.Append("<tr><td>").Append(ipdsfLine.Replace("\t", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else if (footer)
|
||||
{
|
||||
if (ipdsfLine.StartsWith("DELIMITER"))
|
||||
result.Append("<tr><td>").Append(ipdsfLine.Replace(";", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else
|
||||
result.Append("<tr><td>").Append(ipdsfLine.Replace("\t", "</td><td>").Replace("=", "</td><td>").Replace(";", "</td><td>")).AppendLine(" </td></tr>");
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
if (ipdsfLine.StartsWith("END_OFFSET"))
|
||||
{
|
||||
header = false;
|
||||
body = true;
|
||||
result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
}
|
||||
}
|
||||
result.AppendLine("</table></body>");
|
||||
return result;
|
||||
}
|
||||
|
||||
public ContentResult ViewIPDSF(string id = null)
|
||||
{
|
||||
string ipdsfFile;
|
||||
StringBuilder result = new();
|
||||
if (!id.Contains('_'))
|
||||
result.AppendLine("<html><body><table border = '1'><tr><td>A) Error: Invalid input</td></tr></table></body>");
|
||||
else
|
||||
{
|
||||
if (!long.TryParse(id.Split('_')[1], out long sequence))
|
||||
result.AppendLine("<html><body><table border = '1'><tr><td>B) Error: Invalid input</td></tr></table></body>");
|
||||
else
|
||||
{
|
||||
ipdsfFile = _Background.GetIPDSF(sequence);
|
||||
result = GetIPDSFHtml(ipdsfFile);
|
||||
}
|
||||
}
|
||||
return Content(result.ToString(), "text/html");
|
||||
}
|
||||
|
||||
public ActionResult DownloadIPDSF(string id = null)
|
||||
{
|
||||
string ipdsfFile;
|
||||
if (!id.Contains('_'))
|
||||
throw new Exception("A) Error: Invalid input");
|
||||
else
|
||||
{
|
||||
if (!long.TryParse(id.Split('_')[1], out long sequence))
|
||||
throw new Exception("B) Error: Invalid input");
|
||||
else
|
||||
ipdsfFile = _Background.GetIPDSF(sequence);
|
||||
}
|
||||
return File(ipdsfFile, "text/plain", Path.GetFileName(ipdsfFile));
|
||||
}
|
||||
|
||||
public ContentResult ViewCustomIPDSF(string ipdsf_file = null)
|
||||
{
|
||||
StringBuilder result = GetIPDSFHtml(ipdsf_file);
|
||||
return Content(result.ToString(), "text/html");
|
||||
}
|
||||
|
||||
public ActionResult DownloadCustomIPDSF(string ipdsf_file = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ipdsf_file))
|
||||
throw new Exception("Error: Invalid input");
|
||||
else if (!System.IO.File.Exists(ipdsf_file))
|
||||
throw new Exception("Error: file does not exist");
|
||||
return File(ipdsf_file, "text/plain", Path.GetFileName(ipdsf_file));
|
||||
}
|
||||
|
||||
public ActionResult TimePivot(bool is_gaN = false, bool is_Si = false)
|
||||
{
|
||||
Tuple<List<string[]>, List<string[]>> tuple = _Background.GetTimePivot(isGaN: is_gaN, isSi: is_Si);
|
||||
ViewBag.forIPDSF = tuple.Item1;
|
||||
ViewBag.forPDSF = tuple.Item2;
|
||||
return View();
|
||||
}
|
||||
|
||||
IActionResult IHomeController.Background(bool? message_clear, bool? exceptions_clear, bool? set_is_primary_instance, bool? logistics_clear) => throw new NotImplementedException();
|
||||
IActionResult IHomeController.DownloadCustomIPDSF(string ipdsf_file) => throw new NotImplementedException();
|
||||
IActionResult IHomeController.DownloadCustomPDSF(string pdsf_file) => throw new NotImplementedException();
|
||||
IActionResult IHomeController.DownloadIPDSF(string id) => throw new NotImplementedException();
|
||||
IActionResult IHomeController.DownloadPDSF(string id) => throw new NotImplementedException();
|
||||
IActionResult IHomeController.Encode(string value) => throw new NotImplementedException();
|
||||
IActionResult IHomeController.Error() => throw new NotImplementedException();
|
||||
IActionResult IHomeController.Index() => throw new NotImplementedException();
|
||||
IActionResult IHomeController.IPDSF(string directory, string filter, bool is_gaN, bool is_Si) => throw new NotImplementedException();
|
||||
IActionResult IHomeController.PDSF(string directory, string filter, bool is_gaN, bool is_Si) => throw new NotImplementedException();
|
||||
IActionResult IHomeController.Privacy() => throw new NotImplementedException();
|
||||
IActionResult IHomeController.TimePivot(bool is_gaN, bool is_Si) => throw new NotImplementedException();
|
||||
_Background = background;
|
||||
_BackgroundMethods = background;
|
||||
_Log = Serilog.Log.ForContext<HomeController>();
|
||||
}
|
||||
|
||||
}
|
||||
// dotnet publish --configuration Release --runtime win-x64 --verbosity normal --self-contained true -o "L:\net5.0\APCViewer"
|
||||
// dotnet publish --configuration Release --runtime win-x64 --verbosity normal --self-contained true -o "D:\net5.0\APCViewer"
|
||||
// dotnet publish --configuration Release --runtime win-x64 --verbosity normal --self-contained true -o "D:\.jenkins\publish\manual-Mesa-0\APCViewer"
|
||||
//http://mestsa005.infineon.com:8080/job/Mesa/buildWithParameters?token=DotnetRules&projectName=APC%20Viewer
|
||||
// http://mestsa02ec.ec.local:8080/job/Mesa/buildWithParameters?token=DotnetRules&projectName=APC%20Viewer
|
||||
//sc create APCViewer_5003 binPath="D:\.jenkins\publish\manual-Mesa-0\APCViewer\APC Viewer.exe"
|
||||
public ActionResult Index() => View();
|
||||
|
||||
public ActionResult Privacy() => View();
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public ActionResult Error() => View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
|
||||
public ActionResult Encode(string value = "")
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
result = HttpUtility.UrlEncode(value);
|
||||
return Content(result, "text/plain");
|
||||
}
|
||||
|
||||
public ActionResult TestTry()
|
||||
{
|
||||
ActionResult result;
|
||||
try
|
||||
{
|
||||
throw new Exception("This is a test");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = Content(string.Concat(ex.Message, Environment.NewLine, Environment.NewLine, ex.StackTrace));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ActionResult PDSF(string? directory = null, string? filter = null, bool is_gaN = false, bool is_Si = false)
|
||||
{
|
||||
Tuple<int, object, object, string?> tuple = _Background.SetViewBag(directory, filter, isGaN: is_gaN, isSi: is_Si, forPDSF: true);
|
||||
ViewBag.Files = tuple.Item1;
|
||||
ViewBag.Grouped = tuple.Item2;
|
||||
ViewBag.Sorted = tuple.Item3;
|
||||
ViewBag.Directory = tuple.Item4;
|
||||
return View();
|
||||
}
|
||||
|
||||
private static StringBuilder GetPDSFHtml(string? pdsfFile)
|
||||
{
|
||||
StringBuilder result = new();
|
||||
_ = result.AppendLine("<html><body><table border = '1'>");
|
||||
if (string.IsNullOrEmpty(pdsfFile))
|
||||
throw new Exception("<tr><td>Invalid input</td></tr>");
|
||||
else if (!System.IO.File.Exists(pdsfFile))
|
||||
_ = result.AppendLine("<tr><td>File doesn't exist!</td></tr>");
|
||||
else
|
||||
{
|
||||
bool header = true;
|
||||
bool body = false;
|
||||
bool footer = false;
|
||||
string logisticsSegment;
|
||||
List<string> logistics = new();
|
||||
string[] pdsfLines = System.IO.File.ReadAllLines(pdsfFile);
|
||||
foreach (string pdsfLine in pdsfLines)
|
||||
{
|
||||
if (pdsfLine.StartsWith("LOGISTICS_"))
|
||||
{
|
||||
logisticsSegment = pdsfLine.Split('\t')[0];
|
||||
if (!logistics.Contains(logisticsSegment))
|
||||
{
|
||||
logistics.Add(logisticsSegment);
|
||||
_ = result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
}
|
||||
if (pdsfLine.StartsWith("NUM_DATA_ROWS") || pdsfLine.StartsWith("END_HEADER"))
|
||||
{
|
||||
body = false;
|
||||
footer = true;
|
||||
_ = result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
if (header)
|
||||
_ = result.Append("<tr><td>").Append(pdsfLine.Replace("\t", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else if (body)
|
||||
_ = result.Append("<tr><td>").Append(pdsfLine.Replace("\t", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else if (footer)
|
||||
{
|
||||
if (pdsfLine.StartsWith("DELIMITER"))
|
||||
_ = result.Append("<tr><td>").Append(pdsfLine.Replace(";", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else
|
||||
_ = result.Append("<tr><td>").Append(pdsfLine.Replace("\t", "</td><td>").Replace("=", "</td><td>").Replace(";", "</td><td>")).AppendLine(" </td></tr>");
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
if (pdsfLine.StartsWith("END_OFFSET"))
|
||||
{
|
||||
header = false;
|
||||
body = true;
|
||||
_ = result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
}
|
||||
}
|
||||
_ = result.AppendLine("</table></body>");
|
||||
return result;
|
||||
}
|
||||
|
||||
public ContentResult ViewPDSF(string? id = null)
|
||||
{
|
||||
string pdsfFile;
|
||||
StringBuilder result = new();
|
||||
if (string.IsNullOrEmpty(id) || !id.Contains('_'))
|
||||
_ = result.AppendLine("<html><body><table border = '1'><tr><td>A) Error: Invalid input</td></tr></table></body>");
|
||||
else
|
||||
{
|
||||
if (!long.TryParse(id.Split('_')[1], out long sequence))
|
||||
_ = result.AppendLine("<html><body><table border = '1'><tr><td>B) Error: Invalid input</td></tr></table></body>");
|
||||
else
|
||||
{
|
||||
pdsfFile = _Background.GetPDSF(sequence);
|
||||
result = GetPDSFHtml(pdsfFile);
|
||||
}
|
||||
}
|
||||
return Content(result.ToString(), "text/html");
|
||||
}
|
||||
|
||||
public ActionResult DownloadPDSF(string? id = null)
|
||||
{
|
||||
string pdsfFile;
|
||||
if (string.IsNullOrEmpty(id) || !id.Contains('_'))
|
||||
throw new Exception("A) Error: Invalid input");
|
||||
else
|
||||
{
|
||||
if (!long.TryParse(id.Split('_')[1], out long sequence))
|
||||
throw new Exception("B) Error: Invalid input");
|
||||
else
|
||||
pdsfFile = _Background.GetPDSF(sequence);
|
||||
}
|
||||
return File(pdsfFile, "text/plain", Path.GetFileName(pdsfFile));
|
||||
}
|
||||
|
||||
public ContentResult ViewCustomPDSF(string? pdsf_file = null)
|
||||
{
|
||||
StringBuilder result = GetPDSFHtml(pdsf_file);
|
||||
return Content(result.ToString(), "text/html");
|
||||
}
|
||||
|
||||
public ActionResult DownloadCustomPDSF(string? pdsf_file = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pdsf_file))
|
||||
throw new Exception("Error: Invalid input");
|
||||
else if (!System.IO.File.Exists(pdsf_file))
|
||||
throw new Exception("Error: file does not exist");
|
||||
return File(pdsf_file, "text/plain", Path.GetFileName(pdsf_file));
|
||||
}
|
||||
|
||||
public ActionResult IPDSF(string? directory = null, string? filter = null, bool is_gaN = false, bool is_Si = false)
|
||||
{
|
||||
Tuple<int, object, object, string?> tuple = _Background.SetViewBag(directory, filter, isGaN: is_gaN, isSi: is_Si, forIPDSF: true);
|
||||
ViewBag.Files = tuple.Item1;
|
||||
ViewBag.Grouped = tuple.Item2;
|
||||
ViewBag.Sorted = tuple.Item3;
|
||||
ViewBag.Directory = tuple.Item4;
|
||||
return View();
|
||||
}
|
||||
|
||||
private static StringBuilder GetIPDSFHtml(string? ipdsfFile)
|
||||
{
|
||||
StringBuilder result = new();
|
||||
_ = result.AppendLine("<html><body><table border = '1'>");
|
||||
if (string.IsNullOrEmpty(ipdsfFile))
|
||||
throw new Exception("<tr><td>Invalid input</td></tr>");
|
||||
else if (!System.IO.File.Exists(ipdsfFile))
|
||||
_ = result.AppendLine("<tr><td>File doesn't exist!</td></tr>");
|
||||
else
|
||||
{
|
||||
bool header = true;
|
||||
bool body = false;
|
||||
bool footer = false;
|
||||
string logisticsSegment;
|
||||
List<string> logistics = new();
|
||||
string[] ipdsfLines = System.IO.File.ReadAllLines(ipdsfFile);
|
||||
foreach (string ipdsfLine in ipdsfLines)
|
||||
{
|
||||
if (ipdsfLine.StartsWith("LOGISTICS_"))
|
||||
{
|
||||
logisticsSegment = ipdsfLine.Split('\t')[0];
|
||||
if (!logistics.Contains(logisticsSegment))
|
||||
{
|
||||
logistics.Add(logisticsSegment);
|
||||
_ = result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
}
|
||||
if (ipdsfLine.StartsWith("NUM_DATA_ROWS") || ipdsfLine.StartsWith("END_HEADER"))
|
||||
{
|
||||
body = false;
|
||||
footer = true;
|
||||
_ = result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
if (header)
|
||||
_ = result.Append("<tr><td>").Append(ipdsfLine.Replace("\t", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else if (body)
|
||||
_ = result.Append("<tr><td>").Append(ipdsfLine.Replace("\t", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else if (footer)
|
||||
{
|
||||
if (ipdsfLine.StartsWith("DELIMITER"))
|
||||
_ = result.Append("<tr><td>").Append(ipdsfLine.Replace(";", "</td><td>")).AppendLine(" </td></tr>");
|
||||
else
|
||||
_ = result.Append("<tr><td>").Append(ipdsfLine.Replace("\t", "</td><td>").Replace("=", "</td><td>").Replace(";", "</td><td>")).AppendLine(" </td></tr>");
|
||||
}
|
||||
else
|
||||
throw new Exception();
|
||||
if (ipdsfLine.StartsWith("END_OFFSET"))
|
||||
{
|
||||
header = false;
|
||||
body = true;
|
||||
_ = result.AppendLine("</table><hr /><table border = '1'>");
|
||||
}
|
||||
}
|
||||
}
|
||||
_ = result.AppendLine("</table></body>");
|
||||
return result;
|
||||
}
|
||||
|
||||
public ContentResult ViewIPDSF(string? id = null)
|
||||
{
|
||||
string ipdsfFile;
|
||||
StringBuilder result = new();
|
||||
if (string.IsNullOrEmpty(id) || !id.Contains('_'))
|
||||
_ = result.AppendLine("<html><body><table border = '1'><tr><td>A) Error: Invalid input</td></tr></table></body>");
|
||||
else
|
||||
{
|
||||
if (!long.TryParse(id.Split('_')[1], out long sequence))
|
||||
_ = result.AppendLine("<html><body><table border = '1'><tr><td>B) Error: Invalid input</td></tr></table></body>");
|
||||
else
|
||||
{
|
||||
ipdsfFile = _Background.GetIPDSF(sequence);
|
||||
result = GetIPDSFHtml(ipdsfFile);
|
||||
}
|
||||
}
|
||||
return Content(result.ToString(), "text/html");
|
||||
}
|
||||
|
||||
public ActionResult DownloadIPDSF(string? id = null)
|
||||
{
|
||||
string ipdsfFile;
|
||||
if (string.IsNullOrEmpty(id) || !id.Contains('_'))
|
||||
throw new Exception("A) Error: Invalid input");
|
||||
else
|
||||
{
|
||||
if (!long.TryParse(id.Split('_')[1], out long sequence))
|
||||
throw new Exception("B) Error: Invalid input");
|
||||
else
|
||||
ipdsfFile = _Background.GetIPDSF(sequence);
|
||||
}
|
||||
return File(ipdsfFile, "text/plain", Path.GetFileName(ipdsfFile));
|
||||
}
|
||||
|
||||
public ContentResult ViewCustomIPDSF(string? ipdsf_file = null)
|
||||
{
|
||||
StringBuilder result = GetIPDSFHtml(ipdsf_file);
|
||||
return Content(result.ToString(), "text/html");
|
||||
}
|
||||
|
||||
public ActionResult DownloadCustomIPDSF(string? ipdsf_file = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ipdsf_file))
|
||||
throw new Exception("Error: Invalid input");
|
||||
else if (!System.IO.File.Exists(ipdsf_file))
|
||||
throw new Exception("Error: file does not exist");
|
||||
return File(ipdsf_file, "text/plain", Path.GetFileName(ipdsf_file));
|
||||
}
|
||||
|
||||
public ActionResult TimePivot(bool is_gaN = false, bool is_Si = false)
|
||||
{
|
||||
Tuple<List<string[]>, List<string[]>> tuple = _Background.GetTimePivot(isGaN: is_gaN, isSi: is_Si);
|
||||
ViewBag.forIPDSF = tuple.Item1;
|
||||
ViewBag.forPDSF = tuple.Item2;
|
||||
return View();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user