forked from canneverbe/Ketarin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetupInstruction.cs
72 lines (62 loc) · 2.3 KB
/
SetupInstruction.cs
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
using System;
using System.Data;
using System.Data.SQLite;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace Ketarin
{
[Serializable(), XmlInclude(typeof(CustomSetupInstruction)), XmlInclude(typeof(StartProcessInstruction)), XmlInclude(typeof(CopyFileInstruction)), XmlInclude(typeof(CloseProcessInstruction))]
public class SetupInstruction : ICloneable
{
/// <summary>
/// Application this instruction belongs to.
/// </summary>
[XmlIgnore()]
public ApplicationJob Application { get; set; }
/// <summary>
/// Name of the instruction (type).
/// </summary>
public virtual string Name
{
get
{
return string.Empty;
}
}
/// <summary>
/// Executes the action.
/// </summary>
public virtual void Execute()
{
}
/// <summary>
/// Saves the setup instructions to the database.
/// </summary>
public void Save(IDbTransaction transaction, int position)
{
XmlSerializer serializer = new XmlSerializer(this.GetType());
XmlWriterSettings settings = new XmlWriterSettings {Indent = true};
StringBuilder output = new StringBuilder();
using (XmlWriter xmlWriter = XmlWriter.Create(output, settings))
{
serializer.Serialize(xmlWriter, this);
}
using (IDbCommand command = transaction.Connection.CreateCommand())
{
command.Transaction = transaction;
command.CommandText = "INSERT INTO setupinstructions (JobGuid, Position, Data) VALUES(@JobGuid, @Position, @Data)";
command.Parameters.Add(new SQLiteParameter("@JobGuid", DbManager.FormatGuid(this.Application.Guid)));
command.Parameters.Add(new SQLiteParameter("@Position", position));
command.Parameters.Add(new SQLiteParameter("@Data", output.ToString()));
command.ExecuteNonQuery();
}
}
#region ICloneable Member
public object Clone()
{
return this.MemberwiseClone();
}
#endregion
}
}