2
* Xibo - Digitial Signage - http://www.xibo.org.uk
3
* Copyright (C) 2011 Daniel Garner
5
* This file is part of Xibo.
7
* Xibo is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU Affero General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
12
* Xibo is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU Affero General Public License for more details.
17
* You should have received a copy of the GNU Affero General Public License
18
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
21
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
25
using System.Security.Cryptography;
27
using System.Diagnostics;
28
using System.Windows.Forms;
29
using System.Xml.Serialization;
33
public class RequiredFiles
35
private XmlDocument _requiredFilesXml;
36
public Collection<RequiredFile> _requiredFiles;
37
private xmds.xmds _report;
39
public RequiredFiles()
41
_requiredFiles = new Collection<RequiredFile>();
43
// Create a webservice call
44
_report = new XiboClient.xmds.xmds();
46
// Start up the Xmds Service Object
47
_report.Credentials = null;
48
_report.Url = Properties.Settings.Default.XiboClient_xmds_xmds;
49
_report.UseDefaultCredentials = false;
53
/// Set required files from the XML document
55
private void SetRequiredFiles()
57
// Itterate through the RF XML and populate the RF collection
58
XmlNodeList fileNodes = _requiredFilesXml.SelectNodes("/files/file");
60
foreach (XmlNode file in fileNodes)
62
RequiredFile rf = new RequiredFile();
64
XmlAttributeCollection attributes = file.Attributes;
66
rf.FileType = attributes["type"].Value;
69
rf.LastChecked = DateTime.Now;
71
if (rf.FileType == "media")
73
string[] filePart = attributes["path"].Value.Split('.');
74
rf.Id = int.Parse(filePart[0]);
75
rf.Path = attributes["path"].Value;
77
else if (rf.FileType == "layout")
79
rf.Id = int.Parse(attributes["path"].Value);
80
rf.Path = attributes["path"].Value + ".xlf";
87
_requiredFiles.Add(rf);
92
/// Required Files XML
94
public XmlDocument RequiredFilesXml
98
_requiredFilesXml = value;
104
/// Mark a RequiredFile as complete
106
/// <param name="id"></param>
107
/// <param name="md5"></param>
108
public void MarkComplete(int id, string md5)
110
foreach (RequiredFile rf in _requiredFiles)
114
RequiredFile newRf = rf;
120
_requiredFiles.Add(newRf);
121
_requiredFiles.Remove(rf);
129
/// Mark a RequiredFile as incomplete
131
/// <param name="id"></param>
132
/// <param name="md5"></param>
133
public void MarkIncomplete(int id, string md5)
135
foreach (RequiredFile rf in _requiredFiles)
139
RequiredFile newRf = rf;
144
_requiredFiles.Add(newRf);
145
_requiredFiles.Remove(rf);
153
/// Writes Required Files to disk
155
public void WriteRequiredFiles()
157
Debug.WriteLine(new LogMessage("RequiredFiles - WriteRequiredFiles", "About to Write RequiredFiles"), LogType.Info.ToString());
161
using (StreamWriter streamWriter = new StreamWriter(Application.UserAppDataPath + "\\" + Properties.Settings.Default.RequiredFilesFile))
163
XmlSerializer xmlSerializer = new XmlSerializer(typeof(RequiredFiles));
165
xmlSerializer.Serialize(streamWriter, this);
170
System.Diagnostics.Trace.WriteLine(new LogMessage("RequiredFiles - WriteRequiredFiles", "Unable to write RequiredFiles to disk because: " + ex.Message));
175
/// Report Required Files to XMDS
177
public void ReportInventory()
179
HardwareKey hardwareKey = new HardwareKey();
181
// Build the XML required by media file
184
foreach (RequiredFile rf in _requiredFiles)
186
xml += string.Format("<file type=\"{0}\" id=\"{1}\" complete=\"{2}\" lastChecked=\"{3}\" md5=\"{4}\" />",
187
rf.FileType, rf.Id.ToString(), rf.Complete.ToString(), rf.LastChecked.ToString(), rf.Md5);
190
xml = string.Format("<files>{0}</files>", xml);
192
_report.MediaInventoryAsync(Properties.Settings.Default.Version, Properties.Settings.Default.ServerKey,
193
hardwareKey.Key, xml);
197
public struct RequiredFile
199
public string FileType;
202
public DateTime LastChecked;