-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathExecutionHistory.cs
More file actions
91 lines (77 loc) · 2.42 KB
/
ExecutionHistory.cs
File metadata and controls
91 lines (77 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System.IO;
using System.Runtime.Serialization;
using TestStack.White.Configuration;
namespace TestStack.White.ScreenObjects.Services
{
[DataContract]
public class ExecutionHistory
{
[DataMember]
private object lastSnapshotId;
[DataMember]
private bool hasError;
private static readonly string ExecutionHistoryFile =
string.Format(@"{0}\{1}.xml", CoreConfigurationLocator.Get().WorkSessionLocation, "ExecutionHistory");
public ExecutionHistory()
{
ServiceCalls = new ServiceCalls();
}
public virtual void Add(ServiceCall serviceCall)
{
ServiceCalls.Add(serviceCall);
}
public virtual ServiceCalls FindCalls(ServiceCall match)
{
return ServiceCalls.Matching(match);
}
[DataMember]
public virtual object Data { get; set; }
public virtual object LastSnapshot
{
set { lastSnapshotId = value; }
get { return lastSnapshotId; }
}
public virtual bool HasError
{
get { return hasError; }
set { hasError = value; }
}
public static ExecutionHistory Create()
{
if (File.Exists(ExecutionHistoryFile))
{
using (var fs = CreateFileStream(ExecutionHistoryFile))
{
var dcs = new DataContractSerializer(typeof (ExecutionHistory));
return (ExecutionHistory)dcs.ReadObject(fs);
}
}
return new ExecutionHistory();
}
public virtual void SaveIfNoError()
{
if (!HasError)
{
lastSnapshotId = null;
Save();
}
}
public virtual ServiceCalls ServiceCalls { get; private set; }
public virtual void Save()
{
using (var fs = CreateFileStream(ExecutionHistoryFile))
{
var dcs = new DataContractSerializer(typeof(ExecutionHistory));
dcs.WriteObject(fs, this);
}
}
private static FileStream CreateFileStream(string fileLocation)
{
return new FileStream(fileLocation, FileMode.OpenOrCreate);
}
public virtual bool DropSnapshot()
{
return !(hasError || lastSnapshotId == null);
}
}
}