/// <summary> /// Initializes a new instance of the <see cref="TestPlatformDataCollectionLogger"/> class. /// </summary> /// <param name="sink"> /// The underlying raw IMessageSink. Cannot be null. /// </param> /// <param name="dataCollectorConfig"> /// The data Collector Information. /// </param> internal TestPlatformDataCollectionLogger(IMessageSink sink, DataCollectorConfig dataCollectorConfig) { ValidateArg.NotNull(dataCollectorConfig, "dataCollectorInformation"); ValidateArg.NotNull(sink, "sink"); this.dataCollectorConfig = dataCollectorConfig; this.sink = sink; }
/// <summary> /// Loads and initializes data collector using data collector settings. /// </summary> /// <param name="dataCollectorSettings"> /// The data collector settings. /// </param> /// <param name="settingsXml"> runsettings Xml</param> private void LoadAndInitialize(DataCollectorSettings dataCollectorSettings, string settingsXml) { DataCollectorInformation dataCollectorInfo; DataCollectorConfig dataCollectorConfig; try { // Look up the extension and initialize it if one is found. var extensionManager = this.DataCollectorExtensionManager; var dataCollectorUri = string.Empty; this.TryGetUriFromFriendlyName(dataCollectorSettings.FriendlyName, out dataCollectorUri); DataCollector dataCollector = null; if (!string.IsNullOrWhiteSpace(dataCollectorUri)) { dataCollector = this.TryGetTestExtension(dataCollectorUri); } if (dataCollector == null) { this.LogWarning(string.Format(CultureInfo.CurrentUICulture, Resources.Resources.DataCollectorNotFound, dataCollectorSettings.FriendlyName)); return; } if (this.RunDataCollectors.ContainsKey(dataCollector.GetType())) { // Collector is already loaded (may be configured twice). Ignore duplicates and return. return; } dataCollectorConfig = new DataCollectorConfig(dataCollector.GetType()); // Attempt to get the data collector information verifying that all of the required metadata for the collector is available. dataCollectorInfo = new DataCollectorInformation( dataCollector, dataCollectorSettings.Configuration, dataCollectorConfig, this.dataCollectionEnvironmentContext, this.attachmentManager, this.events, this.messageSink, settingsXml); } catch (Exception ex) { if (EqtTrace.IsErrorEnabled) { EqtTrace.Error("DataCollectionManager.LoadAndInitialize: exception while creating data collector {0} : {1}", dataCollectorSettings.FriendlyName, ex); } // No data collector info, so send the error with no direct association to the collector. this.LogWarning(string.Format(CultureInfo.CurrentUICulture, Resources.Resources.DataCollectorInitializationError, dataCollectorSettings.FriendlyName, ex)); return; } try { dataCollectorInfo.InitializeDataCollector(); lock (this.RunDataCollectors) { // Add data collectors to run cache. this.RunDataCollectors[dataCollectorConfig.DataCollectorType] = dataCollectorInfo; } } catch (Exception ex) { if (EqtTrace.IsErrorEnabled) { EqtTrace.Error("DataCollectionManager.LoadAndInitialize: exception while initializing data collector {0} : {1}", dataCollectorSettings.FriendlyName, ex); } // Log error. dataCollectorInfo.Logger.LogError(this.dataCollectionEnvironmentContext.SessionDataCollectionContext, string.Format(CultureInfo.CurrentCulture, Resources.Resources.DataCollectorInitializationError, dataCollectorConfig.FriendlyName, ex.Message)); // Dispose datacollector. dataCollectorInfo.DisposeDataCollector(); } }
/// <summary> /// Loads and initializes datacollector using datacollector settings. /// </summary> /// <param name="dataCollectorSettings"> /// The data collector settings. /// </param> private void LoadAndInitialize(DataCollectorSettings dataCollectorSettings) { var collectorTypeName = dataCollectorSettings.AssemblyQualifiedName; DataCollectorInformation dataCollectorInfo; DataCollectorConfig dataCollectorConfig; try { var dataCollector = this.dataCollectorLoader.Load(dataCollectorSettings.CodeBase, dataCollectorSettings.AssemblyQualifiedName); if (dataCollector == null) { this.LogWarning(string.Format(CultureInfo.CurrentUICulture, Resources.Resources.DataCollectorNotFound, collectorTypeName, string.Empty)); return; } if (this.RunDataCollectors.ContainsKey(dataCollector.GetType())) { // Collector is already loaded (may be configured twice). Ignore duplicates and return. return; } dataCollectorConfig = new DataCollectorConfig(dataCollector.GetType()); // Attempt to get the data collector information verifying that all of the required metadata for the collector is available. dataCollectorInfo = new DataCollectorInformation( dataCollector, dataCollectorSettings.Configuration, dataCollectorConfig, this.dataCollectionEnvironmentContext, this.attachmentManager, this.events, this.messageSink); if (!dataCollectorInfo.DataCollectorConfig.TypeUri.Equals(dataCollectorSettings.Uri)) { // If the data collector was not found, send an error. this.LogWarning(string.Format(CultureInfo.CurrentCulture, Resources.Resources.DataCollectorNotFound, dataCollectorConfig.DataCollectorType.FullName, dataCollectorSettings.Uri)); return; } } catch (Exception ex) { if (EqtTrace.IsErrorEnabled) { EqtTrace.Error("DataCollectionManager.LoadAndInitialize: exception while creating data collector {0} : {1}", collectorTypeName, ex); } // No data collector info, so send the error with no direct association to the collector. this.LogWarning(string.Format(CultureInfo.CurrentUICulture, Resources.Resources.DataCollectorInitializationError, collectorTypeName, ex.Message)); return; } try { dataCollectorInfo.InitializeDataCollector(); lock (this.RunDataCollectors) { // Add data collectors to run cache. this.RunDataCollectors[dataCollectorConfig.DataCollectorType] = dataCollectorInfo; } } catch (Exception ex) { if (EqtTrace.IsErrorEnabled) { EqtTrace.Error("DataCollectionManager.LoadAndInitialize: exception while initializing data collector {0}: " + ex, collectorTypeName); } // Log error. dataCollectorInfo.Logger.LogError(this.dataCollectionEnvironmentContext.SessionDataCollectionContext, string.Format(CultureInfo.CurrentCulture, Resources.Resources.DataCollectorInitializationError, dataCollectorConfig.FriendlyName, ex.Message)); // Dispose datacollector. dataCollectorInfo.DisposeDataCollector(); } }
/// <summary> /// Initializes a new instance of the <see cref="DataCollectorInformation"/> class. /// </summary> /// <param name="dataCollector"> /// The data collector. /// </param> /// <param name="configurationElement"> /// The configuration element. /// </param> /// <param name="dataCollectorConfig"> /// The data collector config. /// </param> /// <param name="environmentContext"> /// The environment Context. /// </param> /// <param name="attachmentManager"> /// The attachment Manager. /// </param> /// <param name="events"> /// The events. /// </param> /// <param name="messageSink"> /// The message Sink. /// </param> /// <param name="settingsXml"></param> internal DataCollectorInformation(DataCollector dataCollector, XmlElement configurationElement, DataCollectorConfig dataCollectorConfig, DataCollectionEnvironmentContext environmentContext, IDataCollectionAttachmentManager attachmentManager, TestPlatformDataCollectionEvents events, IMessageSink messageSink, string settingsXml) { this.DataCollector = dataCollector; this.ConfigurationElement = configurationElement; this.DataCollectorConfig = dataCollectorConfig; this.Events = events; this.EnvironmentContext = environmentContext; this.DataCollectionSink = new TestPlatformDataCollectionSink(attachmentManager, dataCollectorConfig); this.Logger = new TestPlatformDataCollectionLogger(messageSink, dataCollectorConfig); this.SettingsXml = settingsXml; }
/// <summary> /// Initializes a new instance of the <see cref="TestPlatformDataCollectionSink"/> class. /// Creates a data collector sink for data transfer. /// </summary> /// <param name="attachmentManager"> /// The attachment Manager. /// </param> /// <param name="dataCollectorConfig"> /// Data collector info. /// </param> internal TestPlatformDataCollectionSink(IDataCollectionAttachmentManager attachmentManager, DataCollectorConfig dataCollectorConfig) { ValidateArg.NotNull(attachmentManager, nameof(attachmentManager)); ValidateArg.NotNull(dataCollectorConfig, nameof(dataCollectorConfig)); this.DataCollectorConfig = dataCollectorConfig; this.AttachmentManager = attachmentManager; }