to long no commit
This commit is contained in:
@@ -12,7 +12,9 @@ using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using Xylem.Common.Cryptology.Security;
|
||||
using Xylem.Common.Logic.ProductionOrderCore.OrderData;
|
||||
using Xylem.ServiceFwUpdate.Common.FwUpdateDb;
|
||||
using Xylem.ServiceFwUpdate.Common.FwUpdateSafe;
|
||||
using Xylem.ServiceFwUpdate.Common.FwUpdateSafe.MeterRecovery;
|
||||
|
||||
namespace Xylem.Common.Service.MeterProcessState.Controllers
|
||||
@@ -707,25 +709,133 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers
|
||||
|
||||
}
|
||||
|
||||
[Route("GetFakeRecoveryFile"), HttpGet]
|
||||
public async Task<HttpResponseMessage> GetFakeRecoveryFile(int PcbID, int? RadioFrq, string Region, string FlexnetVersion)
|
||||
[Route("GetRecoveryFile"), HttpGet]
|
||||
public async Task<HttpResponseMessage> GetRecoveryFile(int PcbID, int? RadioFrq, string Region, string FlexnetVersion)
|
||||
{
|
||||
|
||||
var file = new RecoverySettings() { PrecondidtionCheckPcbID = PcbID, PrecondidtionCheckRadioFrq = RadioFrq , PrecondidtionCheckRegion = Region , PrecondidtionCheckFlexnetVersion = FlexnetVersion };
|
||||
|
||||
var file = new RecoverySettings() { PcbID = PcbID, RadioFrequencyMhz = RadioFrq, Region = Region, Release = FlexnetVersion };
|
||||
file.RecoveryRegisters = new List<ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem>();
|
||||
file.RecoveryRegisters.Add(new ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem() { RegisterIdent = "SENSUSRADIO_WakeupInterval", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x03 }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0x03 } });
|
||||
file.RecoveryRegisters.Add(new ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem() { RegisterIdent = "GENESISFLOW_SampleRate", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x02 }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0x02 } });
|
||||
file.RecoveryRegisters.Add(new ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem() { RegisterIdent = "GENESISFLOW_DisplayPow10", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0xFD }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0xFD } });
|
||||
file.RecoveryRegisters.Add(new RecoveryRegisterItem() { RegisterIdent = "GENESISFLOW_SealDisplay", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x00 }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0x00 } });
|
||||
|
||||
file.RecoveryRegisters.Add(new ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem() { RegisterIdent = "CUSTOMER_SerialNumber", WriteValue = new byte[] { 0x01, 0x02, 0x03, 0x04,0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00 }, IsCiritcal = false, ReadbackValue = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00 } });
|
||||
file.RecoveryRegisters.Add(new ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem() { RegisterIdent = "GENESISFLOW_StoreConfiguration", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x01 }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0x00 } });
|
||||
|
||||
|
||||
var csdRet = OrderProgrammingParameters.GetProgrammingParameters(PcbID.ToString(), GlobalConfig.connectionString.Value);
|
||||
|
||||
|
||||
foreach (var item in csdRet.Where(w => w.Source == Logic.ProductionOrderCore.ProgrammingSource.Vako))
|
||||
{
|
||||
file.RecoveryRegisters.Add(new RecoveryRegisterItem()
|
||||
{
|
||||
RegisterIdent = item.RegisterName,
|
||||
WriteValue = item.RegisterValue,
|
||||
ReadbackValue = null,
|
||||
IsCiritcal = false,
|
||||
Access = RegisterRecoveryAccess.SetAlways,
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var item in csdRet.Where(w => w.Source == Logic.ProductionOrderCore.ProgrammingSource.Csd))
|
||||
{
|
||||
file.RecoveryRegisters.Add(new RecoveryRegisterItem()
|
||||
{
|
||||
RegisterIdent = item.RegisterName,
|
||||
WriteValue = item.RegisterValue,
|
||||
ReadbackValue = null,
|
||||
IsCiritcal = false,
|
||||
Access = RegisterRecoveryAccess.SetAlways,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
file.RecoveryRegisters.Add(new RecoveryRegisterItem() { RegisterIdent = "GENESISFLOW_SealDisplay", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x01 }, IsCiritcal = true });
|
||||
|
||||
|
||||
file.RecoveryRegisters.Add(new RecoveryRegisterItem() { RegisterIdent = "SENSUSRADIO_SystemState", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x01 }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0x0c } });
|
||||
file.RecoveryRegisters.Add(new RecoveryRegisterItem() { RegisterIdent = "SENSUSRADIO_MainAlarmMask", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x00 } });
|
||||
file.RecoveryRegisters.Add(new RecoveryRegisterItem() { RegisterIdent = "SENSUSRADIO_ExtendedAlarmMask", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x00 } });
|
||||
|
||||
file.RecoveryRegisters.Add(new RecoveryRegisterItem() { RegisterIdent = "SENSUSRADIO_SystemState", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0xFF }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0x0c } });
|
||||
|
||||
|
||||
|
||||
var blacklist = new List<string>()
|
||||
{
|
||||
"CUSTOMER_RebootCount",
|
||||
"GENESISFLOW_ForwardArrow",
|
||||
"SENSUSRADIO_FrequencyOffset",
|
||||
"SENSUSRADIO_FrequencyIndicator",
|
||||
"PERIODICLOG_AverageFlowPeriod",
|
||||
"PERIODICLOG_PeriodicLogLifeTimeCounter",
|
||||
"SENSUSRADIO_MetroRadioLifeTimeCounter"
|
||||
|
||||
};
|
||||
|
||||
|
||||
var Crit = new List<string>()
|
||||
{
|
||||
"GENESISFLOW_SealDisplay",
|
||||
"GENESISFLOW_MeterSize",
|
||||
"GENESISFLOW_DisplayUnits",
|
||||
"METROLOGYASST_FlowUnits",
|
||||
"METROLOGYASST_FlowPoint",
|
||||
"METROLOGYASST_PressurePresent",
|
||||
"GENESISFLOW_DisplayPow10",
|
||||
"POWERMON_WarnFromClamp",
|
||||
"SYSTEM_UpgradePermissions",
|
||||
"POWERMON_BatteryQuantity",
|
||||
"GENESISFLOW_LedMode",
|
||||
"GENESISFLOW_LowFlowMaxPeriod",
|
||||
"GENESISFLOW_LowFlowThreshold",
|
||||
"GENESISFLOW_MaxValidAmplitude",
|
||||
"GENESISFLOW_MaxValidDeltaToF",
|
||||
"GENESISFLOW_MaxValidToF",
|
||||
"GENESISFLOW_MinValidAmplitude",
|
||||
"GENESISFLOW_MinValidToF",
|
||||
"GENESISFLOW_Timeout",
|
||||
"CUSTOMER_Locale",
|
||||
"SENSUSRADIO_EncryptionKey"
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
file.RecoveryRegisters.Where(d => Crit.Contains(d.RegisterIdent)).ToList().ForEach(f => { f.IsCiritcal = true; f.ReadbackValue = f.WriteValue; });
|
||||
|
||||
|
||||
|
||||
var onlyIfDefaultl = new List<string>()
|
||||
{
|
||||
"METROLOGYASST_PulseWeight",
|
||||
"METROLOGYASST_PressureUnits",
|
||||
"METROLOGYASST_TemperatureUnits",
|
||||
"METROLOGYASST_PulseLength",
|
||||
"METROLOGYASST_PulseMode",
|
||||
"CUSTOMER_LeakTimeThreshold",
|
||||
"CUSTOMER_ExcessFlowTimeThreshold",
|
||||
"CUSTOMER_ReverseFlowTimeThreshold",
|
||||
"CUSTOMER_TemperatureHighThreshold",
|
||||
"CUSTOMER_TemperatureHighDelay",
|
||||
"CUSTOMER_TemperatureLowThreshold",
|
||||
"CUSTOMER_TemperatureLowDelay",
|
||||
"CUSTOMER_PressureHighThreshold",
|
||||
"CUSTOMER_PressureHighDelay",
|
||||
"CUSTOMER_PressureLowThreshold",
|
||||
"CUSTOMER_PressureLowDelay",
|
||||
"CUSTOMER_LeakFlowThreshold",
|
||||
"METROLOGYASST_PressureOffset",
|
||||
|
||||
};
|
||||
|
||||
file.RecoveryRegisters.Where(d => onlyIfDefaultl.Contains(d.RegisterIdent)).ToList().ForEach(f => f.Access = RegisterRecoveryAccess.SetIfDefault);
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK, file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[Route("AddNewUser"), HttpGet]
|
||||
|
||||
@@ -0,0 +1,776 @@
|
||||
using Newtonsoft.Json;
|
||||
using Service.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using Xylem.Common.Cryptology.Security;
|
||||
using Xylem.ServiceFwUpdate.Common.FwUpdateDb;
|
||||
using Xylem.ServiceFwUpdate.Common.FwUpdateSafe.MeterRecovery;
|
||||
|
||||
namespace Xylem.Common.Service.MeterProcessState.Controllers
|
||||
{
|
||||
public class LutController : ApiController
|
||||
{
|
||||
public static class GlobalConfig
|
||||
{
|
||||
public static Lazy<string> connectionString = new Lazy<string>(()
|
||||
=>
|
||||
System.Configuration.ConfigurationManager.ConnectionStrings["default"].ConnectionString
|
||||
);
|
||||
}
|
||||
//
|
||||
[Route("GetLutList"), HttpGet]
|
||||
public async Task<HttpResponseMessage> GetLutList()
|
||||
{
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = new System.Collections.Generic.List<UserInformation>();
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($" SELECT [Id] , lut.[FileID] ,[DataLength] ,[Version] ,[FileCrc] ,[MeterSize] ,[FileContent] FROM[Auftrag].[dbo].[Cordonel_Lut] lut inner join [Auftrag].[dbo].[File] f on lut.FileID = f.FileId");
|
||||
|
||||
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
|
||||
foreach (DataRow row in dbResult.Rows)
|
||||
{
|
||||
ret.Add(
|
||||
new UserInformation((int)row["UserId"])
|
||||
{
|
||||
FullName = row["FullName"] == DBNull.Value ? "" : (string)row["FullName"],
|
||||
LogInName = (string)row["LogInName"],
|
||||
Domain = (string)row["Domain"],
|
||||
HardwareId = row["HardwareId"] == DBNull.Value ? "" : (string)row["HardwareId"],
|
||||
PasswordHash = row["PasswordHash"] == DBNull.Value ? "" : (string)row["PasswordHash"],
|
||||
RegisterDate = (DateTimeOffset)row["RegisterDate"],
|
||||
ValidDate = (DateTimeOffset)row["ValidDate"],
|
||||
AccountActive = (bool)row["AccountActive"],
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK, true);
|
||||
|
||||
|
||||
//return Request.CreateResponse(HttpStatusCode.OK, getUserList(LogInName, Id));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
[Route("GetAllBuilderOperator"), HttpGet]
|
||||
public async Task<HttpResponseMessage> GetAllBuilderOperator()
|
||||
{
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = new System.Collections.Generic.List<UserInformation>();
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($" select UserId, FullName,LogInName, Domain,HardwareId,AccountActive from FWUpdateBuilderUser ");
|
||||
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
|
||||
foreach (DataRow row in dbResult.Rows)
|
||||
{
|
||||
ret.Add(
|
||||
new UserInformation((int)row["UserId"])
|
||||
{
|
||||
FullName = row["FullName"] == DBNull.Value ? "" : (string)row["FullName"],
|
||||
LogInName = (string)row["LogInName"],
|
||||
Domain = (string)row["Domain"],
|
||||
HardwareId = row["HardwareId"] == DBNull.Value ? "" : (string)row["HardwareId"],
|
||||
AccountActive = (bool)row["AccountActive"],
|
||||
});
|
||||
|
||||
}
|
||||
return Request.CreateResponse(HttpStatusCode.OK, ret);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[Route("RefreshUsersHardwareId"), HttpGet]
|
||||
public async Task<HttpResponseMessage> RefreshUsersHardwareId(int id, string HardwareId)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = new System.Collections.Generic.List<UserInformation>();
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($" Update FWUpdateUser set HardwareId = '{HardwareId}' where UserId = {id} ");
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
return Request.CreateResponse(HttpStatusCode.OK, true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[Route("RefreshUsersPasswordHash"), HttpGet]
|
||||
public async Task<HttpResponseMessage> RefreshUsersPasswordHash(int id, string PasswordHash)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = new System.Collections.Generic.List<UserInformation>();
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($" Update FWUpdateUser set PasswordHash = '{PasswordHash}' where UserId = {id} ");
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
return Request.CreateResponse(HttpStatusCode.OK, true);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
[Route("EditUserValidity"), HttpGet]
|
||||
public async Task<HttpResponseMessage> EditUserValidity(int id, DateTimeOffset? ValidDate = null, bool? AccountActive = null)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ValidDate.HasValue || AccountActive.HasValue)
|
||||
{
|
||||
var ret = new System.Collections.Generic.List<UserInformation>();
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($" Update FWUpdateUser set ");
|
||||
|
||||
if (ValidDate.HasValue)
|
||||
{
|
||||
sb.AppendLine($" ValidDate = '{ValidDate.Value.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss +00:00")}' ");
|
||||
|
||||
}
|
||||
if (AccountActive.HasValue)
|
||||
{
|
||||
if (ValidDate.HasValue)
|
||||
{
|
||||
sb.AppendLine($" , ");
|
||||
}
|
||||
if (AccountActive.Value)
|
||||
{
|
||||
sb.AppendLine($" AccountActive = 1 ");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine($" AccountActive = 0 ");
|
||||
}
|
||||
}
|
||||
|
||||
sb.AppendLine($" where UserId = {id} ");
|
||||
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
return Request.CreateResponse(HttpStatusCode.OK, true);
|
||||
}
|
||||
}
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, "no change");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Route("GetFileContent"), HttpGet]
|
||||
public async Task<HttpResponseMessage> GetFileContent(int FileId)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($" SELECT TOP (1) [FileContent] FROM [Auftrag].[dbo].[File] where FileId = {FileId}");
|
||||
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK, dbResult.Rows[0][0]);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Route("GetFWUpdateSafeContainers"), HttpGet]
|
||||
public async Task<HttpResponseMessage> GetFWUpdateSafeContainers(int UserId)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var ret = new System.Collections.Generic.List<FwUpdateSafeDb>();
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($" select * from [dbo].[FWUpdateSafeContainer] ");
|
||||
sb.Append($" where FWUpdateSafeContainer_UserId ={UserId} ");
|
||||
//FWUpdateSafeContainer_ValidDate >= CURRENT_TIMESTAMP and
|
||||
|
||||
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
|
||||
foreach (DataRow row in dbResult.Rows)
|
||||
{
|
||||
ret.Add(
|
||||
new FwUpdateSafeDb()
|
||||
{
|
||||
ContainerId = (int)row["FWUpdateSafeContainer_ID"],
|
||||
Name = (string)row["FWUpdateSafeContainer_Name"],
|
||||
UserId = (int)row["FWUpdateSafeContainer_UserId"],
|
||||
FilePartId = (int)row["FWUpdateSafeContainer_FileId"],
|
||||
ValidDate = (DateTime)row["FWUpdateSafeContainer_ValidDate"]
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
return Request.CreateResponse(HttpStatusCode.OK, ret);
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
[Route("AddPcbIdsToSafe"), HttpPost]
|
||||
public async Task<HttpResponseMessage> AddPcbIdsToSafe(int ContainerDbId, [FromBody] List<int> PcbIds)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
StringBuilder sb = null;
|
||||
|
||||
|
||||
foreach (var item in PcbIds)
|
||||
{
|
||||
if (sb == null)
|
||||
{
|
||||
sb = new StringBuilder();
|
||||
sb.AppendLine($" insert into FWUpdateSafeContainerPcbIds ");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine($" UNION ");
|
||||
}
|
||||
sb.AppendLine($" SELECT {ContainerDbId}, {item}");
|
||||
}
|
||||
|
||||
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
return Request.CreateResponse(HttpStatusCode.OK, true);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[Route("GetPcbIdsFromSafe"), HttpGet]
|
||||
public async Task<HttpResponseMessage> GetPcbIdsFromSafe(int ContainerDbId)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var ret = new System.Collections.Generic.List<int>();
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($" select [FWUpdateSafeContainer_PcbId] from [dbo].[FWUpdateSafeContainerPcbIds] ");
|
||||
sb.Append($" where [FWUpdateSafeContainer_ID] = {ContainerDbId} ");
|
||||
|
||||
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
|
||||
foreach (DataRow row in dbResult.Rows)
|
||||
{
|
||||
ret.Add((int)row["FWUpdateSafeContainer_PcbId"]);
|
||||
|
||||
}
|
||||
}
|
||||
return Request.CreateResponse(HttpStatusCode.OK, ret);
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
[Route("PostFWUpdateSafeOdd"), HttpPost]
|
||||
public async Task<HttpResponseMessage> PostFWUpdateSafeOdd(int PUserId, string PFileName, DateTime PValidDate, string PBuilderOperatorName = "none")
|
||||
{
|
||||
var inpStrem = HttpContext.Current.Request.GetBufferlessInputStream(true);
|
||||
var inpHeaders = Request.Content.Headers;
|
||||
return await Task.Run(async () =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var parameters = new List<System.Data.SqlClient.SqlParameter>();
|
||||
var FileName = new System.Data.SqlClient.SqlParameter("@FileName", SqlDbType.NVarChar, 50);
|
||||
var UserId = new System.Data.SqlClient.SqlParameter("@UserId", SqlDbType.Int);
|
||||
var ValidDate = new System.Data.SqlClient.SqlParameter("@ValidDate", SqlDbType.Date);
|
||||
|
||||
|
||||
FileName.Value = PFileName;
|
||||
UserId.Value = PUserId;
|
||||
ValidDate.Value = PValidDate;
|
||||
|
||||
|
||||
parameters.Add(ValidDate);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($" Declare @FileID as int ");
|
||||
sb.AppendLine($" Declare @FileName as NVarChar(50) ");
|
||||
sb.AppendLine($" Declare @UserId as int ");
|
||||
sb.AppendLine($" set @FileName = '{PFileName}' ");
|
||||
sb.AppendLine($" set @UserId = {PUserId} ");
|
||||
|
||||
|
||||
//sb.AppendLine($" INSERT INTO [dbo].[File] ([FileContent], [FileName]) VALUES (@FileContent, @FileName) ;");
|
||||
//sb.AppendLine($" SELECT @FileID = @@IDENTITY; ");
|
||||
sb.AppendLine($" INSERT INTO [dbo].[FWUpdateSafeContainer] ([FWUpdateSafeContainer_Name],[FWUpdateSafeContainer_UserId],[FWUpdateSafeContainer_FileId],[FWUpdateSafeContainer_ValidDate])");
|
||||
sb.AppendLine($" VALUES(@FileName,@UserId,0,@ValidDate); ");
|
||||
sb.AppendLine($" select @@IDENTITY as ContainerID, @FileID as FilePartId ");
|
||||
|
||||
|
||||
|
||||
var retDT = dataacces.ExecuteQuery(sb.ToString(), parameters);
|
||||
var newID = Convert.ToInt32(retDT.Rows[0][0].ToString());
|
||||
|
||||
var fileuploadPath = $"C:\\\\Temp\\{newID}\\";
|
||||
Directory.CreateDirectory(fileuploadPath);
|
||||
var provider = new MultipartFormDataStreamProvider(fileuploadPath);
|
||||
var content = new StreamContent(inpStrem);
|
||||
foreach (var header in inpHeaders)
|
||||
{
|
||||
content.Headers.TryAddWithoutValidation(header.Key, header.Value);
|
||||
}
|
||||
|
||||
await content.ReadAsMultipartAsync(provider);
|
||||
|
||||
string uploadingFileName = provider.FileData.Select(x => x.LocalFileName).FirstOrDefault();
|
||||
string originalFileName = String.Concat(fileuploadPath, "\\" + (provider.Contents[0].Headers.ContentDisposition.FileName).Trim(new Char[] { '"' }));
|
||||
|
||||
if (File.Exists(originalFileName))
|
||||
{
|
||||
File.Delete(originalFileName);
|
||||
}
|
||||
|
||||
File.Move(uploadingFileName, originalFileName);
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK, newID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
[Route("GetFWUpdateSafeContainerContent"), HttpGet]
|
||||
public async Task<HttpResponseMessage> GetFWUpdateSafeContainerContent(int SafeContainerId)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var ret = new System.Collections.Generic.List<FwUpdateSafeDb>();
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($" select * from [dbo].[FWUpdateSafeContainer] ");
|
||||
sb.Append($" where FWUpdateSafeContainer_ValidDate >= CURRENT_TIMESTAMP and FWUpdateSafeContainer_ID ={SafeContainerId} ");
|
||||
|
||||
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
|
||||
foreach (DataRow row in dbResult.Rows)
|
||||
{
|
||||
var content = new byte[] { };
|
||||
var filePath = $"C:\\\\Temp\\{(int)row["FWUpdateSafeContainer_ID"]}\\{(string)row["FWUpdateSafeContainer_Name"]}";
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
content = File.ReadAllBytes(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
content = ASCIIEncoding.ASCII.GetBytes("File Not Found");
|
||||
}
|
||||
ret.Add(
|
||||
new FwUpdateSafeDb()
|
||||
{
|
||||
ContainerId = (int)row["FWUpdateSafeContainer_ID"],
|
||||
Name = (string)row["FWUpdateSafeContainer_Name"],
|
||||
UserId = (int)row["FWUpdateSafeContainer_UserId"],
|
||||
FilePartId = (int)row["FWUpdateSafeContainer_FileId"],
|
||||
ValidDate = (DateTime)row["FWUpdateSafeContainer_ValidDate"],
|
||||
Content = content
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
return Request.CreateResponse(HttpStatusCode.OK, ret);
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
[Route("PostFWUpdateSafe"), HttpPost]
|
||||
public async Task<HttpResponseMessage> PostFWUpdateSafe([FromBody] FwUpdateSafeDb fwc)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var parameters = new List<System.Data.SqlClient.SqlParameter>();
|
||||
var FileContent = new System.Data.SqlClient.SqlParameter("FileContent", SqlDbType.VarBinary);
|
||||
// var FileName = new System.Data.SqlClient.SqlParameter("FileName", SqlDbType.NVarChar, 50);
|
||||
var UserId = new System.Data.SqlClient.SqlParameter("UserId", SqlDbType.Int);
|
||||
var ValidDate = new System.Data.SqlClient.SqlParameter("ValidDate", SqlDbType.Date);
|
||||
|
||||
|
||||
// FileName.Value = fwc.Name;
|
||||
FileContent.Value = fwc.Content;
|
||||
UserId.Value = fwc.UserId;
|
||||
ValidDate.Value = fwc.ValidDate.Date;
|
||||
|
||||
//parameters.Add(FileName);
|
||||
parameters.Add(UserId);
|
||||
parameters.Add(FileContent);
|
||||
parameters.Add(ValidDate);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($" Declare @FileID as int ");
|
||||
|
||||
|
||||
sb.AppendLine($" INSERT INTO [dbo].[File] ([FileContent], [FileName]) VALUES (@FileContent, 't') ;");
|
||||
sb.AppendLine($" SELECT @FileID = @@IDENTITY; ");
|
||||
sb.AppendLine($" INSERT INTO [dbo].[FWUpdateSafeContainer] ([FWUpdateSafeContainer_Name],[FWUpdateSafeContainer_UserId],[FWUpdateSafeContainer_FileId],[FWUpdateSafeContainer_ValidDate])");
|
||||
sb.AppendLine($" VALUES('t',@UserId,@FileID,@ValidDate); ");
|
||||
sb.AppendLine($" select @@IDENTITY as ContainerID, @FileID as FilePartId ");
|
||||
|
||||
|
||||
|
||||
var retDT = dataacces.ExecuteQuery(sb.ToString(), parameters);
|
||||
var newID = Convert.ToInt32(retDT.Rows[0][0].ToString());
|
||||
return Request.CreateResponse(HttpStatusCode.OK, newID);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public virtual byte[] GetFileBytes(HttpPostedFile uploadedFile)
|
||||
{
|
||||
var bytes = new byte[uploadedFile.ContentLength];
|
||||
uploadedFile.InputStream.Read(bytes, 0, uploadedFile.ContentLength);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
[Route("PostFWUpdateReportFile"), HttpPost]
|
||||
public async Task<HttpResponseMessage> PostFWUpdateReportFiles([FromBody] FwUpdateReportDb FileContent)
|
||||
{
|
||||
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var parameters = new List<System.Data.SqlClient.SqlParameter>();
|
||||
var DbFileContent = new System.Data.SqlClient.SqlParameter("@FileContent", SqlDbType.VarBinary);
|
||||
var DbFileName = new System.Data.SqlClient.SqlParameter("@FileName", SqlDbType.NVarChar, 50);
|
||||
|
||||
|
||||
|
||||
DbFileName.Value = FileContent.FileName;
|
||||
DbFileContent.Value = UTF32Encoding.UTF32.GetBytes(JsonConvert.SerializeObject(FileContent));
|
||||
|
||||
|
||||
|
||||
parameters.Add(DbFileName);
|
||||
|
||||
parameters.Add(DbFileContent);
|
||||
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($" Declare @FileID as int ");
|
||||
|
||||
|
||||
sb.AppendLine($" INSERT INTO [dbo].[File] ([FileContent], [FileName]) VALUES (@FileContent, @FileName) ;");
|
||||
sb.AppendLine($" SELECT @FileID = @@IDENTITY; ");
|
||||
sb.AppendLine($" INSERT INTO [dbo].[FWUpdateReports] ([FWUpdateReport_Name],[FWUpdateReport_UserId], [FWUpdateReport_FileId],[FWUpdateReport_Date],[FWUpdateReport_PcbId], [FWUpdateReport_OrderNr], [FWUpdateReport_OrderPos]) ");
|
||||
sb.AppendLine($" VALUES(@FileName,{FileContent.UserId},@FileID,CURRENT_TIMESTAMP, {FileContent.PcbId}, {FileContent.OrderNr}, {FileContent.OrderPos} ); ");
|
||||
sb.AppendLine($" select @@IDENTITY as FWUpdateReportsId, @FileID as FilePartId ");
|
||||
|
||||
|
||||
|
||||
var retDT = dataacces.ExecuteQuery(sb.ToString(), parameters);
|
||||
var newID = Convert.ToInt32(retDT.Rows[0][0].ToString());
|
||||
return Request.CreateResponse(HttpStatusCode.OK, newID);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK, false);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[Route("GetFWUpdateReportFile"), HttpGet]
|
||||
public async Task<HttpResponseMessage> GetFWUpdateReportFile(int? PcbId = null, int? UserId = null, int? OrderNr = null, bool WithContent = true)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var ret = new System.Collections.Generic.List<FwUpdateReportDb>();
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
|
||||
sb.AppendLine($" select FWUpdateReport_ID, FWUpdateReport_Name, FWUpdateReport_UserId, FWUpdateReport_FileId, FWUpdateReport_Date, FWUpdateReport_PcbId, FWUpdateReport_OrderNr ");
|
||||
if (WithContent)
|
||||
{
|
||||
sb.Append(", FileContent ");
|
||||
}
|
||||
sb.AppendLine($" from [dbo].[FWUpdateReports] r ");
|
||||
if (WithContent)
|
||||
{
|
||||
sb.AppendLine($" inner join [dbo].[File] f on r.FWUpdateReport_FileId = f.FileId ");
|
||||
}
|
||||
sb.AppendLine($" where FWUpdateReport_ID > 0 ");
|
||||
|
||||
if (PcbId.HasValue)
|
||||
{
|
||||
sb.AppendLine($" and FWUpdateReport_PcbId = {PcbId.Value}");
|
||||
}
|
||||
if (UserId.HasValue)
|
||||
{
|
||||
sb.AppendLine($" and FWUpdateReport_UserId = {UserId.Value}");
|
||||
}
|
||||
if (OrderNr.HasValue)
|
||||
{
|
||||
sb.AppendLine($" and FWUpdateReport_OrderNr = {OrderNr.Value}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
|
||||
foreach (DataRow row in dbResult.Rows)
|
||||
{
|
||||
var addOBJ = JsonConvert.DeserializeObject<FwUpdateReportDb>(UTF32Encoding.UTF32.GetString((byte[])row["FileContent"]));
|
||||
addOBJ.FileId = (int)row["FWUpdateReport_ID"];
|
||||
addOBJ.Date = (DateTime)row["FWUpdateReport_Date"];
|
||||
ret.Add(addOBJ);
|
||||
}
|
||||
}
|
||||
return Request.CreateResponse(HttpStatusCode.OK, ret);
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
[Route("GetFakeRecoveryFile"), HttpGet]
|
||||
public async Task<HttpResponseMessage> GetFakeRecoveryFile(int PcbID, int? RadioFrq, string Region, string FlexnetVersion)
|
||||
{
|
||||
|
||||
var file = new RecoverySettings() { PcbID = PcbID, RadioFrequencyMhz = RadioFrq , Region = Region , Release = FlexnetVersion };
|
||||
|
||||
file.RecoveryRegisters = new List<ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem>();
|
||||
file.RecoveryRegisters.Add(new ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem() { RegisterIdent = "SENSUSRADIO_WakeupInterval", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x03 }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0x03 } });
|
||||
file.RecoveryRegisters.Add(new ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem() { RegisterIdent = "GENESISFLOW_SampleRate", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x02 }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0x02 } });
|
||||
file.RecoveryRegisters.Add(new ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem() { RegisterIdent = "GENESISFLOW_DisplayPow10", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0xFD }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0xFD } });
|
||||
|
||||
file.RecoveryRegisters.Add(new ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem() { RegisterIdent = "CUSTOMER_SerialNumber", WriteValue = new byte[] { 0x01, 0x02, 0x03, 0x04,0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00 }, IsCiritcal = false, ReadbackValue = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00 } });
|
||||
file.RecoveryRegisters.Add(new ServiceFwUpdate.Common.FwUpdateSafe.RecoveryRegisterItem() { RegisterIdent = "GENESISFLOW_StoreConfiguration", WriteValue = new byte[] { 0x00, 0x00, 0x00, 0x01 }, IsCiritcal = true, ReadbackValue = new byte[] { 0x00, 0x00, 0x00, 0x00 } });
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK, file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[Route("AddNewUser"), HttpGet]
|
||||
public async Task<HttpResponseMessage> AddNewUser(string FullName, string LogInName, string Domain, string HardwareId = null, string PasswordHash = null)
|
||||
{
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = new System.Collections.Generic.List<UserInformation>();
|
||||
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($" insert into FWUpdateUser ");
|
||||
sb.AppendLine($" select ");
|
||||
sb.AppendLine($" '{FullName}', ");
|
||||
sb.AppendLine($" '{LogInName}', ");
|
||||
sb.AppendLine($" '{Domain}', ");
|
||||
|
||||
sb.AppendLine(string.IsNullOrEmpty(HardwareId) ? "null , " : $"'{HardwareId}' ,");
|
||||
sb.AppendLine(string.IsNullOrEmpty(PasswordHash) ? "null , " : $"'{PasswordHash}' ,");
|
||||
|
||||
sb.AppendLine($" '{DateTimeOffset.UtcNow.ToString("yyyy-MM-dd HH:mm:ss +01:00")}', ");
|
||||
sb.AppendLine($" '{DateTimeOffset.UtcNow.ToString("yyyy-MM-dd HH:mm:ss +01:00")}', ");
|
||||
sb.AppendLine($" 0 ");
|
||||
|
||||
sb.AppendLine($" select @@IDENTITY ");
|
||||
|
||||
var dbResult = dataacces.ExecuteQuery(sb.ToString());
|
||||
|
||||
|
||||
|
||||
|
||||
var newID = Convert.ToInt32(dbResult.Rows[0][0].ToString());
|
||||
return Request.CreateResponse(HttpStatusCode.OK, newID);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -222,6 +222,7 @@
|
||||
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
|
||||
<Compile Include="Controllers\FinalCheckController.cs" />
|
||||
<Compile Include="Controllers\FileUpToDateController.cs" />
|
||||
<Compile Include="Controllers\LUTController.cs" />
|
||||
<Compile Include="Controllers\FwUpdateController.cs" />
|
||||
<Compile Include="Controllers\TestBenchController.cs" />
|
||||
<Compile Include="Controllers\MarriageController.cs" />
|
||||
|
||||
Reference in New Issue
Block a user