137
137
Trace.WriteLine(new LogMessage("FileAgent - Run", "Thread alive and Lock Obtained"), LogType.Info.ToString());
139
while (!file.Complete)
139
if (file.FileType == "resource")
141
byte[] getFileReturn;
141
// Download using GetResource
144
142
using (xmds.xmds xmds = new xmds.xmds())
146
144
xmds.Credentials = null;
147
145
xmds.Url = Settings.Default.XiboClient_xmds_xmds;
148
xmds.UseDefaultCredentials = false;
150
getFileReturn = xmds.GetFile(Settings.Default.ServerKey, _hardwareKey, file.Path, file.FileType, file.ChunkOffset, file.ChunkSize, Settings.Default.Version);
153
// Set the flag to indicate we have a connection to XMDS
154
Settings.Default.XmdsLastConnection = DateTime.Now;
156
if (file.FileType == "layout")
158
// Decode this byte[] into a string and stick it in the file.
159
string layoutXml = Encoding.UTF8.GetString(getFileReturn);
161
// Full file is downloaded
146
xmds.UseDefaultCredentials = true;
148
string result = xmds.GetResource(Settings.Default.ServerKey, Settings.Default.hardwareKey, file.LayoutId, file.RegionId, file.MediaId, Settings.Default.Version);
150
// Write the result to disk
162
151
using (StreamWriter sw = new StreamWriter(File.Open(Settings.Default.LibraryPath + @"\" + file.Path, FileMode.Create, FileAccess.Write, FileShare.Read)))
158
file.Downloading = false;
168
159
file.Complete = true;
164
while (!file.Complete)
166
byte[] getFileReturn;
169
using (xmds.xmds xmds = new xmds.xmds())
171
xmds.Credentials = null;
172
xmds.Url = Settings.Default.XiboClient_xmds_xmds;
173
xmds.UseDefaultCredentials = false;
175
getFileReturn = xmds.GetFile(Settings.Default.ServerKey, _hardwareKey, file.Path, file.FileType, file.ChunkOffset, file.ChunkSize, Settings.Default.Version);
178
// Set the flag to indicate we have a connection to XMDS
179
Settings.Default.XmdsLastConnection = DateTime.Now;
181
if (file.FileType == "layout")
183
// Decode this byte[] into a string and stick it in the file.
184
string layoutXml = Encoding.UTF8.GetString(getFileReturn);
186
// Full file is downloaded
187
using (StreamWriter sw = new StreamWriter(File.Open(Settings.Default.LibraryPath + @"\" + file.Path, FileMode.Create, FileAccess.Write, FileShare.Read)))
193
file.Complete = true;
198
// Need to write to the file - in append mode
199
using (FileStream fs = new FileStream(Settings.Default.LibraryPath + @"\" + file.Path, FileMode.Append, FileAccess.Write))
201
fs.Write(getFileReturn, 0, getFileReturn.Length);
205
// Increment the offset by the amount we just asked for
206
file.ChunkOffset = file.ChunkOffset + file.ChunkSize;
208
// Has the offset reached the total size?
209
if (file.Size > file.ChunkOffset)
211
int remaining = file.Size - file.ChunkOffset;
213
// There is still more to come
214
if (remaining < file.ChunkSize)
217
file.ChunkSize = remaining;
221
OnPartComplete(file.Id);
226
file.Complete = true;
230
getFileReturn = null;
234
file.Downloading = false;
237
string md5 = _requiredFiles.CurrentCacheManager.GetMD5(file.Path);
240
// Mark it as complete
241
_requiredFiles.MarkComplete(_requiredFileId, file.Md5);
243
// Add it to the cache manager
244
_requiredFiles.CurrentCacheManager.Add(file.Path, file.Md5);
246
Trace.WriteLine(new LogMessage("FileAgent - Run", "File Downloaded Successfully. " + file.Path), LogType.Info.ToString());
173
// Need to write to the file - in append mode
174
using (FileStream fs = new FileStream(Settings.Default.LibraryPath + @"\" + file.Path, FileMode.Append, FileAccess.Write))
176
fs.Write(getFileReturn, 0, getFileReturn.Length);
180
// Increment the offset by the amount we just asked for
181
file.ChunkOffset = file.ChunkOffset + file.ChunkSize;
183
// Has the offset reached the total size?
184
if (file.Size > file.ChunkOffset)
186
int remaining = file.Size - file.ChunkOffset;
188
// There is still more to come
189
if (remaining < file.ChunkSize)
192
file.ChunkSize = remaining;
196
OnPartComplete(file.Id);
201
file.Complete = true;
250
// Just error - we will pick it up again the next time we download
251
Trace.WriteLine(new LogMessage("FileAgent - Run", "Downloaded file failed MD5 check. Calculated [" + md5 + "] & XMDS [ " + file.Md5 + "] . " + file.Path), LogType.Error.ToString());
205
getFileReturn = null;
209
file.Downloading = false;
212
string md5 = _requiredFiles.CurrentCacheManager.GetMD5(file.Path);
215
// Mark it as complete
216
_requiredFiles.MarkComplete(_requiredFileId, file.Md5);
218
// Add it to the cache manager
219
_requiredFiles.CurrentCacheManager.Add(file.Path, file.Md5);
221
Trace.WriteLine(new LogMessage("FileAgent - Run", "File Downloaded Successfully. " + file.Path), LogType.Info.ToString());
225
// Just error - we will pick it up again the next time we download
226
Trace.WriteLine(new LogMessage("FileAgent - Run", "Downloaded file failed MD5 check. Calculated [" + md5 + "] & XMDS [ " + file.Md5 + "] . " + file.Path), LogType.Error.ToString());
229
255
// Inform the Player thread that a file has been modified.