Class WorkContext
Represents a context for request/response server processing in WAVE framework
Inheritance
System.Object
WorkContext
Implements
System.IDisposable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Assembly: Azos.Wave.dll
Syntax
[SlimSerializationProhibited]
public class WorkContext : DisposableObject, IDisposable
Properties
Aborted
Indicates whether the work context is logically finished and its nested processing (i.e. through Filters/Handlers) should stop.
For example, when some filter detects a special condition (judging by the request) and generates the response
and needs to abort the work request so it does no get filtered/processed anymore, it can set this property to true.
This mechanism performs much better than throwing exceptions
Declaration
public bool Aborted { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
About
Generates short context description
Declaration
public string About { get; }
Property Value
Type |
Description |
System.String |
|
App
Returns the application that this context is under
Declaration
public IApplication App { get; }
Property Value
Current
Returns the current call context/thread/async flow instance
Declaration
public static WorkContext Current { get; }
Property Value
EffectiveCallerIPEndPoint
Returns the effective caller endpoint- that is, if the real caller filter is set it will inject the real IP
as seen before any proxy devices. By default this property returns the Request.RemoteEndPoint
Declaration
public IPEndPoint EffectiveCallerIPEndPoint { get; }
Property Value
Type |
Description |
System.Net.IPEndPoint |
|
GeoEntity
Gets sets geo location information as detected by GeoLookupHandler.
If Session context is injected then get/set passes through into session object
Declaration
public GeoEntity GeoEntity { get; set; }
Property Value
Handled
Returns true when the work has been executed by the WorkHandler instance
Declaration
public bool Handled { get; }
Property Value
Type |
Description |
System.Boolean |
|
Handler
Returns the work handler instance that was matched to perform work on this context or null if the match has not been made yet
Declaration
public WorkHandler Handler { get; }
Property Value
ID
Uniquely identifies the request
Declaration
Property Value
Type |
Description |
System.Guid |
|
IsAuthenticated
Returns true to indicate that this context is/was authenticated.
Used to not redirect users to login page on authorization exception
Declaration
public bool IsAuthenticated { get; }
Property Value
Type |
Description |
System.Boolean |
|
IsDELETE
Indicates that request method id DELETE
Declaration
public bool IsDELETE { get; }
Property Value
Type |
Description |
System.Boolean |
|
IsGET
Indicates that request method id GET
Declaration
public bool IsGET { get; }
Property Value
Type |
Description |
System.Boolean |
|
IsPATCH
Indicates that request method id PATCH
Declaration
public bool IsPATCH { get; }
Property Value
Type |
Description |
System.Boolean |
|
IsPOST
Indicates that request method id POST
Declaration
public bool IsPOST { get; }
Property Value
Type |
Description |
System.Boolean |
|
IsPUT
Indicates that request method id PUT
Declaration
public bool IsPUT { get; }
Property Value
Type |
Description |
System.Boolean |
|
Items
Provides a thread-safe dictionary of items. The underlying collection is lazily allocated
Declaration
public ConcurrentDictionary<object, object> Items { get; }
Property Value
Type |
Description |
System.Collections.Concurrent.ConcurrentDictionary<System.Object, System.Object> |
|
LastError
Declaration
public Exception LastError { get; set; }
Property Value
Type |
Description |
System.Exception |
|
Match
Returns the work match instances that was made for this requested work or null if nothing was matched yet
Declaration
public WorkMatch Match { get; }
Property Value
Matched
Returns dynamic object that contains variables that have been extracted by WorkMatch when dispatcher assigned request to WorkHandler.
If variables have not been assigned yet returns empty object
Declaration
public dynamic Matched { get; }
Property Value
Type |
Description |
System.Object |
|
MatchedVars
Returns variables that have been extracted by WorkMatch when dispatcher assigned request to WorkHandler.
If variables have not been assigned yet returns empty object
Declaration
public JSONDataMap MatchedVars { get; }
Property Value
NoDefaultAutoClose
Indicates whether the default dispatcher should close the WorkContext upon completion of async processing.
This property may ONLY be set to TRUE IF Response.Buffered = false (chunked transfer) and Response has already been written to.
When this property is set to true the WorkDispatcher will not auto dispose this WorkContext instance.
This may be needed for a server that streams chat messages and some other thread manages the lifetime of this WorkContext.
Keep in mind that alternative implementations of WorkDispatcher (derived classes that implement alternative threading/lifecycle)
may disregard this flag altogether
Declaration
public bool NoDefaultAutoClose { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
Portal
Returns portal object for this request or null if no portal was injected
Declaration
public Portal Portal { get; }
Property Value
PortalFilter
Returns the first portal filter which was injected in the processing line.
It is the filter that manages the portals for this context
Declaration
public PortalFilter PortalFilter { get; }
Property Value
PortalMatch
Returns matched that was made by portal filter or null
Declaration
public WorkMatch PortalMatch { get; }
Property Value
PortalMatchedVars
Returns variables that have been extracted by WorkMatch when PortalFilter assigned portal.
Returns null if no portal was matched
Declaration
public JSONDataMap PortalMatchedVars { get; }
Property Value
PortalTheme
Gets/sets portal theme. This may be null as this is just a holder variable
Declaration
public Theme PortalTheme { get; set; }
Property Value
Request
Returns HttpListenerRequest object for this context
Declaration
public HttpListenerRequest Request { get; }
Property Value
Type |
Description |
System.Net.HttpListenerRequest |
|
RequestBodyAsJSONDataMap
Fetches request body: multi-part content, URL encoded content, or JSON body into one JSONDataMap bag,
or null if there is no body.
The property does caching
Declaration
public JSONDataMap RequestBodyAsJSONDataMap { get; }
Property Value
RequestedJSON
Returns true if client indicated in response that "application/json" is accepted
Declaration
public bool RequestedJSON { get; }
Property Value
Type |
Description |
System.Boolean |
|
Response
Returns Response object for this context
Declaration
public Response Response { get; }
Property Value
Server
Returns the server that this context is under
Declaration
public WaveServer Server { get; }
Property Value
Session
Returns session that this context is linked with or null
Declaration
public WaveSession Session { get; }
Property Value
SessionFilter
Returns the first session filter which was injected in the processing line.
It is the filter that manages the session state for this context
Declaration
public SessionFilter SessionFilter { get; }
Property Value
SupportsSession
Returns true when the context was configured to support SessionFilter so Session can be injected
Declaration
public bool SupportsSession { get; }
Property Value
Type |
Description |
System.Boolean |
|
WholeRequestAsJSONDataMap
Fetches matched vars, multi-part content, URL encoded content, or JSON body into one JSONDataMap bag.
The property does caching
Declaration
public JSONDataMap WholeRequestAsJSONDataMap { get; }
Property Value
WorkSemaphoreReleased
Returns true to indicate that work semaphore has been already released.
It is not necessary to use this property or ReleaseWorkSemaphore() method as the framework does it
automatically in 99% cases. ReleaseWorkSemaphore() may need to be called from special places like HTTP streaming
servers that need to keep WorkContext instances open for a long time
Declaration
public bool WorkSemaphoreReleased { get; }
Property Value
Type |
Description |
System.Boolean |
|
Methods
___InternalInjectPortal(Portal, Theme, WorkMatch, JSONDataMap)
DEVELOPERS do not use!
A hack method needed in some VERY RARE cases, like serving an error page form the filter which is out of portal scope.
Declaration
public void ___InternalInjectPortal(Portal portal = null, Theme theme = null, WorkMatch match = null, JSONDataMap matchedVars = null)
Parameters
Destructor()
Warning: if overridden, must call base otherwise semaphore will not get released
Declaration
protected override void Destructor()
Overrides
GetWholeRequestAsJSONDataMap()
Converts request body and MatchedVars into a single JSONDataMap. Users should call WholeRequestAsJSONDataMap.get() as it caches the result
Declaration
protected virtual JSONDataMap GetWholeRequestAsJSONDataMap()
Returns
HasAnyVarsMatchingFieldNames(Doc)
Returns true if the whole request (body or matched vars) contains any names matching any field names of the specified document
Declaration
public bool HasAnyVarsMatchingFieldNames(Doc doc)
Parameters
Type |
Name |
Description |
Doc |
doc |
|
Returns
Type |
Description |
System.Boolean |
|
Log(MessageType, String, String, Exception, String, Nullable<Guid>)
Facilitates context-aware logging
Declaration
public void Log(MessageType type, string text, string from = null, Exception error = null, string pars = null, Guid? related = default(Guid? ))
Parameters
Type |
Name |
Description |
MessageType |
type |
|
System.String |
text |
|
System.String |
from |
|
System.Exception |
error |
|
System.String |
pars |
|
System.Nullable<System.Guid> |
related |
|
NeedsSession(Boolean)
Ensures that session is injected if session filter is present in processing chain.
If session is already available (Session!=null) then does nothing, otherwise
fills Session property with either NEW session (if onlyExisting=false(default)) if user supplied no session token,
OR gets session from session store as defined by the first SessionFilter in the chain
Declaration
public WaveSession NeedsSession(bool onlyExisting = false)
Parameters
Type |
Name |
Description |
System.Boolean |
onlyExisting |
|
Returns
ParseRequestBodyAsJSONDataMap()
This method is called only once as it touches the input streams
Declaration
protected virtual JSONDataMap ParseRequestBodyAsJSONDataMap()
Returns
ReleaseWorkSemaphore()
Releases work semaphore that throttles the processing of WorkContext instances.
The WorkContext is released automatically in destructor, however there are cases when the semaphore release
may be needed sooner, i.e. in a HTTP streaming application where work context instances are kept open indefinitely
it may not be desirable to consider long-living work context instances as a throttling factor.
Returns true if semaphore was released, false if it was not released during this call as it was already released before
Declaration
public bool ReleaseWorkSemaphore()
Returns
Type |
Description |
System.Boolean |
|
SetAuthenticated(Boolean)
Invoked by applications to signify the presence of authentication
Declaration
public void SetAuthenticated(bool value)
Parameters
Type |
Name |
Description |
System.Boolean |
value |
|
ToString()
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
|
Overrides
System.Object.ToString()
Implements
System.IDisposable
Extension Methods