// -----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------------
namespace Microsoft.DiagnosticsHub
{
using System;
public sealed class UserMarkRange : IDisposable
{
private readonly string rangeGuid;
private readonly int startId;
private readonly int endId;
private bool disposed = false;
///
/// Creates a range for usermarks
///
/// Optional name for range
/// Optional message to emit
public UserMarkRange(string name = "", string message = "")
{
this.startId = UserMarks.GetNewId();
this.endId = UserMarks.GetNewId();
this.rangeGuid = Guid.NewGuid().ToString();
// Correlate ids to range
UserMarkSource.Log.FireRangeEvent(this.rangeGuid, this.startId, this.endId);
// Add range name
UserMarkSource.Log.FireRangeIdToName(this.rangeGuid, name);
// Fire start event
UserMarkSource.Log.FireEmitEvent(this.startId, message);
}
///
/// Gets the range id
///
public string RangeId => this.rangeGuid;
///
/// Gets the start usermark id for the range
///
public int StartId => this.startId;
///
/// Gets the end usermark id for the range
///
public int EndId => this.endId;
///
/// Disposes the range.This also will automatically fire EndRange.
///
public void Dispose()
{
if (!this.disposed)
{
UserMarkSource.Log.FireEmitEvent(this.endId);
this.disposed = true;
}
}
}
}