Exemple #1
0
        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="configurationElement">Configuration element</param>
        /// <param name="dataSink">Data sink</param>
        /// <param name="logger">Logger</param>
        public virtual void Initialize(
            XmlElement configurationElement,
            IDataCollectionSink dataSink,
            IDataCollectionLogger logger)
        {
            EqtTrace.Info("DynamicCoverageDataCollectorImpl.Initialize: Initialize configuration. ");
            if (string.IsNullOrEmpty(configurationElement?.InnerXml))
            {
                configurationElement = DynamicCoverageDataCollectorImpl.GetDefaultConfiguration();
            }

            this.logger   = logger;
            this.dataSink = dataSink;

            this.dataSink.SendFileCompleted += this.OnSendFileCompletedEvent;

            this.SessionName = Guid.NewGuid().ToString();

            this.sessionDirectory = Path.Combine(Path.GetTempPath(), this.SessionName);
            this.directoryHelper.CreateDirectory(this.sessionDirectory);

            this.SetCoverageFileName(configurationElement);

            this.PrepareVanguardProcess(configurationElement);
        }
        private void PrepareVanguardProcess(XmlElement configurationElement)
        {
            EqtTrace.Info("DynamicCoverageDataCollectorImpl.PrepareVanguardProcess: Preparing Vanguard process.");

            XmlElement config = configurationElement[ConfigCodeCoverageElementName]
                                ?? DynamicCoverageDataCollectorImpl.GetDefaultConfiguration()[ConfigCodeCoverageElementName];

            string configurationFileName = Path.Combine(this.sessionDirectory, VanguardConfigFileName);

            this.fileHelper.WriteAllText(configurationFileName, config.OuterXml);

            EqtTrace.Info("DynamicCoverageDataCollectorImpl.PrepareVanguardProcess: Initializing  with config: {0}.", config.OuterXml);
            this.Vanguard.Initialize(this.SessionName, configurationFileName, this.logger);
        }
        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="configurationElement">Configuration element</param>
        /// <param name="dataSink">Data sink</param>
        /// <param name="logger">Logger</param>
        public virtual void Initialize(
            XmlElement configurationElement,
            IDataCollectionSink dataSink,
            IDataCollectionLogger logger)
        {
            var defaultConfigurationElement = DynamicCoverageDataCollectorImpl.GetDefaultConfiguration();

            try
            {
                // WARNING: Do NOT remove this function call !!!
                //
                // Due to a dependency we took on Microsoft.TestPlatform.Utilities.dll, an
                // exception may be thrown if we cannot resolve CodeCoverageRunSettingsProcessor.
                // If such an exception is thrown we cannot catch it in this try-catch block
                // because all method dependencies must be resolved before the method call, thus
                // we introduced an additional layer of indirection.
                configurationElement = this.AddDefaultExclusions(configurationElement, defaultConfigurationElement);
            }
            catch (Exception ex)
            {
                EqtTrace.Warning(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        string.Join(
                            " ",
                            "DynamicCoverageDataCollectorImpl.Initialize: Exception encountered while processing the configuration element.",
                            "Keeping the configuration element unaltered. More info about the exception: {0}"),
                        ex.Message));
            }

            EqtTrace.Info("DynamicCoverageDataCollectorImpl.Initialize: Initialize configuration. ");
            if (string.IsNullOrEmpty(configurationElement?.InnerXml))
            {
                configurationElement = defaultConfigurationElement;
            }

            this.logger   = logger;
            this.dataSink = dataSink;

            this.dataSink.SendFileCompleted += this.OnSendFileCompletedEvent;

            this.SessionName = Guid.NewGuid().ToString();

            this.sessionDirectory = Path.Combine(Path.GetTempPath(), this.SessionName);
            this.directoryHelper.CreateDirectory(this.sessionDirectory);

            this.SetCoverageFileName(configurationElement);

            this.PrepareVanguardProcess(configurationElement);
        }
        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="configurationElement">Configuration element</param>
        /// <param name="dataSink">Data sink</param>
        /// <param name="logger">Logger</param>
        public virtual void Initialize(
            XmlElement configurationElement,
            IDataCollectionSink dataSink,
            IDataCollectionLogger logger)
        {
            var defaultConfigurationElement = DynamicCoverageDataCollectorImpl.GetDefaultConfiguration();

            try
            {
                var processor = new CodeCoverageRunSettingsProcessor(defaultConfigurationElement);
                configurationElement = (XmlElement)processor.Process(configurationElement);
            }
            catch (Exception ex)
            {
                EqtTrace.Warning(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        string.Join(
                            " ",
                            "DynamicCoverageDataCollectorImpl.Initialize: Exception encountered while processing the configuration element.",
                            "Keeping the configuration element unaltered. More info about the exception: {0}"),
                        ex.Message));
            }

            EqtTrace.Info("DynamicCoverageDataCollectorImpl.Initialize: Initialize configuration. ");
            if (string.IsNullOrEmpty(configurationElement?.InnerXml))
            {
                configurationElement = defaultConfigurationElement;
            }

            this.logger   = logger;
            this.dataSink = dataSink;

            this.dataSink.SendFileCompleted += this.OnSendFileCompletedEvent;

            this.SessionName = Guid.NewGuid().ToString();

            this.sessionDirectory = Path.Combine(Path.GetTempPath(), this.SessionName);
            this.directoryHelper.CreateDirectory(this.sessionDirectory);

            this.SetCoverageFileName(configurationElement);

            this.PrepareVanguardProcess(configurationElement);
        }
Exemple #5
0
        private void PrepareVanguardProcess(XmlElement configurationElement)
        {
            EqtTrace.Info("DynamicCoverageDataCollectorImpl.PrepareVanguardProcess: Preparing Vanguard process.");

            XmlElement config = configurationElement[ConfigCodeCoverageElementName]
                                ?? DynamicCoverageDataCollectorImpl.GetDefaultConfiguration()[ConfigCodeCoverageElementName];

            string configurationFileName = Path.Combine(this.sessionDirectory, VanguardConfigFileName);

            this.fileHelper.WriteAllText(configurationFileName, config.OuterXml);

            this.CodeCoverageDepsJsonFilePath = Path.Combine(this.sessionDirectory, CodeCoverageDepsJsonFileName);
            var codeCoverageDepsJsonContent = this.profilersLocationProvider.GetCodeCoverageShimPath()?.Replace(@"\", "/");

            this.fileHelper.WriteAllText(this.CodeCoverageDepsJsonFilePath, string.Format(CodeCoverageDepsJsonTemplate, codeCoverageDepsJsonContent));

            EqtTrace.Info("DynamicCoverageDataCollectorImpl.PrepareVanguardProcess: Initializing  with config: {0}.", config.OuterXml);
            this.Vanguard.Initialize(this.SessionName, configurationFileName, this.logger);
        }