示例#1
0
 internal static void RequireNotEmpty(this TelemetryEventCorrelation correlation, string argumentName)
 {
     if (correlation.IsEmpty)
     {
         throw new ArgumentException("Value shouldn't be empty.", argumentName);
     }
 }
示例#2
0
        /// <summary>
        /// Register correlation from a given asset id with specified asset type.
        /// </summary>
        /// <param name="assetTypeName">Asset type name. It is defined by asset provider.</param>
        /// <param name="assetId">
        /// Used to identify the asset. The id should be immutable in the asset life cycle, even if the status or content changes over time.
        /// E.g., project guid is generated during project creation and will never change. This makes it a good candidate for asset id of Project asset.
        /// </param>
        /// <param name="correlation">correlation of the asset.</param>
        /// <remarks>
        /// Used by Asset Provider.
        /// </remarks>
        public void RegisterCorrelation(string assetTypeName, string assetId, TelemetryEventCorrelation correlation)
        {
            CodeContract.RequiresArgumentNotNullAndNotWhiteSpace(assetTypeName, "assetTypeName");
            CodeContract.RequiresArgumentNotNullAndNotWhiteSpace(assetId, "assetId");
            CacheKey key = new CacheKey(assetTypeName, assetId);

            registeredCorrelations[key] = correlation;
        }
示例#3
0
 /// <summary>
 /// Creates the new telemetry event instance with specific information.
 /// </summary>
 /// <param name="eventName">Event name that is unique, not null and not empty.</param>
 /// <param name="severity">Severity level of the event.</param>
 /// <param name="correlation">Correlation value for this event.</param>
 internal TelemetryEvent(string eventName, TelemetrySeverity severity, TelemetryEventCorrelation correlation)
 {
     CodeContract.RequiresArgumentNotNullAndNotWhiteSpace(eventName, "eventName");
     correlation.RequireNotEmpty("correlation");
     TelemetryService.EnsureEtwProviderInitialized();
     this.eventName     = eventName.ToLower(CultureInfo.InvariantCulture);
     Severity           = severity;
     Correlation        = correlation;
     EventSchemaVersion = 5;
     InitDataModelBasicProperties();
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Coding4Fun.VisualStudio.Telemetry.AssetEvent" /> class.
 /// </summary>
 /// <param name="eventName">
 /// An event name following data model schema.
 /// It requires that event name is a unique, not null or empty string.
 /// It consists of 3 parts and must follows pattern [product]/[featureName]/[entityName]. FeatureName could be a one-level feature or feature hierarchy delimited by "/".
 /// For examples,
 /// vs/platform/opensolution;
 /// vs/platform/editor/lightbulb/fixerror;
 /// </param>
 /// <param name="assetId">
 /// Used to identify the asset. The id should be immutable in the asset life cycle, even if the status or content changes over time.
 /// E.g., project guid is generated during project creation and will never change. This makes it a good candidate for asset id of Project asset.
 /// </param>
 /// <param name="assetEventVersion">
 /// Used for customized properties versioning.
 /// E.g., project asset posts event with name "vs/platform/project".
 /// If the event is updated, uses this parameter to increment the version.
 /// </param>
 /// <param name="correlation">
 /// Correlation value for this event.
 /// </param>
 public AssetEvent(string eventName, string assetId, int assetEventVersion, TelemetryEventCorrelation correlation)
     : base(eventName, TelemetrySeverity.Normal, correlation)
 {
     if (correlation.EventType != DataModelEventType.Asset)
     {
         throw new ArgumentException("Property EventType should be AssetEvent.", "correlation");
     }
     DataModelEventNameHelper.SetProductFeatureEntityName(this);
     AssetId = assetId;
     base.ReservedProperties["DataModel.Asset.AssetId"] = assetId;
     AssetEventVersion = assetEventVersion;
     base.ReservedProperties["DataModel.Asset.SchemaVersion"] = assetEventVersion;
 }
示例#5
0
 /// <summary>
 /// Correlate this event with other event via <see cref="T:Coding4Fun.VisualStudio.Telemetry.TelemetryEventCorrelation" /> with description information.
 /// </summary>
 /// <param name="correlation">The property <see cref="P:Coding4Fun.VisualStudio.Telemetry.TelemetryEvent.Correlation" /> of correlated event.</param>
 /// <param name="description">
 /// A description string for this correlation information, such as name, hint, tag, category.
 /// Please don't include comma which is a reserved char.
 /// It could be null or empty string.
 /// </param>
 /// <remarks>
 /// This method is not thread-safe.
 /// </remarks>
 protected void CorrelateWithDescription(TelemetryEventCorrelation correlation, string description)
 {
     if (description != null && description.Contains(','))
     {
         throw new ArgumentException("Comma is not allowed.", "description");
     }
     if (!correlation.IsEmpty && !Correlation.Equals(correlation))
     {
         if (CorrelatedWith == null)
         {
             CorrelatedWith = new Dictionary <TelemetryEventCorrelation, string>();
         }
         CorrelatedWith[correlation] = description;
     }
 }
示例#6
0
        /// <summary>
        /// Get correlation for a given asset type and asset id.
        /// </summary>
        /// <param name="assetTypeName">Asset type name. It is defined by asset provider.</param>
        /// <param name="assetId">
        /// Used to identify the asset. The id should be immutable in the asset life cycle, even if the status or content changes over time.
        /// E.g., project guid is generated during project creation and will never change. This makes it a good candidate for asset id of Project asset.
        /// You can get more information from asset provider.
        /// </param>
        /// <returns>Asset correlation</returns>
        public TelemetryEventCorrelation GetCorrelation(string assetTypeName, string assetId)
        {
            CodeContract.RequiresArgumentNotNullAndNotWhiteSpace(assetTypeName, "assetTypeName");
            CodeContract.RequiresArgumentNotNullAndNotWhiteSpace(assetId, "assetId");
            IAssetProvider            provider    = null;
            CacheKey                  key         = new CacheKey(assetTypeName, assetId);
            TelemetryEventCorrelation correlation = TelemetryEventCorrelation.Empty;

            lock (locker)
            {
                if (!registeredCorrelations.TryGetValue(key, out correlation))
                {
                    correlation = TelemetryEventCorrelation.Empty;
                    if (registeredProviders.TryGetValue(assetTypeName, out provider))
                    {
                        correlation = new TelemetryEventCorrelation(Guid.NewGuid(), DataModelEventType.Asset);
                        RegisterCorrelation(assetTypeName, assetId, correlation);
                    }
                }
            }
            if (provider != null)
            {
                ThreadScheduler.Schedule(delegate
                {
                    bool flag = false;
                    try
                    {
                        flag = provider.PostAsset(assetId, correlation);
                    }
                    finally
                    {
                        if (!flag)
                        {
                            UnregisterCorrelation(assetTypeName, assetId);
                        }
                    }
                });
            }
            return(correlation);
        }
示例#7
0
 /// <summary>
 /// Correlate this event with other event via <see cref="T:Coding4Fun.VisualStudio.Telemetry.TelemetryEventCorrelation" /> with description information.
 /// </summary>
 /// <param name="correlation">The property <see cref="P:Coding4Fun.VisualStudio.Telemetry.TelemetryEvent.Correlation" /> of correlated event.</param>
 /// <param name="description">
 /// A description string for this correlation information, such as name, hint, tag, category.
 /// Please don't include comma which is a reserved char.
 /// </param>
 /// <remarks>
 /// This method is not thread-safe.
 /// </remarks>
 public void Correlate(TelemetryEventCorrelation correlation, string description)
 {
     CodeContract.RequiresArgumentNotNullAndNotWhiteSpace(description, "description");
     CorrelateWithDescription(correlation, description);
 }
示例#8
0
 /// <summary>
 /// Register correlation from a given asset id with specified asset type.
 /// </summary>
 /// <param name="assetTypeName">Asset type name. It is defined by asset provider.</param>
 /// <param name="assetId">
 /// Used to identify the asset. The id should be immutable in the asset life cycle, even if the status or content changes over time.
 /// E.g., project guid is generated during project creation and will never change. This makes it a good candidate for asset id of Project asset.
 /// </param>
 /// <param name="correlation">correlation of the asset.</param>
 /// <remarks>
 /// Used by Asset Provider.
 /// </remarks>
 public void RegisterCorrelation(string assetTypeName, Guid assetId, TelemetryEventCorrelation correlation)
 {
     CodeContract.RequiresArgumentNotNullAndNotWhiteSpace(assetTypeName, assetTypeName);
     CodeContract.RequiresArgumentNotEmpty(assetId, "assetId");
     RegisterCorrelation(assetTypeName, assetId.ToString("D"), correlation);
 }