C# Class FiftyOne.Foundation.Mobile.Detection.WebProvider

A provider with methods designed to be called from within web applications where HttpRequest objects can be used to provide the necessary evidence for detection.
Inheritance: Provider, IDisposable
Mostra file Open project: 51Degrees/dotNET-Device-Detection Class Usage Examples

Public Methods

Method Description
CheckDataFileRefresh ( object state ) : void

Checks if the data file has been updated and refreshes if it has.

Download ( ) : LicenceKeyResults

Checks for a new version of the data file if licence keys are available.

Refresh ( ) : void

Forces the application to reload the active provider on the next request.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Disposes of the DataSet if one is available.

Private Methods

Method Description
CheckDataFileHasRefreshed ( FiftyOne.Foundation.Mobile.Detection.Entities.DataSet dataSet ) : bool

Returns true if a newer data set is now available.

CleanTemporaryFiles ( ) : void

Cleans up any temporary files that remain from previous providers.

Create ( ) : WebProvider

Forces the provider to update current ActiveProvider with new data.

CreateNewTemporaryFile ( FileInfo masterFile ) : FileInfo

Create a new temporary file for use the stream factory.

GetActiveProvider ( ) : WebProvider

A reference to the active provider.

GetContextItems ( HttpRequest request ) : System.Collections.IDictionary

Returns a collection that can be used to persist data across the request. If using .NET 4 or above the HttpRequest context items collection is used. If lower versions then the current context, if it exists is used. If there is no collection available then null is returned and the requesting routine will need to work without the benefit of persisting the detection result across the request.

The implementation varies by .NET version.

GetDataFileDate ( string fileName ) : DateTime?

Creates a stream data set for the file provided and returns the published data of the file. Throws an exception if there's a problem accessing the file.

GetMatch ( HttpRequest request ) : Match

Returns the match results for the request, or creates one if one does not already exist. If the match has already been calculated it is fetched from the context items collection.

GetRequiredHeaders ( HttpRequest request ) : NameValueCollection

Gets the required headers. If the MVC method SetBrowserOverride has been used the User-Agent will be escapted and may contain + characters which need to be removed.

Requests after SetOverrideBrowser are still expected to use the overriden alias. The override useragent is stored in cookie which ASP.NET unpacks automatically, however it is url encoded with pluses instead of spaces. This code transforms the useragent back, but a new NameValueCollection is needed as the original collection cannot be modified.

GetTempFileDataSet ( ) : FiftyOne.Foundation.Mobile.Detection.Entities.DataSet

Returns a data set initialised with a temporary data file. If an existing one is present that can be used then it will be favoured. If a new one is needed then one will be created.

GetTempFileName ( ) : string

Returns a temporary file name for the data file.

OnProcessExit ( object sender, EventArgs e ) : void

The application is being disposed of either due to a recycle event or shutdown. Ensure the active provider is disposed of to release resources.

WebProvider ( FiftyOne.Foundation.Mobile.Detection.Entities.DataSet dataSet ) : System

Constructs a new instance of the provider with the data set supplied.

Method Details

CheckDataFileRefresh() public static method

Checks if the data file has been updated and refreshes if it has.
public static CheckDataFileRefresh ( object state ) : void
state object Required for timer callback. This parameter is not used.
return void

Dispose() protected method

Disposes of the DataSet if one is available.
protected Dispose ( bool disposing ) : void
disposing bool /// True if the calling method is Dispose, false for the finaliser. ///
return void

Download() public static method

Checks for a new version of the data file if licence keys are available.
public static Download ( ) : LicenceKeyResults
return LicenceKeyResults

Refresh() public static method

Forces the application to reload the active provider on the next request.
public static Refresh ( ) : void
return void