-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project.cs
232 lines (188 loc) · 8.12 KB
/
Project.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Xml;
using ProcessCapture.Screenshot;
using ProcessCapture.Log;
using System.IO;
using OpenSpanWPF;
using Ionic.Zip;
namespace ProcessCapture
{
public class Project : DependencyObject
{
private static DependencyProperty ProcessNameDO = DependencyProperty.Register("ProcessName", typeof(string), typeof(Project));
private static DependencyProperty ProcessDescDO = DependencyProperty.Register("Description", typeof(string), typeof(Project));
private static DependencyProperty ProcessAuthorDO = DependencyProperty.Register("Author", typeof(string), typeof(Project));
private static DependencyProperty ProcessImageDO = DependencyProperty.Register("ProcessImage", typeof(string), typeof(Project));
public string ProjectFileLocation;
public bool SaveRequired = false;
public void RequestSave()
{
SaveRequired = true;
}
public string ProcessName
{
get
{
return (string) GetValue(ProcessNameDO);
}
set
{
SetValue(ProcessNameDO, value);
}
}
public string Description
{
get
{
return (string)GetValue(ProcessDescDO);
}
set
{
SetValue(ProcessDescDO, value);
}
}
public string Author
{
get
{
return (string)GetValue(ProcessAuthorDO);
}
set
{
SetValue(ProcessAuthorDO, value);
}
}
public string ProcessImage
{
get
{
return (string)GetValue(ProcessImageDO);
}
set
{
SetValue(ProcessImageDO, value);
}
}
public string ToXML(List<ScreenImage> images)
{
StringBuilder sb = new StringBuilder();
sb.Append("<project>" + Environment.NewLine);
sb.Append("<name>");
sb.Append(ProcessName);
sb.Append("</name>" + Environment.NewLine);
sb.Append("<description>");
sb.Append(Description);
sb.Append("</description>" + Environment.NewLine);
sb.Append("<author>");
sb.Append(Author);
sb.Append("</author>" + Environment.NewLine);
sb.Append("<image>");
sb.Append(ProcessImage);
sb.Append("</image>" + Environment.NewLine);
sb.Append("<screenshots>" + Environment.NewLine);
foreach (ScreenImage si in images)
{
sb.Append("<screenshot>" + Environment.NewLine);
sb.Append("<location><![CDATA[");
sb.Append("images\\" + Path.GetFileName(si.Filename));
sb.Append("]]></location>" + Environment.NewLine);
sb.Append("<url><![CDATA[");
//sb.Append(Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(si.ApplicationURL)));
sb.Append(si.ApplicationURL);
sb.Append("]]></url>" + Environment.NewLine);
sb.Append("<title><![CDATA[");
sb.Append(si.Title);
sb.Append("]]></title>" + Environment.NewLine);
sb.Append("<path><![CDATA[");
sb.Append(si.Path);
sb.Append("]]></path>" + Environment.NewLine);
sb.Append("<notes><![CDATA[");
sb.Append(si.Notes);
sb.Append("]]></notes>" + Environment.NewLine);
sb.Append("<modules>" + Environment.NewLine);
foreach (string m in si.Modules)
{
sb.Append("<module><![CDATA[");
sb.Append(m);
sb.Append("]]></module>" + Environment.NewLine);
}
sb.Append("</modules>" + Environment.NewLine);
sb.Append("</screenshot>" + Environment.NewLine);
}
sb.Append("</screenshots>" + Environment.NewLine);
sb.Append("</project>");
return sb.ToString();
}
public static Project FromXML(string filename, string xml, out List<ScreenImage> images)
{
images = new List<ScreenImage>();
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
string baseDir = Path.GetDirectoryName(filename);
Project newProject = new Project();
newProject.ProcessName = xmlDoc.SelectSingleNode("/project/name/text()") != null ? xmlDoc.SelectSingleNode("/project/name/text()").InnerText : "";
newProject.Description = xmlDoc.SelectSingleNode("/project/description/text()") != null ? xmlDoc.SelectSingleNode("/project/description/text()").InnerText : "";
newProject.Author = xmlDoc.SelectSingleNode("/project/author/text()") != null ? xmlDoc.SelectSingleNode("/project/author/text()").InnerText : "";
newProject.ProcessImage = xmlDoc.SelectSingleNode("/project/image/text()") != null ? xmlDoc.SelectSingleNode("/project/image/text()").InnerText : "";
XmlNodeList screenshots = xmlDoc.SelectNodes("/project/screenshots/screenshot");
foreach (XmlNode screenshot in screenshots)
{
string path = screenshot.SelectSingleNode("location").InnerText;
if (!Path.IsPathRooted(path))
{
//relative path in XML
//append Images directory
path = baseDir + "\\" + path;
}
ScreenImage si = new ScreenImage(path);
si.ApplicationURL = screenshot.SelectSingleNode("url") != null ? screenshot.SelectSingleNode("url").InnerText : "";
si.Title = screenshot.SelectSingleNode("title") != null ? screenshot.SelectSingleNode("title").InnerText : "";
si.Path = screenshot.SelectSingleNode("path") != null ? screenshot.SelectSingleNode("path").InnerText : "";
si.Notes = screenshot.SelectSingleNode("notes") != null ? screenshot.SelectSingleNode("notes").InnerText : "";
XmlNodeList modules = screenshot.SelectNodes("modules/module");
List<string> moduleList = new List<string>();
foreach (XmlNode module in modules)
{
moduleList.Add(module.InnerText);
}
si.Modules = moduleList.ToArray();
images.Add(si);
}
return newProject;
}
catch (Exception e)
{
string file = Logger.GetInstance().Log(e);
MessageBox.Show("An error has occurred - it has been saved to " + file + " - please email this to [email protected]");
return null;
}
}
public static bool ExportToZip(Project proj, string zipfile)
{
try
{
using (ZipFile zip = new ZipFile(zipfile))
{
zip.AddFile(proj.ProjectFileLocation, "");
OpenSpanWPFWindow window = (OpenSpanWPFWindow)Application.Current.MainWindow;
foreach (ScreenImage si in window.screenCapture._screenImages)
{
zip.AddFile(si.Filename, "images");
}
zip.Save();
}
return true;
}
catch (Exception e)
{
return false;
}
}
}
}