private void readCab(XmlTextReader xmlReader, TestDatabaseProduct product, TestDatabaseFile file, TestDatabaseEvent theEvent) { AtomCab cab = new AtomCab(); cab.Cab = new StackHashCab(); while (xmlReader.Read()) { if ((xmlReader.NodeType == XmlNodeType.EndElement) && (xmlReader.Name.ToUpperInvariant() == "CAB")) { theEvent.Cabs.Add(cab); return; } if (xmlReader.NodeType == XmlNodeType.Element) { String elementName = xmlReader.Name.ToUpperInvariant(); xmlReader.Read(); String elementText = xmlReader.Value; switch (elementName) { case "DATECREATEDLOCAL": cab.Cab.DateCreatedLocal = DateTime.Parse(elementText); break; case "DATEMODIFIEDLOCAL": cab.Cab.DateModifiedLocal = DateTime.Parse(elementText); break; case "EVENTID": cab.Cab.EventId = Int32.Parse(elementText); break; case "EVENTTYPENAME": cab.Cab.EventTypeName = elementText; break; case "FILENAME": cab.Cab.FileName = elementText; break; case "ID": cab.Cab.Id = Int32.Parse(elementText); break; case "SIZEINBYTES": cab.Cab.SizeInBytes = Int64.Parse(elementText); break; } } } }
/// <summary> /// Download Cab to the specified filename. /// </summary> /// <param name="cab">Cab data to download.</param> /// <param name="overwrite">True - overwrite, false - don't overwrite.</param> /// <param name="folder">Full path of the cab.</param> /// <returns>Filename.</returns> public String DownloadCab(AtomCab cab, bool overwrite, String folder) { if (cab == null) { throw new ArgumentNullException("cab"); } if (folder == null) { throw new ArgumentNullException("folder"); } // No abort requested yet. m_AbortRequested = false; if (!Directory.Exists(folder)) { throw new ArgumentException("Directory must exist: " + folder, "folder"); } String fullFileName = Path.Combine(folder, cab.Cab.FileName); if (File.Exists(fullFileName) && !overwrite) { FileAttributes attributes = File.GetAttributes(fullFileName); File.SetAttributes(fullFileName, attributes & ~FileAttributes.ReadOnly); return(fullFileName); } try { if (m_AbortRequested) { throw new OperationCanceledException("Downloading cab aborted"); } String sourceCabFile = TestSettings.GetAttribute("TestCabFile"); File.Copy(sourceCabFile, fullFileName); FileAttributes attributes = File.GetAttributes(fullFileName); File.SetAttributes(fullFileName, attributes & ~FileAttributes.ReadOnly); return(fullFileName); } catch (System.Exception ex) { throw new StackHashException(ex.Message, ex, StackHashServiceErrorCode.CabDownloadFailed); } }