/// <summary> /// Set required files from the XML document /// </summary> private void SetRequiredFiles() { List<RequiredFileModel> newList = new List<RequiredFileModel>(); foreach (var file in _requiredFiles) { RequiredFileModel rf = new RequiredFileModel(); rf.FileType =file.FileType; rf.Complete = false; rf.MD5 = file.MD5; rf.LastChecked = DateTime.Now; rf.Size = file.Size; if (rf.FileType == "media") { string[] filePart = file.Path.Split('.'); rf.Id = file.Id;//int.Parse(filePart[0]); rf.Path =file.Path; } else if (rf.FileType == "layout") { rf.Id = int.Parse(file.Path); rf.Path = file.Path + ".mosaic";//attributes["path"].Value + ".mosaic"; } else { continue; } newList.Add(rf); } _requiredFiles = newList; }
/// <summary> /// Set required files from the XML document /// </summary> private void SetRequiredFiles() { List <RequiredFileModel> newList = new List <RequiredFileModel>(); foreach (var file in _requiredFiles) { RequiredFileModel rf = new RequiredFileModel(); rf.FileType = file.FileType; rf.Complete = false; rf.MD5 = file.MD5; rf.LastChecked = DateTime.Now; rf.Size = file.Size; if (rf.FileType == "media") { string[] filePart = file.Path.Split('.'); rf.Id = file.Id;//int.Parse(filePart[0]); rf.Path = file.Path; } else if (rf.FileType == "layout") { rf.Id = int.Parse(file.Path); rf.Path = file.Path + ".mosaic";//attributes["path"].Value + ".mosaic"; } else { continue; } newList.Add(rf); } _requiredFiles = newList; }
/// <summary> /// Mark a RequiredFileModel as incomplete /// </summary> /// <param name="id"></param> /// <param name="md5"></param> public void MarkIncomplete(int id, string md5) { foreach (RequiredFileModel rf in _requiredFiles) { if (rf.Id == id) { RequiredFileModel newRf = rf; newRf.Complete = false; newRf.MD5 = md5; _requiredFiles.Add(newRf); _requiredFiles.Remove(rf); return; } } }
/// <summary> /// Mark a RequiredFileModel as complete /// </summary> /// <param name="path"></param> /// <param name="md5"></param> public void MarkComplete(string path, string md5) { foreach (RequiredFileModel rf in _requiredFiles) { if (rf.Path == path) { RequiredFileModel newRf = rf; newRf.Complete = true; newRf.MD5 = md5; _requiredFiles.Add(newRf); _requiredFiles.Remove(rf); return; } } }
/// <summary> /// Compares the xml file list with the files currently in the library /// Downloads any missing files /// For file types of Layout will fire a LayoutChanged event, giving the filename of the layout changed /// </summary> public void CompareAndCollect() { var fileForComparison = new List<RequiredFileModel>((IEnumerable<RequiredFileModel>)_requiredFiles.Files); //Inspect each file we have here foreach (var file in fileForComparison) { RequiredFileModel fileList = new RequiredFileModel(); string path = file.Path; if (file.FileType == "layout") { // Layout // Does this file exist? if (File.Exists(Settings.Default.LibraryPath + @"\" + path)) { // Calculate a MD5 for the current file String md5 = _cacheManager.GetMD5(path); System.Diagnostics.Debug.WriteLine(String.Format("Comparing current MD5 [{0}] with given MD5 [{1}]", md5, file.MD5)); // Now we have the md5, compare it to the md5 in the xml if (file.MD5 != md5) { // They are different _cacheManager.Remove(path); //TODO: This might be bad! Delete the old layout as it is wrong try { File.Delete(Settings.Default.LibraryPath + @"\" + path); } catch (Exception ex) { Trace.WriteLine(new LogMessage("CompareAndCollect", "Unable to delete incorrect file because: " + ex.Message)); } // Get the file and save it fileList.ChunkOffset = 0; fileList.ChunkSize = 0; fileList.Complete = false; fileList.Downloading = false; fileList.Path = path; fileList.FileType = "layout"; fileList.MD5 = file.MD5; fileList.Retrys = 0; _files.Add(fileList); } else { // The MD5 of the current file and the MD5 in RequiredFiles are the same. // Therefore make sure this MD5 is in the CacheManager _cacheManager.Add(path, md5); _requiredFiles.MarkComplete(path, md5); } } else { // No - get the file and save it (no chunks) fileList.ChunkOffset = 0; fileList.ChunkSize = 0; fileList.Complete = false; fileList.Downloading = false; fileList.Path = path; fileList.FileType = "layout"; fileList.MD5 = file.MD5; fileList.Retrys = 0; _files.Add(fileList); } } else if (file.FileType == "media") { // Media // Does this media exist? if (File.Exists(Settings.Default.LibraryPath + @"\" + path)) { String md5 = _cacheManager.GetMD5(path); System.Diagnostics.Debug.WriteLine(String.Format("Comparing current MD5 [{0}] with given MD5 [{1}]", md5, file.MD5)); // MD5 the file to make sure it is the same. if (md5 != file.MD5) { // File changed _cacheManager.Remove(path); // Delete the old media as it is wrong try { File.Delete(Settings.Default.LibraryPath + @"\" + path); } catch (Exception ex) { Trace.WriteLine(new LogMessage("CompareAndCollect", "Unable to delete incorrect file because: " + ex.Message)); } // Add to queue fileList.ChunkOffset = 0; fileList.ChunkSize = DefaultChunkSize; fileList.Complete = false; fileList.Downloading = false; fileList.Path = path; fileList.FileType = "media"; fileList.Size = file.Size; fileList.MD5 = file.MD5; fileList.Retrys = 0; _files.Add(fileList); } else { // The MD5 of the current file and the MD5 in RequiredFiles are the same. // Therefore make sure this MD5 is in the CacheManager _cacheManager.Add(path, md5); //string[] filePart = path.Split('.'); _requiredFiles.MarkComplete(path, md5); } } else { // No - Get it (async call - with chunks... through another class?) fileList.ChunkOffset = 0; fileList.ChunkSize = DefaultChunkSize; fileList.Complete = false; fileList.Downloading = false; fileList.Path = path; fileList.FileType = "media"; fileList.Size = file.Size; fileList.MD5 = file.MD5; fileList.Retrys = 0; _files.Add(fileList); } } else if (file.FileType == "blacklist") { // Expect <file type="blacklist"><file id="" /></file> var items = (List<string>)file.Other; BlackList blackList = new BlackList(); try { blackList.Truncate(); } catch { } if (items.Count > 0) { blackList.Add(items); blackList.Dispose(); blackList = null; } items = null; } else { //Ignore node } } Debug.WriteLine(String.Format("There are {0} files to get", _files.Count.ToString())); // Output a list of the files we need to get string debugMessage = ""; foreach (RequiredFileModel fileToGet in _files) debugMessage += string.Format("File: {0}, Type: {1}, MD5: {2}. ", fileToGet.Path, fileToGet.FileType, fileToGet.MD5); Debug.WriteLine(debugMessage); // Report the files files back to XMDS _requiredFiles.ReportInventory(); // Write Required Files _requiredFiles.WriteRequiredFiles(); // Is there anything to get? if (_files.Count == 0) { CollectionComplete(); return; } // Start with the first file _currentFile = 0; // Preload the first filelist _currentFileList = _files[_currentFile]; // Get the first file GetFile(); }
/// <summary> /// Compares the xml file list with the files currently in the library /// Downloads any missing files /// For file types of Layout will fire a LayoutChanged event, giving the filename of the layout changed /// </summary> public void CompareAndCollect() { var fileForComparison = new List <RequiredFileModel>((IEnumerable <RequiredFileModel>)_requiredFiles.Files); //Inspect each file we have here foreach (var file in fileForComparison) { RequiredFileModel fileList = new RequiredFileModel(); string path = file.Path; if (file.FileType == "layout") { // Layout // Does this file exist? if (File.Exists(Settings.Default.LibraryPath + @"\" + path)) { // Calculate a MD5 for the current file String md5 = _cacheManager.GetMD5(path); System.Diagnostics.Debug.WriteLine(String.Format("Comparing current MD5 [{0}] with given MD5 [{1}]", md5, file.MD5)); // Now we have the md5, compare it to the md5 in the xml if (file.MD5 != md5) { // They are different _cacheManager.Remove(path); //TODO: This might be bad! Delete the old layout as it is wrong try { File.Delete(Settings.Default.LibraryPath + @"\" + path); } catch (Exception ex) { Trace.WriteLine(new LogMessage("CompareAndCollect", "Unable to delete incorrect file because: " + ex.Message)); } // Get the file and save it fileList.ChunkOffset = 0; fileList.ChunkSize = 0; fileList.Complete = false; fileList.Downloading = false; fileList.Path = path; fileList.FileType = "layout"; fileList.MD5 = file.MD5; fileList.Retrys = 0; _files.Add(fileList); } else { // The MD5 of the current file and the MD5 in RequiredFiles are the same. // Therefore make sure this MD5 is in the CacheManager _cacheManager.Add(path, md5); _requiredFiles.MarkComplete(path, md5); } } else { // No - get the file and save it (no chunks) fileList.ChunkOffset = 0; fileList.ChunkSize = 0; fileList.Complete = false; fileList.Downloading = false; fileList.Path = path; fileList.FileType = "layout"; fileList.MD5 = file.MD5; fileList.Retrys = 0; _files.Add(fileList); } } else if (file.FileType == "media") { // Media // Does this media exist? if (File.Exists(Settings.Default.LibraryPath + @"\" + path)) { String md5 = _cacheManager.GetMD5(path); System.Diagnostics.Debug.WriteLine(String.Format("Comparing current MD5 [{0}] with given MD5 [{1}]", md5, file.MD5)); // MD5 the file to make sure it is the same. if (md5 != file.MD5) { // File changed _cacheManager.Remove(path); // Delete the old media as it is wrong try { File.Delete(Settings.Default.LibraryPath + @"\" + path); } catch (Exception ex) { Trace.WriteLine(new LogMessage("CompareAndCollect", "Unable to delete incorrect file because: " + ex.Message)); } // Add to queue fileList.ChunkOffset = 0; fileList.ChunkSize = DefaultChunkSize; fileList.Complete = false; fileList.Downloading = false; fileList.Path = path; fileList.FileType = "media"; fileList.Size = file.Size; fileList.MD5 = file.MD5; fileList.Retrys = 0; _files.Add(fileList); } else { // The MD5 of the current file and the MD5 in RequiredFiles are the same. // Therefore make sure this MD5 is in the CacheManager _cacheManager.Add(path, md5); //string[] filePart = path.Split('.'); _requiredFiles.MarkComplete(path, md5); } } else { // No - Get it (async call - with chunks... through another class?) fileList.ChunkOffset = 0; fileList.ChunkSize = DefaultChunkSize; fileList.Complete = false; fileList.Downloading = false; fileList.Path = path; fileList.FileType = "media"; fileList.Size = file.Size; fileList.MD5 = file.MD5; fileList.Retrys = 0; _files.Add(fileList); } } else if (file.FileType == "blacklist") { // Expect <file type="blacklist"><file id="" /></file> var items = (List <string>)file.Other; BlackList blackList = new BlackList(); try { blackList.Truncate(); } catch { } if (items.Count > 0) { blackList.Add(items); blackList.Dispose(); blackList = null; } items = null; } else { //Ignore node } } Debug.WriteLine(String.Format("There are {0} files to get", _files.Count.ToString())); // Output a list of the files we need to get string debugMessage = ""; foreach (RequiredFileModel fileToGet in _files) { debugMessage += string.Format("File: {0}, Type: {1}, MD5: {2}. ", fileToGet.Path, fileToGet.FileType, fileToGet.MD5); } Debug.WriteLine(debugMessage); // Report the files files back to XMDS _requiredFiles.ReportInventory(); // Write Required Files _requiredFiles.WriteRequiredFiles(); // Is there anything to get? if (_files.Count == 0) { CollectionComplete(); return; } // Start with the first file _currentFile = 0; // Preload the first filelist _currentFileList = _files[_currentFile]; // Get the first file GetFile(); }