﻿Option Strict On
Option Explicit On

Imports System
Imports System.Diagnostics

Friend NotInheritable Class ShowcaseHostDiagnostics
    Private Shared ReadOnly _enabled As Boolean = String.Equals(Environment.GetEnvironmentVariable("MAS_SHOWCASE_HOST_DIAGNOSTICS"), "1", StringComparison.OrdinalIgnoreCase)

    Private Sub New()
    End Sub

    Friend Shared Sub RecordWindowOpened(title As String, isLauncher As Boolean, activeWindowCount As Integer)
        Write("window-open", title, isLauncher, activeWindowCount, 0, False)
    End Sub

    Friend Shared Sub RecordWindowClosed(title As String, isLauncher As Boolean, activeWindowCount As Integer)
        Write("window-close", title, isLauncher, activeWindowCount, 0, False)
    End Sub

    Friend Shared Sub RecordSampleOpenRequested(title As String, serial As Integer)
        Write("sample-open-request", title, False, 0, serial, False)
    End Sub

    Friend Shared Sub RecordActiveSampleChanged(title As String, serial As Integer, replacedPrevious As Boolean)
        Write("active-sample", title, False, 0, serial, replacedPrevious)
    End Sub

    Private Shared Sub Write(kind As String, title As String, isLauncher As Boolean, activeWindowCount As Integer, serial As Integer, replacedPrevious As Boolean)
        If Not _enabled Then Return
        Trace.WriteLine("NexamasUIShowcaseHost " & kind &
                        " title='" & If(title, String.Empty) & "'" &
                        " launcher=" & isLauncher.ToString() &
                        " activeWindows=" & activeWindowCount.ToString(Globalization.CultureInfo.InvariantCulture) &
                        " sampleSerial=" & serial.ToString(Globalization.CultureInfo.InvariantCulture) &
                        " replacedPrevious=" & replacedPrevious.ToString())
    End Sub
End Class
