Check out the latest documentation.

Offline Applications

As well as real time detection, 51Degrees Detector can also be used completely separately from ASP.NET and IIS. To do this, a Provider must be created from either a data file or the embedded data in the Detector.

Note: The Detector cannot be configured with the same config files as used in web applications, it must be configured in code. If you have installed the Detector in your offline application via Nuget the config and 'Mobile' folder can be deleted.

										
										using
										
										
										System
										
									;

										
										using
										
										
										FiftyOne.Foundation.Mobile.Detection
										
									;

										
										using
										
										
										FiftyOne.Foundation.Mobile.Detection.Factories
										
									;


										
										namespace
										
										
										Offline
										
									
{
    
										
										class
										
										
										Program
										
									
    {
        
										
										static
										
										
										void
										
										
										CreateProviders
										
									()
        {
            
										
										// A provider with no parameters creates a
										
										
										//provider from embedded lite data.
										
									
            Provider liteProvider = 
										
										new
										
									 Provider();

            
										
										// To create a provider from a dataset a factory
										
										
										// must be used.
										
									
            Provider premiumProvider = 
										
										new
										
									 Provider(StreamFactory.Create(
										
										"PATH_TO_DATA_FILE"
										
									));
        }

    }

}

									

A Provider uses the underlying data to provide information such as meta data about the properties and the publish date of the data. It is also able to return a Match object when given a useragent string or a NameValueCollection of http headers.

The following code will create a Provider from premium data and detect a useragent given from the command, outputting the hardware family of the device:

										
										using
										
										
										System
										
									;

										
										using
										
										
										System.Linq
										
									;

										
										using
										
										
										FiftyOne.Foundation.Mobile.Detection
										
									;

										
										using
										
										
										FiftyOne.Foundation.Mobile.Detection.Factories
										
									;


										
										namespace
										
										
										Offline
										
									
{
    
										
										class
										
										
										Program
										
									
    {
        
										
										static
										
									 Provider 
										
										CreateProvider
										
									()
        {
            
										
										// create a provider
										
									
            Provider provider = 
										
										new
										
									 Provider(StreamFactory.Create(
										
										"PATH_TO_DATA_FILE"
										
									));
            
										
										return
										
									 provider;
        }

        
										
										static
										
										
										void
										
										
										Main
										
									(
										
										string
										
									[] args)
        {
            
										
										// check a useragent is available
										
										
										if
										
									 (args.Length == 
										
										0
										
									)
            {
                Console.WriteLine(
										
										"You must supply a useragent"
										
									);
                
										
										return
										
									;
            }
            
										
										string
										
									 userAgent = args[
										
										0
										
									];

            Provider provider = CreateProvider();

            
										
										// provider created, now get a match
										
									
            Match match = provider.Match(userAgent);

            
										
										string
										
									 hardwareFamily = match.Results[
										
										"HardwareFamily"
										
									].First();

            Console.WriteLine(
                        
										
										"Useragent '{0}' is from HardwareFamily '{1}'"
										
									,
                        userAgent, hardwareFamily);
        }

    }

}