init
This commit is contained in:
949
DataPRO/DbAPI/Channels/Channels.cs
Normal file
949
DataPRO/DbAPI/Channels/Channels.cs
Normal file
@@ -0,0 +1,949 @@
|
||||
using DbAPI.Connections;
|
||||
using DbAPI.Errors;
|
||||
using DbAPI.Logging;
|
||||
using DTS.Common.Classes.Channels;
|
||||
using DTS.Common.Interface.Database;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using DTS.Common.Interface.Channels;
|
||||
using DTS.Common.Classes.Groups.ChannelSettings;
|
||||
using DTS.Common.Enums.Channels;
|
||||
using DTS.Common.Interface.Channels.ChannelCodes;
|
||||
using DTS.Common.Classes.ChannelCodes;
|
||||
using DTS.Common.Classes;
|
||||
using DTS.Common;
|
||||
using DTS.Common.Enums.DASFactory;
|
||||
|
||||
namespace DbAPI.Channels
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles channel functions
|
||||
/// </summary>
|
||||
internal class Channels : IChannels
|
||||
{
|
||||
/// <summary>
|
||||
/// insert a new channel code, channel code is modified with a new id if successful
|
||||
/// </summary>
|
||||
/// <param name="user">user submitting request</param>
|
||||
/// <param name="connection">connection being submitted on</param>
|
||||
/// <param name="channelCode">channel code to insert</param>
|
||||
/// <param name="lookup">mapping of code type to code type integer</param>
|
||||
/// <param name="id">new id of channel code record inserted</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
public ulong ChannelCodesInsert(IUserDbRecord user, IConnectionDetails connection,
|
||||
IReadOnlyDictionary<ChannelEnumsAndConstants.ChannelCodeType, short> lookup, IChannelCode channelCode,
|
||||
out int id)
|
||||
{
|
||||
id = -1;
|
||||
if (null == channelCode) { return ErrorCodes.ERROR_MISSING_PARAMETER; }
|
||||
if (string.IsNullOrEmpty(channelCode.Code) || string.IsNullOrEmpty(channelCode.Name))
|
||||
{
|
||||
return ErrorCodes.ERROR_MISSING_PARAMETER;
|
||||
}
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_ChannelCodesInsert");
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@Code", SqlDbType.NVarChar, 255) { Value = channelCode.Code });
|
||||
cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 255) { Value = channelCode.Name });
|
||||
cmd.Parameters.Add(new SqlParameter("@CodeType", SqlDbType.Int) { Value = lookup[channelCode.CodeType] });
|
||||
var errorNumber = new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumber);
|
||||
var errorMessage =
|
||||
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 255)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cmd.Parameters.Add(errorMessage);
|
||||
var newId = new SqlParameter("@new_id", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(newId);
|
||||
|
||||
_ = cmd.ExecuteNonQuery();
|
||||
if (!DBNull.Value.Equals(errorNumber.Value) && 0 != Convert.ToInt32(errorNumber.Value))
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups,
|
||||
$"ChannelCodesInsert - Error - {errorNumber.Value} - {errorMessage.Value}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
if (DBNull.Value.Equals(newId.Value))
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups,
|
||||
$"ChannelCodesInsert - Error, null new id");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
id = Convert.ToInt32(newId.Value);
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups,
|
||||
$"ChannelCodesInsert - Error - {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Update a channel record in the database
|
||||
/// </summary>
|
||||
/// <param name="user">user committing change</param>
|
||||
/// <param name="connection">connection change is committed on</param>
|
||||
/// <param name="channelCode">channel code being record being updated</param>
|
||||
/// <param name="lookup">mapping of code type to code type integer</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
public ulong ChannelCodesUpdate(IUserDbRecord user, IConnectionDetails connection,
|
||||
IReadOnlyDictionary<ChannelEnumsAndConstants.ChannelCodeType, short> lookup, IChannelCode channelCode)
|
||||
{
|
||||
if (null == channelCode) { return ErrorCodes.ERROR_MISSING_PARAMETER; }
|
||||
if (string.IsNullOrEmpty(channelCode.Code) || string.IsNullOrEmpty(channelCode.Name))
|
||||
{
|
||||
return ErrorCodes.ERROR_MISSING_PARAMETER;
|
||||
}
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_ChannelCodesUpdate");
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int) { Value = channelCode.Id });
|
||||
cmd.Parameters.Add(new SqlParameter("@Code", SqlDbType.NVarChar, 255) { Value = channelCode.Code });
|
||||
cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 255) { Value = channelCode.Name });
|
||||
cmd.Parameters.Add(new SqlParameter("@CodeType", SqlDbType.Int) { Value = lookup[channelCode.CodeType] });
|
||||
var errorNumber =
|
||||
new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumber);
|
||||
var errorMessage =
|
||||
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 255)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cmd.Parameters.Add(errorMessage);
|
||||
|
||||
_ = cmd.ExecuteNonQuery();
|
||||
if (!DBNull.Value.Equals(errorNumber.Value) && 0 != Convert.ToInt32(errorNumber.Value))
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups,
|
||||
$"ChannelCodesInsert - Error - {errorNumber.Value} - {errorMessage.Value}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups,
|
||||
$"ChannelCodesInsert - Error - {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// deletes matching channel codes
|
||||
/// </summary>
|
||||
/// <param name="user">user making deletes</param>
|
||||
/// <param name="connection">connection to delete on</param>
|
||||
/// <param name="id">id of channel code</param>
|
||||
/// <param name="code">code of matching channel codes (can be null)</param>
|
||||
/// <param name="name">name of matching channel codes (can be null)</param>
|
||||
/// <param name="codeType">code type of matching channel codes (can be null)</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
public ulong ChannelCodesDelete(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int? id,
|
||||
string code,
|
||||
string name,
|
||||
int? codeType)
|
||||
{
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_ChannelCodesDelete");
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
if (null != id)
|
||||
{
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int) { Value = (int)id });
|
||||
}
|
||||
else { cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int) { Value = null }); }
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@Code", SqlDbType.NVarChar, 255) { Value = code });
|
||||
cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 255) { Value = name });
|
||||
if (null == codeType)
|
||||
{
|
||||
cmd.Parameters.Add(new SqlParameter("@CodeType", SqlDbType.Int) { Value = null });
|
||||
}
|
||||
else { cmd.Parameters.Add(new SqlParameter("@CodeType", SqlDbType.Int) { Value = (int)codeType }); }
|
||||
|
||||
var errorNumber =
|
||||
new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumber);
|
||||
var errorMessage =
|
||||
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 255)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cmd.Parameters.Add(errorMessage);
|
||||
|
||||
_ = cmd.ExecuteNonQuery();
|
||||
if (!DBNull.Value.Equals(errorNumber.Value) && 0 != Convert.ToInt32(errorNumber.Value))
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups,
|
||||
$"ChannelCodesDelete - Error - {errorNumber.Value} - {errorMessage.Value}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups,
|
||||
$"ChannelCodesDelete error - {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// retrieves all matching channel code types (int identifier and string identifier)
|
||||
/// </summary>
|
||||
/// <param name="user">user making request</param>
|
||||
/// <param name="connection">connection request is being made on</param>
|
||||
/// <param name="codeType">code type (use null for all)</param>
|
||||
/// <param name="id">id (use null for all)</param>
|
||||
/// <param name="records">all matching records</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
public ulong ChannelCodeTypesGet(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
short? id,
|
||||
string codeType,
|
||||
out Tuple<short, string>[] records)
|
||||
{
|
||||
records = null;
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_ChannelCodeTypeGet");
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
if (null == id)
|
||||
{
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.TinyInt) { Value = null });
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.TinyInt) { Value = (short)id });
|
||||
}
|
||||
cmd.Parameters.Add(new SqlParameter("@CodeType", SqlDbType.NVarChar, 50) { Value = codeType });
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
var list = new List<Tuple<short, string>>();
|
||||
while (reader.Read())
|
||||
{
|
||||
var itemId = Utility.GetShort(reader, "Id");
|
||||
var cType = Utility.GetString(reader, "CodeType");
|
||||
list.Add(new Tuple<short, string>(itemId, cType));
|
||||
}
|
||||
records = list.ToArray();
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelCodeTypesGet failed: {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// retrieves all matching channel codes
|
||||
/// </summary>
|
||||
/// <param name="user">user making request</param>
|
||||
/// <param name="connection">connection query is being made on</param>
|
||||
/// <param name="Id">id of channel code (use null for all)</param>
|
||||
/// <param name="code">code of channel code (use null for all)</param>
|
||||
/// <param name="name">name of channel code (use null for all)</param>
|
||||
/// <param name="codeType">code type of channel code (use null for all)</param>
|
||||
/// <param name="channelTypeLookup">lookup of a short to a string for a channel code type</param>
|
||||
/// <param name="records">matching records</param>
|
||||
/// <returns>0 (ERROR SUCCESS) on success, all other values are error codes</returns>
|
||||
public ulong ChannelCodesGet(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int? Id,
|
||||
string code,
|
||||
string name,
|
||||
ChannelEnumsAndConstants.ChannelCodeType? codeType,
|
||||
IReadOnlyDictionary<short, string> channelTypeLookup,
|
||||
out IChannelCode[] records
|
||||
)
|
||||
{
|
||||
records = null;
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
if (null == channelTypeLookup)
|
||||
{
|
||||
return ErrorCodes.ERROR_MISSING_PARAMETER;
|
||||
}
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_ChannelCodesGet");
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
if (null == Id)
|
||||
{
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int) { Value = null });
|
||||
}
|
||||
else { cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int) { Value = (int)Id }); }
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@Code", SqlDbType.NVarChar, 255) { Value = code });
|
||||
cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 255) { Value = name });
|
||||
if (null == codeType)
|
||||
{
|
||||
cmd.Parameters.Add(new SqlParameter("@CodeType", SqlDbType.SmallInt) { Value = null });
|
||||
}
|
||||
else { cmd.Parameters.Add(new SqlParameter("@CodeType", SqlDbType.SmallInt) { Value = (short)codeType }); }
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
var list = new List<IChannelCode>();
|
||||
while (reader.Read())
|
||||
{
|
||||
list.Add(new ChannelCode(reader, channelTypeLookup));
|
||||
}
|
||||
records = list.ToArray();
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelCodesGet failed: {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// updates the default value for a channel setting
|
||||
/// </summary>
|
||||
/// <param name="user">user making update</param>
|
||||
/// <param name="connection">connection update is being made on</param>
|
||||
/// <param name="settingId">setting id to update</param>
|
||||
/// <param name="defaultValue">new value for setting</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
public ulong ChannelSettingsUpdate(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int settingId,
|
||||
string defaultValue)
|
||||
{
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_ChannelSettingsUpdate");
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int) { Value = settingId });
|
||||
cmd.Parameters.Add(new SqlParameter("@DefaultValue", SqlDbType.NVarChar, 255) { Value = defaultValue });
|
||||
|
||||
var errorNumber = new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumber);
|
||||
|
||||
var errorMessage = new SqlParameter("@errorMessage", SqlDbType.NVarChar, 255) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorMessage);
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
var o = errorNumber.Value;
|
||||
if (!DBNull.Value.Equals(o) && 0 != Convert.ToInt32(o))
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups,
|
||||
$"ChannelSettingsUpdate failed: {errorNumber.Value} - {errorMessage.Value}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelSettingsUpdate failed: {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// retrieves all channel settings from the db for a given channel
|
||||
/// </summary>
|
||||
/// <param name="user">user making request</param>
|
||||
/// <param name="connection">connection request is being made on</param>
|
||||
/// <param name="settingId">channel id to match (allows null)</param>
|
||||
/// <param name="settingName">setting name to match (allows null/empty)</param>
|
||||
/// <param name="records">matching records</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
public ulong ChannelSettingsGet(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int? settingId,
|
||||
string settingName,
|
||||
out IChannelSettingRecord[] records)
|
||||
{
|
||||
records = null;
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, Database.Database.GetStoredProcedureVersionCached(connection, "sp_ChannelSettingsGet"));
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
if (null == settingId)
|
||||
{
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int) { Value = null });
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int) { Value = (int)settingId });
|
||||
}
|
||||
cmd.Parameters.Add(new SqlParameter("@SettingName", SqlDbType.NVarChar, 255) { Value = settingName });
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
var list = new List<IChannelSettingRecord>();
|
||||
while (reader.Read())
|
||||
{
|
||||
list.Add(new ChannelSettingRecord(reader));
|
||||
}
|
||||
records = list.ToArray();
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelSettingsGet failed: {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// removes group channel settings from the db for a given channel
|
||||
/// </summary>
|
||||
/// <param name="user">user requesting changes</param>
|
||||
/// <param name="connection">connection changes are being made on</param>
|
||||
/// <param name="channelId">channel settings belong to</param>
|
||||
/// <param name="settingId">setting which to delete (use null to delete all settings)</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
public ulong GroupChannelSettingsDelete(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
long channelId,
|
||||
int? settingId)
|
||||
{
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_GroupChannelSettingsDelete");
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@ChannelId", SqlDbType.BigInt) { Value = channelId });
|
||||
if (null != settingId)
|
||||
{
|
||||
cmd.Parameters.Add(new SqlParameter("@SettingId", SqlDbType.Int) { Value = (int)settingId });
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.Parameters.Add(new SqlParameter("@SettingId", SqlDbType.Int) { Value = null });
|
||||
}
|
||||
|
||||
var errorNumber = new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumber);
|
||||
|
||||
var errorMessage = new SqlParameter("@errorMessage", SqlDbType.NVarChar, 250) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorMessage);
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
|
||||
var o = errorNumber.Value;
|
||||
if (!DBNull.Value.Equals(o) && 0 != Convert.ToInt32(errorNumber.Value))
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelSettingsDelete failed: {errorNumber.Value} : {errorMessage.Value}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelSettingsDelete failed: {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Inserts a new channel setting record into db
|
||||
/// </summary>
|
||||
/// <param name="user">user inserting record</param>
|
||||
/// <param name="connection">connection record is being inserted on</param>
|
||||
/// <param name="clientDbVersion">connection client db version</param>
|
||||
/// <param name="channelId">channel setting belongs to</param>
|
||||
/// <param name="record">record being inserted</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
public ulong GroupChannelSettingsInsert(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int clientDbVersion,
|
||||
long channelId,
|
||||
IGroupChannelSettingRecord record)
|
||||
{
|
||||
SqlCommand cmd;
|
||||
var storedProcedureVersionToUse = 0;
|
||||
var ret = Database.Database.PrepareForDbAccess(user, connection, clientDbVersion,
|
||||
"sp_GroupChannelSettingsInsert", out storedProcedureVersionToUse, out cmd);
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS) { return ret; }
|
||||
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.Parameters.Add(new SqlParameter("@ChannelId", SqlDbType.BigInt) { Value = channelId });
|
||||
cmd.Parameters.Add(new SqlParameter("@SettingId", SqlDbType.Int) { Value = record.SettingId });
|
||||
cmd.Parameters.Add(new SqlParameter("@SettingValue", SqlDbType.NVarChar, 255) { Value = record.SettingValue });
|
||||
|
||||
var errorNumber = new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumber);
|
||||
|
||||
var errorMessage = new SqlParameter("@errorMessage", SqlDbType.NVarChar, 255) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorMessage);
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
|
||||
var o = errorNumber.Value;
|
||||
if (!DBNull.Value.Equals(o) && 0 != Convert.ToInt32(errorNumber.Value))
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelSettingsInsert failed: {errorNumber.Value} : {errorMessage.Value}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelSettingsInsert failed: {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// returns all channel settings for a given channel
|
||||
/// </summary>
|
||||
/// <param name="user">user making request</param>
|
||||
/// <param name="clientDbVersion">calling client's database version</param>
|
||||
/// <param name="connection">connection request is being made on</param>
|
||||
/// <param name="channelIdList">list of channels for the request</param>
|
||||
/// <param name="records">all matching channel settings</param>
|
||||
/// <param name="errors">any errors encountered while retrieving group channel settings</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
public ulong GroupChannelSettingsGet(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int clientDbVersion,
|
||||
List<long> channelIdList,
|
||||
out IGroupChannelSettingRecord[] records,
|
||||
out string[] errors)
|
||||
{
|
||||
errors = new string[0];
|
||||
records = new IGroupChannelSettingRecord[0];
|
||||
var storedProcedureVersionToUse = 0;
|
||||
SqlCommand cmd;
|
||||
|
||||
var ret = Database.Database.PrepareForDbAccess(user, connection, clientDbVersion,
|
||||
"sp_GroupChannelSettingsGet", out storedProcedureVersionToUse, out cmd);
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS) { return ret; }
|
||||
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
try
|
||||
{
|
||||
var list = new List<IGroupChannelSettingRecord>();
|
||||
if (storedProcedureVersionToUse < Constants.BULK_GROUPCHANNELSETTINGS_GET_DB_VERSION)
|
||||
{
|
||||
//Call the old procedure that takes only one channel ID
|
||||
foreach (var channelId in channelIdList)
|
||||
{
|
||||
if (ErrorCodes.ERROR_SUCCESS != ret) { return ret; }
|
||||
//we can re-enter here, so clear the parameters just for simplicity
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Parameters.Add(new SqlParameter("@ChannelId", SqlDbType.Int) { Value = channelId });
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
list.Add(new GroupChannelSettingRecord(reader, storedProcedureVersionToUse) { ChannelId = channelId });
|
||||
}
|
||||
//http://manuscript.dts.local/f/cases/35503/Unable-to-add-a-test-setup-with-attached-database
|
||||
//close the reader
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Call the new procedure that takes a table of channel IDs
|
||||
using (var table = new DataTable())
|
||||
{
|
||||
table.Columns.Add("Item", typeof(string));
|
||||
|
||||
foreach (var channelId in channelIdList)
|
||||
{
|
||||
table.Rows.Add(channelId.ToString());
|
||||
}
|
||||
|
||||
var pList = new SqlParameter("@ChannelIdList", SqlDbType.Structured);
|
||||
pList.TypeName = "dbo.StringList";
|
||||
pList.Value = table;
|
||||
|
||||
cmd.Parameters.Add(pList);
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
list.Add(new GroupChannelSettingRecord(reader, storedProcedureVersionToUse));
|
||||
}
|
||||
}
|
||||
}
|
||||
records = list.ToArray();
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelSettingsGet failed: {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
public ulong ChannelsInsert(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
ref IChannelDbRecord channel)
|
||||
{
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_ChannelsInsert");
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.Parameters.Add(new SqlParameter("@GroupId", SqlDbType.Int) { Value = channel.GroupId });
|
||||
cmd.Parameters.Add(new SqlParameter("@IsoCode", SqlDbType.NVarChar, 50) { Value = channel.IsoCode ?? "" });
|
||||
cmd.Parameters.Add(new SqlParameter("@IsoChannelName", SqlDbType.NVarChar, 255) { Value = channel.IsoChannelName ?? "" });
|
||||
cmd.Parameters.Add(new SqlParameter("@UserCode", SqlDbType.NVarChar, 50) { Value = channel.UserCode ?? "" });
|
||||
cmd.Parameters.Add(new SqlParameter("@UserChannelName", SqlDbType.NVarChar, 255) { Value = channel.UserChannelName ?? "" });
|
||||
object dasId = null;
|
||||
if (channel.DASId > 0 && channel.DASChannelIndex >= 0)
|
||||
{
|
||||
dasId = channel.DASId;
|
||||
}
|
||||
cmd.Parameters.Add(new SqlParameter("@DASId", SqlDbType.Int) { Value = dasId });
|
||||
cmd.Parameters.Add(new SqlParameter("@DASChannelIndex", SqlDbType.Int) { Value = channel.DASChannelIndex });
|
||||
cmd.Parameters.Add(new SqlParameter("@GroupChannelOrder", SqlDbType.Int) { Value = channel.GroupChannelOrder });
|
||||
cmd.Parameters.Add(new SqlParameter("@TestSetupOrder", SqlDbType.Int) { Value = channel.TestSetupOrder });
|
||||
object sensorId = null;
|
||||
if (channel.SensorId > 0)
|
||||
{
|
||||
sensorId = channel.SensorId;
|
||||
}
|
||||
cmd.Parameters.Add(new SqlParameter("@SensorId", SqlDbType.Int) { Value = sensorId });
|
||||
cmd.Parameters.Add(new SqlParameter("@Disabled", SqlDbType.Bit) { Value = channel.Disabled });
|
||||
cmd.Parameters.Add(new SqlParameter("@LastModified", SqlDbType.DateTime) { Value = channel.LastModified });
|
||||
cmd.Parameters.Add(new SqlParameter("@LastModifiedBy", SqlDbType.NVarChar, 255) { Value = channel.LastModifiedBy });
|
||||
|
||||
var errorNumber = new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumber);
|
||||
|
||||
var errorMessage = new SqlParameter("@errorMessage", SqlDbType.NVarChar, 255) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorMessage);
|
||||
|
||||
var newId = new SqlParameter("@new_id", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(newId);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (!DBNull.Value.Equals(errorNumber.Value) && 0 != Convert.ToInt32(errorNumber.Value))
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error,
|
||||
LogManager.LogEvents.TestSetups, $"ChannelsInsert error - {errorNumber.Value} - {errorMessage.Value}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
channel.Id = Convert.ToInt64(newId.Value);
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelsInsert error: {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
cmd.Dispose();
|
||||
}
|
||||
}
|
||||
public ulong ChannelsUpdate(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
IChannelDbRecord channel)
|
||||
{
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_ChannelsUpdate");
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.BigInt) { Value = channel.Id });
|
||||
cmd.Parameters.Add(new SqlParameter("@GroupId", SqlDbType.Int) { Value = channel.GroupId });
|
||||
cmd.Parameters.Add(new SqlParameter("@IsoCode", SqlDbType.NVarChar, 50) { Value = channel.IsoCode });
|
||||
cmd.Parameters.Add(new SqlParameter("@IsoChannelName", SqlDbType.NVarChar, 255) { Value = channel.IsoChannelName });
|
||||
cmd.Parameters.Add(new SqlParameter("@UserCode", SqlDbType.NVarChar, 50) { Value = channel.UserCode });
|
||||
cmd.Parameters.Add(new SqlParameter("@UserChannelName", SqlDbType.NVarChar, 255) { Value = channel.UserChannelName });
|
||||
|
||||
object dasId = null;
|
||||
if (channel.DASId > 0)
|
||||
{
|
||||
dasId = channel.DASId;
|
||||
}
|
||||
cmd.Parameters.Add(new SqlParameter("@DASId", SqlDbType.Int) { Value = dasId });
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@DASChannelIndex", SqlDbType.Int) { Value = channel.DASChannelIndex });
|
||||
cmd.Parameters.Add(new SqlParameter("@GroupChannelOrder", SqlDbType.Int) { Value = channel.GroupChannelOrder });
|
||||
cmd.Parameters.Add(new SqlParameter("@TestSetupOrder", SqlDbType.Int) { Value = channel.TestSetupOrder });
|
||||
|
||||
object sensorId = null;
|
||||
if (channel.SensorId > 0)
|
||||
{
|
||||
sensorId = channel.SensorId;
|
||||
}
|
||||
cmd.Parameters.Add(new SqlParameter("@SensorId", SqlDbType.Int) { Value = sensorId });
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@Disabled", SqlDbType.Bit) { Value = channel.Disabled });
|
||||
cmd.Parameters.Add(new SqlParameter("@LastModified", SqlDbType.DateTime) { Value = channel.LastModified });
|
||||
cmd.Parameters.Add(new SqlParameter("@LastModifiedBy", SqlDbType.NVarChar, 255) { Value = channel.LastModifiedBy });
|
||||
|
||||
var errorNumber = new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumber);
|
||||
|
||||
var errorMessage = new SqlParameter("@errorMessage", SqlDbType.NVarChar, 255) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorMessage);
|
||||
|
||||
if (!DBNull.Value.Equals(errorNumber.Value) && 0 != Convert.ToInt32(errorNumber.Value))
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups,
|
||||
$"ChannelsUpdate {errorNumber.Value} - {errorMessage.Value}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.TestSetups, $"ChannelsUpdate {ex.Message}");
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
public ulong ChannelsGet(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int clientDbVersion,
|
||||
long? channelId,
|
||||
int? groupId,
|
||||
int? dasId,
|
||||
int? sensorId,
|
||||
int? testSetupId,
|
||||
string testSetupName,
|
||||
out IChannelDbRecord[] channels)
|
||||
{
|
||||
channels = null;
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
var storedProcedureVersionToUse = 0;
|
||||
SqlCommand cmd;
|
||||
|
||||
var ret = Database.Database.PrepareForDbAccess(user, connection, clientDbVersion, "sp_ChannelsGet", out storedProcedureVersionToUse, out cmd);
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS) { return ret; }
|
||||
|
||||
var list = new List<IChannelDbRecord>();
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int) { Value = channelId });
|
||||
cmd.Parameters.Add(new SqlParameter("@GroupId", SqlDbType.Int) { Value = groupId });
|
||||
cmd.Parameters.Add(new SqlParameter("@DASId", SqlDbType.Int) { Value = dasId });
|
||||
cmd.Parameters.Add(new SqlParameter("@SensorId", SqlDbType.Int) { Value = sensorId });
|
||||
cmd.Parameters.Add(new SqlParameter("@TestSetupId", SqlDbType.Int) { Value = testSetupId });
|
||||
cmd.Parameters.Add(new SqlParameter("@TestSetupName", SqlDbType.NVarChar, 255) { Value = testSetupName });
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
//33192 Hide the TSR AIR Humidity channel
|
||||
var newDbRecord = new ChannelDbRecord(reader);
|
||||
if (newDbRecord.UserChannelName.EndsWith(DFConstantsAndEnums.USER_CHANNEL_NAME_HUMIDITY)) { continue; }
|
||||
list.Add(newDbRecord);
|
||||
}
|
||||
channels = list.ToArray();
|
||||
return ErrorCodes.ERROR_SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Log(TraceEventType.Error, LogManager.LogEvents.DataRecorders, ex.Message);
|
||||
return ErrorCodes.ERROR_UNKNOWN;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
public ulong ChannelsDelete(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
long id,
|
||||
out string errorString)
|
||||
{
|
||||
errorString = string.Empty;
|
||||
if (!DbAPI.Connections.IsUserLoggedIn(user, connection))
|
||||
{
|
||||
return ErrorCodes.ERROR_ACCESS_DENIED;
|
||||
}
|
||||
var ret = ConnectionManager.GetSqlCommand(connection, out var cmd, "sp_ChannelsDelete");
|
||||
if (ret != ErrorCodes.ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
var errorNumberULong = ErrorCodes.ERROR_SUCCESS;
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.BigInt) { Value = id });
|
||||
cmd.Parameters.Add(new SqlParameter("@GroupId", SqlDbType.Int) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@DASId", SqlDbType.Int) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@SensorId", SqlDbType.Int) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@TestSetupId", SqlDbType.Int) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@TestSetupName", SqlDbType.NVarChar, 255) { Value = null });
|
||||
var errorNumber = new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumber);
|
||||
var errorMessage = new SqlParameter("@errorMessage", SqlDbType.NVarChar, 255) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorMessage);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (null != errorNumber.Value)
|
||||
{
|
||||
if (Convert.ToInt32(errorNumber.Value) != 0)
|
||||
{
|
||||
errorNumberULong = Convert.ToUInt64(errorNumber.Value);
|
||||
errorString = (string)errorMessage.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Concatenate any error string returned from the stored procedure call
|
||||
errorString = $"{ex.Message}; {errorString}";
|
||||
return errorNumberULong;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
|
||||
return errorNumberULong;
|
||||
}
|
||||
}
|
||||
}
|
||||
216
DataPRO/DbAPI/Channels/IChannels.cs
Normal file
216
DataPRO/DbAPI/Channels/IChannels.cs
Normal file
@@ -0,0 +1,216 @@
|
||||
using DbAPI.Connections;
|
||||
using DTS.Common.Interface.Database;
|
||||
using DTS.Common.Interface.Channels;
|
||||
using System;
|
||||
using DTS.Common.Enums.Channels;
|
||||
using DTS.Common.Interface.Channels.ChannelCodes;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DbAPI.Channels
|
||||
{
|
||||
/// <summary>
|
||||
/// Channel related functions (GetChannels, )
|
||||
/// </summary>
|
||||
public interface IChannels
|
||||
{
|
||||
/// <summary>
|
||||
/// insert a new channel code, channel code is modified with a new id if successful
|
||||
/// </summary>
|
||||
/// <param name="user">user submitting request</param>
|
||||
/// <param name="connection">connection being submitted on</param>
|
||||
/// <param name="channelCode">channel code to insert</param>
|
||||
/// <param name="lookup">mapping of code type string to code type integer</param>
|
||||
/// <param name="id">id of newly inserted database record</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelCodesInsert(IUserDbRecord user, IConnectionDetails connection,
|
||||
IReadOnlyDictionary<ChannelEnumsAndConstants.ChannelCodeType, short> lookup, IChannelCode channelCode,
|
||||
out int id);
|
||||
/// <summary>
|
||||
/// Update a channel record in the database
|
||||
/// </summary>
|
||||
/// <param name="user">user committing change</param>
|
||||
/// <param name="connection">connection change is committed on</param>
|
||||
/// <param name="channelCode">channel code being record being updated</param>
|
||||
/// <param name="lookup">mapping of code type string to code type integer</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelCodesUpdate(IUserDbRecord user, IConnectionDetails connection,
|
||||
IReadOnlyDictionary<ChannelEnumsAndConstants.ChannelCodeType, short> lookup, IChannelCode channelCode);
|
||||
/// <summary>
|
||||
/// deletes matching channel codes
|
||||
/// </summary>
|
||||
/// <param name="user">user making deletes</param>
|
||||
/// <param name="connection">connection to delete on</param>
|
||||
/// <param name="id">id of channel code</param>
|
||||
/// <param name="code">code of matching channel codes (can be null)</param>
|
||||
/// <param name="name">name of matching channel codes (can be null)</param>
|
||||
/// <param name="codeType">code type of matching channel codes (can be null)</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelCodesDelete(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int? id,
|
||||
string code,
|
||||
string name,
|
||||
int? codeType);
|
||||
|
||||
/// <summary>
|
||||
/// retrieves all matching channel code types (int identifier and string identifier)
|
||||
/// </summary>
|
||||
/// <param name="user">user making request</param>
|
||||
/// <param name="codeType">code type (use null for all)</param>
|
||||
/// <param name="id">id (use null for all)</param>
|
||||
/// <param name="connection">connection request is being made on</param>
|
||||
/// <param name="records">all matching records</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelCodeTypesGet(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
short? id,
|
||||
string codeType,
|
||||
out Tuple<short, string>[] records);
|
||||
/// <summary>
|
||||
/// retrieves all matching channel codes
|
||||
/// </summary>
|
||||
/// <param name="user">user making request</param>
|
||||
/// <param name="connection">connection query is being made on</param>
|
||||
/// <param name="Id">id of channel code (use null for all)</param>
|
||||
/// <param name="code">code of channel code (use null for all)</param>
|
||||
/// <param name="name">name of channel code (use null for all)</param>
|
||||
/// <param name="codeType">code type of channel code (use null for all)</param>
|
||||
/// <param name="channelTypeLookup">matches a channel code type to a short id for that type</param>
|
||||
/// <param name="records">matching records</param>
|
||||
/// <returns>0 (ERROR SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelCodesGet(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int? Id,
|
||||
string code,
|
||||
string name,
|
||||
ChannelEnumsAndConstants.ChannelCodeType? codeType,
|
||||
IReadOnlyDictionary<short, string> channelTypeLookup,
|
||||
out IChannelCode[] records
|
||||
);
|
||||
/// <summary>
|
||||
/// updates the default value for a channel setting
|
||||
/// </summary>
|
||||
/// <param name="user">user making update</param>
|
||||
/// <param name="connection">connection update is being made on</param>
|
||||
/// <param name="settingId">setting id to update</param>
|
||||
/// <param name="defaultValue">new value for setting</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelSettingsUpdate(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int settingId,
|
||||
string defaultValue);
|
||||
/// <summary>
|
||||
/// retrieves all channel settings from the db for a given channel
|
||||
/// </summary>
|
||||
/// <param name="user">user making request</param>
|
||||
/// <param name="connection">connection request is being made on</param>
|
||||
/// <param name="settingId">channel id to match (allows null)</param>
|
||||
/// <param name="settingName">setting name to match (allows null/empty)</param>
|
||||
/// <param name="records">matching records</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelSettingsGet(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int? settingId,
|
||||
string settingName,
|
||||
out IChannelSettingRecord[] records);
|
||||
/// <summary>
|
||||
/// removes group channel settings from the db for a given channel
|
||||
/// </summary>
|
||||
/// <param name="user">user requesting changes</param>
|
||||
/// <param name="connection">connection changes are being made on</param>
|
||||
/// <param name="channelId">channel settings belong to</param>
|
||||
/// <param name="settingId">setting which to delete (use null to delete all settings)</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong GroupChannelSettingsDelete(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
long channelId,
|
||||
int? settingId);
|
||||
/// <summary>
|
||||
/// Inserts a new channel setting record into db
|
||||
/// </summary>
|
||||
/// <param name="user">user inserting record</param>
|
||||
/// <param name="connection">connection record is being inserted on</param>
|
||||
/// <param name="channelId">channel setting belongs to</param>
|
||||
/// <param name="record">record being inserted</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong GroupChannelSettingsInsert(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int clientDbVersion,
|
||||
long channelId,
|
||||
IGroupChannelSettingRecord record);
|
||||
/// <summary>
|
||||
/// returns all channel settings for a given channel
|
||||
/// </summary>
|
||||
/// <param name="user">user making request</param>
|
||||
/// <param name="connection">connection request is being made on</param>
|
||||
/// <param name="clientDbVersion">calling client's database version</param>
|
||||
/// <param name="channelIdList">list of channels for the request</param>
|
||||
/// <param name="records">all matching channel settings</param>
|
||||
/// <param name="errors">any errors encountered while retrieving group channel settings</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong GroupChannelSettingsGet(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int clientDbVersion,
|
||||
List<long> channelIdList,
|
||||
out IGroupChannelSettingRecord[] records,
|
||||
out string[] errors);
|
||||
/// <summary>
|
||||
/// Inserts a new record in the Channels table
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="connection"></param>
|
||||
/// <param name="channel">The new values for the record in the Channels table</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelsInsert(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
ref IChannelDbRecord channel);
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing record in the Channels table
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="connection"></param>
|
||||
/// <param name="channel">The new values for the record in the Channels table</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelsUpdate(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
IChannelDbRecord channel);
|
||||
|
||||
/// <summary>
|
||||
/// retrieves all channels matching search criteria
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="connection"></param>
|
||||
/// <param name="channelId"></param>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="dasId"></param>
|
||||
/// <param name="sensorId"></param>
|
||||
/// <param name="testSetupId"></param>
|
||||
/// <param name="testSetupName"></param>
|
||||
/// <param name="channels">null, or calibrations found</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelsGet(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
int clientDbVersion,
|
||||
long? channelId,
|
||||
int? groupId,
|
||||
int? dasId,
|
||||
int? sensorId,
|
||||
int? testSetupId,
|
||||
string testSetupName,
|
||||
out IChannelDbRecord[] channels);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an entry in the Channels table
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="connection"></param>
|
||||
/// <param name="id">Id in the Channels table</param>
|
||||
/// <param name="errorString">Error string returned, possibly from sp_ChannelsDelete</param>
|
||||
/// <returns>0 (ERROR_SUCCESS) on success, all other values are error codes</returns>
|
||||
ulong ChannelsDelete(IUserDbRecord user,
|
||||
IConnectionDetails connection,
|
||||
long id,
|
||||
out string errorString);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user