|
- <?xml version="1.0"?>
- <?component error="true" debug="false"?>
- <component>
- <registration
- description="WscMvc RequestContext"
- progid="WscMvc.RequestContext"
- version="1.00"
- classid="{1C36FA55-34DF-4974-94B9-D657389362B2}">
- </registration>
-
- <public>
- <method name="Initialize">
- <parameter name="path"/>
- <parameter name="httpMethod"/>
- <parameter name="logDir"/>
- </method>
- <method name="ElapsedMs"/>
- <method name="Path"/>
- <method name="HttpMethod"/>
- <method name="CorrelationId"/>
- <method name="LogDir"/>
- </public>
-
- <script language="VBScript">
- <![CDATA[
- Option Explicit
-
- ' Per-request, primitive-only data holder. Never references ASP intrinsics
- ' (Request/Response/Server/Session) - Default.asp resolves logDir via
- ' Server.MapPath before calling Initialize, and passes it in as a plain string.
- '
- ' NOTE: `Property Get/Let/Set` requires a `Class...End Class` block in
- ' VBScript - it cannot be used at the top level of a WSC <script> block
- ' (verified experimentally: registration fails with "Must be defined inside
- ' a Class", error 1048). Plain Function-style getters exposed as <method>
- ' are used instead, matching Application.wsc/HomeController.wsc.
-
- Dim m_path, m_httpMethod, m_logDir, m_correlationId, m_startTimer, m_initialized
-
- m_initialized = False
-
- Sub Initialize(path, httpMethod, logDir)
- m_path = path
- m_httpMethod = httpMethod
- m_logDir = logDir
- m_correlationId = NewCorrelationId()
- m_startTimer = Timer
- m_initialized = True
- End Sub
-
- Function NewCorrelationId()
- ' Timer/Randomize/Rnd() was tried first and FAILED experimentally: two
- ' Initialize calls within the same system-clock tick call `Randomize` with
- ' the same implicit time-based seed, so Rnd() returns the identical first
- ' value both times - two contexts created back-to-back got the exact same
- ' correlation id. FileSystemObject.GetTempName() is used instead: verified
- ' experimentally to return a distinct value on every call even in a tight
- ' loop (it does not depend on Randomize/Rnd state at all).
- Dim secs, fso, tempPart
- secs = Fix(Timer)
- Set fso = CreateObject("Scripting.FileSystemObject")
- tempPart = Replace(fso.GetTempName(), ".tmp", "")
- Set fso = Nothing
- NewCorrelationId = CStr(secs) & "-" & tempPart
- End Function
-
- Function ElapsedMs()
- If m_initialized Then
- ElapsedMs = CLng((Timer - m_startTimer) * 1000)
- Else
- ElapsedMs = -1
- End If
- End Function
-
- Function Path()
- Path = m_path
- End Function
-
- Function HttpMethod()
- HttpMethod = m_httpMethod
- End Function
-
- Function CorrelationId()
- CorrelationId = m_correlationId
- End Function
-
- Function LogDir()
- LogDir = m_logDir
- End Function
- ]]>
- </script>
- </component>
|