Mostly EOL and LUT Management

This commit is contained in:
Roland Drabesch
2022-08-10 17:06:09 +02:00
parent f819392e7e
commit 0c3e28b8bd
24 changed files with 1116 additions and 241 deletions
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Logic.ProductionToProductMapper.Cordonel;
using Newtonsoft.Json;
using Service.Core;
using System;
using System.Collections.Generic;
@@ -10,10 +11,8 @@ using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Consts;
using Xylem.Common.Logic.ProductionOrderCore.File;
using Xylem.Common.Logic.ProductionOrderCore.FW;
using Logic.ProductionToProductMapper.Cordonel;
namespace Xylem.Common.Service.MeterProcessState.Controllers
{
@@ -154,6 +153,89 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers
}
/// <summary>
/// Set LUT JSON content
/// </summary>
/// <returns></returns>
[Route("PostLutFile"), HttpPost]
public async Task<HttpResponseMessage> PostLutFile(int DataLength, string version, int crc, int Metersize, string Region)
{
var httpFiles = HttpContext.Current.Request.Files;
var listOfFiles = new List<Tuple<string, byte[]>>();
foreach (var a in httpFiles)
{
try
{
if (HttpContext.Current.Request.Files[a.ToString()] is HttpPostedFile f)
{
listOfFiles.Add(new Tuple<string, byte[]>(f.FileName, GetFileBytes(f)));
}
}
catch (Exception)
{
}
}
var fileID = 0;
return await Task.Run(() =>
{
try
{
int? retId = null;
int FileCounter = StoreFiles(out retId, true, listOfFiles.First().Item1, FileCategoryID: 7, listOfFiles: listOfFiles);
if (FileCounter == listOfFiles.Count && retId.HasValue)
{
fileID = retId.Value;
}
if (fileID != 0)
{
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
{
var sb = new StringBuilder();
sb.AppendLine($" insert into [Cordonel_Lut] ");
sb.AppendLine($" select ");
sb.AppendLine($" {fileID} ");
sb.AppendLine($" , {DataLength} ");
sb.AppendLine($" , '{version}' ");
sb.AppendLine($" , '{crc}' ");
sb.AppendLine($" , '{Metersize}' ");
sb.AppendLine($" , '{Region}' ");
sb.AppendLine($" , 0 "); // [CurrentVerionForProd]
sb.AppendLine($" select @@IDENTITY ");
var retDT = dataacces.ExecuteQuery(sb.ToString());
return Request.CreateResponse(HttpStatusCode.OK, retDT.Rows[0][0]);
}
}
else
{
throw new ApplicationException($"file was not uploaded. Without error");
}
}
catch (Exception ex)
{
throw new ApplicationException($"file was not uploaded {ex.Message}");
}
throw new ApplicationException("file was not uploaded");
});
}
public virtual byte[] GetFileBytes(HttpPostedFile uploadedFile)
{
var bytes = new byte[uploadedFile.ContentLength];
@@ -162,6 +244,54 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers
}
/// <summary>
/// Set LUT JSON content
/// </summary>
/// <returns></returns>
[Route("GetLutFiles"), HttpGet]
public async Task<HttpResponseMessage> GetLutFiles(int? Metersize = null, string Region = null, bool? ForProd = null)
{
return await Task.Run(() =>
{
try
{
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
{
var sb = new StringBuilder();
sb.AppendLine($" SELECT [Id] ");
sb.AppendLine($" ,lut.[FileID] ");
sb.AppendLine($" ,[DataLength] ");
sb.AppendLine($" ,[Version] ");
sb.AppendLine($" ,[FileCrc] ");
sb.AppendLine($" ,[MeterSize] ");
sb.AppendLine($" ,[Region] ");
sb.AppendLine($" ,[CurrentVerionForProd] ");
sb.AppendLine($" ,files.[FileName] ");
sb.AppendLine($" ,files.FileContent ");
sb.AppendLine($" FROM [Auftrag].[dbo].[Cordonel_Lut] lut ");
sb.AppendLine($" inner join [Auftrag].[dbo].[FileClusterStore] fileMaster on fileMaster.FileId = lut.[FileID] ");
sb.AppendLine($" inner join [Auftrag].[dbo].[FileMapToCluster] map on fileMaster.FileIsDeleted = 0 and fileMaster.FileId = map.[FileMapToCluster_FileClusterId] ");
sb.AppendLine($" inner join [Auftrag].[dbo].[File] files on files.FileId = map.[FileMapToCluster_FileId] ");
var retDT = dataacces.ExecuteQuery(sb.ToString());
return Request.CreateResponse(HttpStatusCode.OK, retDT);
}
}
catch (Exception ex)
{
throw new ApplicationException($"file was not uploaded {ex.Message}");
}
throw new ApplicationException("file was not uploaded");
});
}
/// <summary>
/// Set TextFile content PostFileJsonContent
@@ -184,12 +314,12 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers
catch (Exception)
{
}
}
return await Task.Run(() =>
{
@@ -213,6 +343,7 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers
//4 Cordonel Update Safe
//5 Cordonel Update Sotware
//6 Cordonel Release Config
//7 Cordonel Look up table
FileClusterStoreId = null;