/// <summary> /// Saves the state to the XML element /// </summary> /// <param name="element">The XML element to save to</param> /// <param name="parameters">Parameters to customize the save behavior</param> public void Save(XmlElement element, XmlTestStoreParameters parameters) { EqtAssert.ParameterNotNull(element, "element"); XmlPersistence helper = new XmlPersistence(); helper.SaveSimpleField(element, "@agentName", this.agentName, null); helper.SaveSimpleField(element, "@agentDisplayName", this.agentDisplayName, this.agentName); helper.SaveSimpleField(element, "@isFromRemoteAgent", this.isFromRemoteAgent, false); helper.SaveSimpleField(element, "@uri", this.uri.AbsoluteUri, null); helper.SaveSimpleField(element, "@collectorDisplayName", this.collectorDisplayName, string.Empty); IList <UriDataAttachment> uriAttachments = new List <UriDataAttachment>(); foreach (IDataAttachment attachment in this.Attachments) { UriDataAttachment uriAtt = attachment as UriDataAttachment; if (uriAtt != null) { uriAttachments.Add(uriAtt); } } helper.SaveIEnumerable(uriAttachments, element, "UriAttachments", "A", "UriAttachment", parameters); }
/// <summary> /// Copies the specified collector data entry, making the paths in the data attachments absolute or relative, with /// respect to the results directory /// </summary> /// <param name="other">The instance to copy from</param> /// <param name="resultsDirectory">The results directory to use to make paths in the data attachments relative or absolute</param> /// <param name="useAbsolutePaths">True to use absolute paths in this instance, false to use relative paths</param> private CollectorDataEntry(CollectorDataEntry other, string resultsDirectory, bool useAbsolutePaths) { Debug.Assert(other != null, "'other' is null"); Debug.Assert(other.attachments != null, "'other.m_attachments' is null"); Debug.Assert(!string.IsNullOrEmpty(resultsDirectory), "'resultsDirectory' is null or empty"); this.attachments = new List <IDataAttachment>(other.attachments.Count); this.Initialize(other.uri, other.collectorDisplayName, other.agentName, other.agentDisplayName, other.isFromRemoteAgent, null); // Clone the attachments foreach (IDataAttachment attachment in other.attachments) { Debug.Assert(attachment != null, "'attachment' is null"); UriDataAttachment uriDataAttachment = attachment as UriDataAttachment; if (uriDataAttachment != null) { this.attachments.Add(uriDataAttachment.Clone(resultsDirectory, useAbsolutePaths)); } else { this.attachments.Add(attachment); } } }
// Returns a list of collector entry private static CollectorDataEntry ToCollectorEntry(ObjectModel.AttachmentSet attachmentSet, Guid testResultExecutionId, TestRun testRun, string trxFileDirectory) { string runDirectoryName = Path.Combine(trxFileDirectory, testRun.RunConfiguration.RunDeploymentRootDirectory); string inDirectory = Path.Combine(runDirectoryName, "In"); string targetDirectory = inDirectory; if (!testResultExecutionId.Equals(Guid.Empty)) { targetDirectory = Path.Combine(inDirectory, testResultExecutionId.ToString()); } targetDirectory = Path.Combine(targetDirectory, Environment.MachineName); if (!Directory.Exists(targetDirectory)) { Directory.CreateDirectory(targetDirectory); } List <IDataAttachment> uriDataAttachments = new List <IDataAttachment>(); foreach (ObjectModel.UriDataAttachment uriDataAttachment in attachmentSet.Attachments) { if (ObjectModel.EqtTrace.IsVerboseEnabled) { ObjectModel.EqtTrace.Verbose("TrxLogger: ToCollectorEntry: Got attachment " + uriDataAttachment.Uri + " with description " + uriDataAttachment.Description); } string sourceFile = uriDataAttachment.Uri.LocalPath; Debug.Assert(Path.IsPathRooted(sourceFile), "Source file is not rooted"); // copy the source file to the target location string targetFileName = FileHelper.GetNextIterationFileName(targetDirectory, Path.GetFileName(sourceFile), false); try { CopyFile(sourceFile, targetFileName); // Add the target file name to the collector files list. // (Trx viewer automatically adds In\ to the collected file. string fileName = Path.Combine(Environment.MachineName, Path.GetFileName(targetFileName)); Uri sourceFileUri = new Uri(fileName, UriKind.Relative); TrxObjectModel.UriDataAttachment dataAttachment = new TrxObjectModel.UriDataAttachment(uriDataAttachment.Description, sourceFileUri); uriDataAttachments.Add(dataAttachment); } catch (Exception ex) { if (ObjectModel.EqtTrace.IsErrorEnabled) { ObjectModel.EqtTrace.Error("Trxlogger: ToCollectorEntry: " + ex); } } } return(new CollectorDataEntry( attachmentSet.Uri, attachmentSet.DisplayName, Environment.MachineName, Environment.MachineName, false, uriDataAttachments)); }