init
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace DTS.Common.Storage.TestSetups
|
||||
{
|
||||
/// <summary>
|
||||
/// this is a class representing test history
|
||||
/// 3003 Attach Test History to Sensors
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TestHistory
|
||||
{
|
||||
/// <summary>
|
||||
/// the primary key/id for the record in the test history table
|
||||
/// </summary>
|
||||
public long TestHistoryId { get; set; }
|
||||
/// <summary>
|
||||
/// the id for the test setup in the db
|
||||
/// </summary>
|
||||
public int TestSetupId { get; set; }
|
||||
/// <summary>
|
||||
/// the name of the test setup
|
||||
/// </summary>
|
||||
public string TestSetupName { get; set; }
|
||||
/// <summary>
|
||||
/// the description for the test setup
|
||||
/// </summary>
|
||||
public string TestSetupDescription { get; set; }
|
||||
/// <summary>
|
||||
/// the user provided test id for the test run
|
||||
/// </summary>
|
||||
public string TestId { get; set; }
|
||||
/// <summary>
|
||||
/// whether the test was marked as destructive or not
|
||||
/// </summary>
|
||||
public bool Destructive { get; set; }
|
||||
/// <summary>
|
||||
/// the time the unit was armed or auto-armed
|
||||
/// </summary>
|
||||
public DateTime ArmTime { get; set; }
|
||||
/// <summary>
|
||||
/// bytes array representing the test setup xml in gzip'd compressed form
|
||||
/// </summary>
|
||||
public byte[] TestSetup { get; set; }
|
||||
|
||||
public TestHistory()
|
||||
{
|
||||
}
|
||||
|
||||
public TestHistory(IDataReader reader)
|
||||
{
|
||||
var o = reader["TestHistoryId"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
TestHistoryId = Convert.ToInt64(o);
|
||||
}
|
||||
|
||||
o = reader["TestSetupId"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
TestSetupId = Convert.ToInt32(o);
|
||||
}
|
||||
|
||||
o = reader["TestSetupName"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
TestSetupName = Convert.ToString(o);
|
||||
}
|
||||
|
||||
o = reader["TestSetupDescription"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
TestSetupDescription = Convert.ToString(o);
|
||||
}
|
||||
|
||||
o = reader["TestId"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
TestId = Convert.ToString(o);
|
||||
}
|
||||
|
||||
o = reader["Destructive"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
Destructive = Convert.ToBoolean(o);
|
||||
}
|
||||
|
||||
o = reader["ArmTime"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
ArmTime = Convert.ToDateTime(o);
|
||||
}
|
||||
|
||||
o = reader["TestSetup"];
|
||||
if (!DBNull.Value.Equals(o))
|
||||
{
|
||||
TestSetup = (byte[])o;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// retrieves all test histories matching the test name
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public static TestHistory[] GetTestHistory(string name)
|
||||
{
|
||||
var list = new List<TestHistory>();
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = "sp_TestHistoryGet";
|
||||
cmd.Parameters.Add(new SqlParameter("@TestSetupName", SqlDbType.NVarChar)
|
||||
{ Value = name });
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
var history = new TestHistory(reader);
|
||||
list.Add(history);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
/// <summary>
|
||||
/// returns an xml document in string form representing all the input histories
|
||||
/// </summary>
|
||||
/// <param name="histories"></param>
|
||||
/// <returns></returns>
|
||||
public static string SerializeToString(TestHistory[] histories)
|
||||
{
|
||||
var serializer = new XmlSerializer(typeof(TestHistoryCollection));
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
serializer.Serialize(memoryStream, new TestHistoryCollection(histories));
|
||||
return Encoding.UTF8.GetString(memoryStream.ToArray());
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// this is just a helper class for serialization
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TestHistoryCollection
|
||||
{
|
||||
public TestHistory[] Histories { get; set; }
|
||||
|
||||
public TestHistoryCollection(TestHistory[] histories)
|
||||
{
|
||||
Histories = histories;
|
||||
}
|
||||
public TestHistoryCollection() { }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user