Imports System.Diagnostics
Public Class SharePricesUtils
    Private Shared JavascriptEpochTimeBase As New Date(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)

    Public Shared Function ToEpochTime(DT As Date) As Long
        Return (DT - JavascriptEpochTimeBase).TotalMilliseconds
    End Function

    Public Shared Function FromEpochTime(DT As Long) As Date
        Return JavascriptEpochTimeBase.AddMilliseconds(DT)
    End Function

    Public Shared Sub SetResponseAndCompleteRequest(CurrentRequest As HttpContext, ContentType As String, ResponseText As String)
        'System.Diagnostics.Debug.Print("ReponseText: " + ResponseText)
        With CurrentRequest
            .Response.Clear()
            .Response.ContentType = ContentType
            .Response.Write(ResponseText)
            .Response.Flush()
            .Response.SuppressContent = True
            .ApplicationInstance.CompleteRequest()
        End With
    End Sub

    Public Shared Sub SetResponseAndCompleteRequest(CurrentRequest As HttpContext, ContentType As String, BinaryResponse() As Byte)
        Try
            With CurrentRequest
                .Response.Clear()
                .Response.ContentType = ContentType
                .Response.BinaryWrite(BinaryResponse)
                .Response.Flush()
                .Response.SuppressContent = True
                .ApplicationInstance.CompleteRequest()
            End With
        Catch ex As Exception
            Debug.Print("SetResponseAndCompleteRequest (binary) error: " + ex.ToString())
        End Try
    End Sub

End Class
