init
This commit is contained in:
1
DataPRO/DTS.Core.DbAPIWrapper/.svn/entries
Normal file
1
DataPRO/DTS.Core.DbAPIWrapper/.svn/entries
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
1
DataPRO/DTS.Core.DbAPIWrapper/.svn/format
Normal file
1
DataPRO/DTS.Core.DbAPIWrapper/.svn/format
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DbAPI\DbAPI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,147 @@
|
||||
using DbAPI.Connections;
|
||||
using DTS.Common.Interface.Database;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using DTS.Common.Interface.TestSetups.TestSetupsList;
|
||||
|
||||
namespace DTS.Core.DbAPIWrapper
|
||||
{
|
||||
public class DbApiWrapper
|
||||
{
|
||||
private readonly ConnectionDetails _connectionDetail;
|
||||
private ApiInfo? _apiInfo;
|
||||
public DbApiWrapper(string dbServer, string dbName, string dbUsername,
|
||||
string dbPassword, bool adAuthentication, bool useCentralizedDb, int? clientDbVersion=null)
|
||||
{
|
||||
|
||||
_connectionDetail = new ConnectionDetails
|
||||
{
|
||||
DbName = dbName,
|
||||
DbServer = dbServer,
|
||||
DbUser = dbUsername,
|
||||
DbUserPassword = dbPassword,
|
||||
UseNTLMAuthentication = adAuthentication,
|
||||
UsingCentralizedDb = useCentralizedDb,
|
||||
ClientDbVersion = clientDbVersion.HasValue ? clientDbVersion.Value : 0
|
||||
};
|
||||
}
|
||||
|
||||
private void Connect()
|
||||
{
|
||||
var res = DbAPI.DbAPI.Connections.ConnectToDb(_connectionDetail);
|
||||
if (res != 0)
|
||||
{
|
||||
throw new Exception("Failed to connect to database");
|
||||
}
|
||||
}
|
||||
|
||||
public void AuthenticateUser(string username, string password)
|
||||
{
|
||||
Connect();
|
||||
var hr = DbAPI.DbAPI.Connections.LoginUser(_connectionDetail, username, password, out var userRecord);
|
||||
if (hr == 0)
|
||||
_ = userRecord;
|
||||
else
|
||||
throw new UnauthorizedAccessException("Failed to Authenticate the user");
|
||||
|
||||
var loggedInUsers = DbAPI.DbAPI.Connections.GetLoggedInUsers();
|
||||
|
||||
if (loggedInUsers != null && loggedInUsers.Any())
|
||||
{
|
||||
ApiInfo apiInfo = new ApiInfo { ConnectionDetails = loggedInUsers[0].Item2, UserDbRecord = loggedInUsers[0].Item1 };
|
||||
_apiInfo = apiInfo;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new UnauthorizedAccessException("Failed to Authenticate the user");
|
||||
}
|
||||
|
||||
public Tuple<ITestSetupRecord[], string[], ulong> TestSetupsGet(int? testSetupId = null, string? testSetupName = null, double defaultROIStart = double.NaN, double defaultROIEnd =double.NaN, bool defaultIgnoreShortedStart = false, bool defaultIgnoreShortedTrigger = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetTestSetups(testSetupId, testSetupName, defaultROIStart, defaultROIEnd, defaultIgnoreShortedStart, defaultIgnoreShortedTrigger);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"TestSetupsGet failed. {ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="testSetupId"></param>
|
||||
/// <returns>Returns Tuple<ITestSetupRecord[], string[]> with arrays of ITestSetupRecord as Item1 and array of errors as Item2 and error code as Item3</returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public async Task<Tuple<ITestSetupRecord[], string[], ulong>> TestSetupsGetAsync(int? testSetupId = null, string? testSetupName = null, double defaultROIStart = double.NaN, double defaultROIEnd = double.NaN, bool defaultIgnoreShortedStart = false, bool defaultIgnoreShortedTrigger = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var taskResult = await Task.Run(() =>
|
||||
{
|
||||
return GetTestSetups(testSetupId, testSetupName, defaultROIStart, defaultROIEnd, defaultIgnoreShortedStart, defaultIgnoreShortedTrigger);
|
||||
});
|
||||
|
||||
return taskResult;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"TestSetupsGet failed. {ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="testSetupId">Optional testSetupId</param>
|
||||
/// <returns>Returns Tuple<ITestSetupRecord[], string[]> with arrays of ITestSetupRecord as Item1 and array of errors as Item2 and error code as Item3</returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
private Tuple<ITestSetupRecord[], string[], ulong> GetTestSetups(int? testSetupId, string? testSetupName, double defaultROIStart, double defaultROIEnd, bool defaultIgnoreShortedStart, bool defaultIgnoreShortedTrigger)
|
||||
{
|
||||
if (_apiInfo?.UserDbRecord is null || _apiInfo.ConnectionDetails is null)
|
||||
{
|
||||
throw new Exception($"Authentication is required");
|
||||
}
|
||||
var errorCode = DbAPI.DbAPI.TestSetups.TestSetupsGet(_apiInfo.UserDbRecord, _apiInfo.ConnectionDetails, _apiInfo.ConnectionDetails.ClientDbVersion,
|
||||
testSetupId, testSetupName, defaultROIStart, defaultROIEnd, defaultIgnoreShortedStart, defaultIgnoreShortedTrigger, out var records, out var errorsFromDbApi);
|
||||
return Tuple.Create(records, errorsFromDbApi, errorCode);
|
||||
}
|
||||
|
||||
public Tuple<IDASDBRecord[],ulong> DASGet(string? dasSerial = null, string? position = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetDAS(dasSerial, position);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"DASGet failed. {ex.Message}");
|
||||
}
|
||||
}
|
||||
public async Task<Tuple<IDASDBRecord[], ulong>> DASGetAsync(string? dasSerial = null, string? position = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var taskResult = await Task.Run(() =>
|
||||
{
|
||||
return GetDAS(dasSerial, position);
|
||||
});
|
||||
|
||||
return taskResult;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"DASGet failed. {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private Tuple<IDASDBRecord[], ulong> GetDAS(string? dasSerial, string? position)
|
||||
{
|
||||
if (_apiInfo?.UserDbRecord is null || _apiInfo.ConnectionDetails is null)
|
||||
{
|
||||
throw new Exception($"Authentication is required");
|
||||
}
|
||||
var error = DbAPI.DbAPI.DAS.DASGet(_apiInfo.UserDbRecord, _apiInfo.ConnectionDetails, _apiInfo.ConnectionDetails.ClientDbVersion, dasSerial, position, out var records);
|
||||
return Tuple.Create(records, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using DbAPI.Connections;
|
||||
using DTS.Common.Interface.Database;
|
||||
|
||||
namespace DTS.Core.DbAPIWrapper
|
||||
{
|
||||
public class ApiInfo
|
||||
{
|
||||
public IUserDbRecord? UserDbRecord { get; set; }
|
||||
public IConnectionDetails? ConnectionDetails { get; set; }
|
||||
}
|
||||
}
|
||||
BIN
DataPRO/DTS.Core.DbAPIWrapper/.svn/wc.db
Normal file
BIN
DataPRO/DTS.Core.DbAPIWrapper/.svn/wc.db
Normal file
Binary file not shown.
0
DataPRO/DTS.Core.DbAPIWrapper/.svn/wc.db-journal
Normal file
0
DataPRO/DTS.Core.DbAPIWrapper/.svn/wc.db-journal
Normal file
Reference in New Issue
Block a user