100 lines
5.5 KiB
C#
100 lines
5.5 KiB
C#
using Microsoft.Win32;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Prevu
|
|
{
|
|
public class Result
|
|
{
|
|
public string Project { get; set; }
|
|
public string Browser { get; set; }
|
|
public string Name { get; set; }
|
|
public string Class { get; set; }
|
|
public string AssemblyLocation { get; set; }
|
|
public string MethodModule { get; set; }
|
|
public string UseCase { get; set; }
|
|
public string Scenario { get; set; }
|
|
public DateTime Created { get; set; }
|
|
public DateTime Started { get; set; }
|
|
public DateTime Finished { get; set; }
|
|
public string Duration { get; set; }
|
|
public string Domain { get; set; }
|
|
public string Outcome { get; set; }
|
|
public string FailureReason { get; set; }
|
|
public string ScreenShot { get; set; }
|
|
|
|
private static string NormName(string name)
|
|
{
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
return name.Replace("\\", "").Replace("/", "").Replace("(", "").Replace(")", "").Replace("#", "").Replace("@", "").Replace("*", "").Replace("!", "").Replace("$", "").Replace("%", "").Replace("^", "").Replace(":", "").Replace("?", "").Replace("+", "").Replace("=", "").Replace("|", "").Replace("{", "").Replace("}", "").Replace("[", "").Replace("]", "").Replace("'", "").Replace("\"", "").Replace(";", "").Replace("<", "").Replace(">", "").Replace(".", "").Replace(",", "").Replace("-", "").Replace(" ", "").Replace("_", "");
|
|
} else { return ""; }
|
|
}
|
|
|
|
private static DateTime ConvertToDateTime(Object obj)
|
|
{
|
|
DateTime date = DateTime.MinValue;
|
|
DateTime.TryParse(obj.ToString(), out date);
|
|
return date;
|
|
}
|
|
public static Result Load(string className, string browser, string name)
|
|
{
|
|
string project = className;
|
|
string[] set = className.Split('.');
|
|
if (set.Length > 1)
|
|
{
|
|
project = set[0];
|
|
}
|
|
|
|
string regKey = string.Format("Software\\TestSystem\\Test Results\\{0}\\{1}\\{2}", project, browser, NormName(name));
|
|
RegistryKey testKey = Registry.CurrentUser.OpenSubKey(regKey, false);
|
|
Result result = new Result();
|
|
result.Project = project;
|
|
result.Browser = browser;
|
|
result.Class = className;
|
|
if (testKey != null)
|
|
{
|
|
try { result.Name = testKey.GetValue("Name").ToString(); } catch { }
|
|
try { result.Class = testKey.GetValue("Class").ToString(); } catch { }
|
|
try { result.AssemblyLocation = testKey.GetValue("Assembly Location").ToString(); } catch { }
|
|
try { result.MethodModule = testKey.GetValue("Method Module").ToString(); } catch { }
|
|
try { result.UseCase = testKey.GetValue("Use Case").ToString(); } catch { }
|
|
try { result.Scenario = testKey.GetValue("Scenario").ToString(); } catch { }
|
|
try { result.Created = ConvertToDateTime(testKey.GetValue("Created")); } catch { }
|
|
try { result.Started = ConvertToDateTime(testKey.GetValue("Started")); } catch { }
|
|
try { result.Finished = ConvertToDateTime(testKey.GetValue("Finished")); } catch { }
|
|
try { result.Duration = testKey.GetValue("Duration").ToString(); } catch { }
|
|
try { result.Domain = testKey.GetValue("Domain").ToString(); } catch { }
|
|
try { result.Outcome = testKey.GetValue("Outcome").ToString(); } catch { }
|
|
try { result.FailureReason = testKey.GetValue("Failure Reason").ToString(); } catch { }
|
|
try { result.ScreenShot = testKey.GetValue("Screen Shot").ToString(); } catch { }
|
|
} else
|
|
{
|
|
result.Created = DateTime.Today;
|
|
}
|
|
return result;
|
|
}
|
|
public void Save()
|
|
{
|
|
string regKey = string.Format("HKEY_CURRENT_USER\\Software\\TestSystem\\Test Results\\{0}\\{1}\\{2}", Project, Browser, NormName(Name));
|
|
if (!string.IsNullOrEmpty(Name)) Registry.SetValue(regKey, "Name", Name);
|
|
if (!string.IsNullOrEmpty(Class)) Registry.SetValue(regKey, "Class", Class);
|
|
if (!string.IsNullOrEmpty(AssemblyLocation)) Registry.SetValue(regKey, "Assembly Location", AssemblyLocation);
|
|
if (!string.IsNullOrEmpty(MethodModule)) Registry.SetValue(regKey, "Method Module", MethodModule);
|
|
if (!string.IsNullOrEmpty(UseCase)) Registry.SetValue(regKey, "Use Case", UseCase);
|
|
if (!string.IsNullOrEmpty(Scenario)) Registry.SetValue(regKey, "Scenario", Scenario);
|
|
if (Created > DateTime.MinValue) Registry.SetValue(regKey, "Created", Created);
|
|
if (Started > DateTime.MinValue) Registry.SetValue(regKey, "Started", Started);
|
|
if (Finished > DateTime.MinValue) Registry.SetValue(regKey, "Finished", Finished);
|
|
if (!string.IsNullOrEmpty(Duration)) Registry.SetValue(regKey, "Duration", Duration);
|
|
if (!string.IsNullOrEmpty(Domain)) Registry.SetValue(regKey, "Domain", Domain);
|
|
if (!string.IsNullOrEmpty(Outcome)) Registry.SetValue(regKey, "Outcome", Outcome);
|
|
if (!string.IsNullOrEmpty(FailureReason)) Registry.SetValue(regKey, "Failure Reason", FailureReason);
|
|
if (!string.IsNullOrEmpty(ScreenShot)) Registry.SetValue(regKey, "Screen Shot", ScreenShot);
|
|
}
|
|
|
|
}
|
|
} |