예제 #1
0
        /// <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);
                }
            }
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <summary>
        /// Adds collector data entries to the <see cref="collectorDataEntries"/> collection
        /// </summary>
        /// <param name="collectorDataEntryList">The collector data entry to add</param>
        internal void AddCollectorDataEntries(IEnumerable <CollectorDataEntry> collectorDataEntryList)
        {
            Debug.Assert(collectorDataEntryList != null, "'collectorDataEntryList' is null");

            string testResultsDirectory = this.TestResultsDirectory;

            foreach (CollectorDataEntry collectorDataEntry in collectorDataEntryList)
            {
                Debug.Assert(collectorDataEntry != null, "'collectorDataEntry' is null");
                Debug.Assert(!this.collectorDataEntries.Contains(collectorDataEntry), "The collector data entry already exists in the collection");
#if DEBUG
                // Verify that any URI data attachments in the entry have relative paths
                foreach (IDataAttachment attachment in collectorDataEntry.Attachments)
                {
                    UriDataAttachment uriDataAttachment = attachment as UriDataAttachment;
                    if (uriDataAttachment != null)
                    {
                        Debug.Assert(uriDataAttachment.Uri.IsAbsoluteUri, "'collectorDataEntry' contains a URI data attachment with a relative URI");
                    }
                }
#endif

                this.collectorDataEntries.Add(collectorDataEntry.Clone(testResultsDirectory, false));
            }
        }
예제 #4
0
        // 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);
                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);
            }

            return(new CollectorDataEntry(
                       attachmentSet.Uri,
                       attachmentSet.DisplayName,
                       Environment.MachineName,
                       Environment.MachineName,
                       false,
                       uriDataAttachments));
        }