PersistToFile Method (.NET)

The Enterprise Edition of CountryHawk keeps a running total of all statistics in memory. This means that once the application or web services that use CountryHawk are restarted, the statistics will be zeroed. This is a static method.

The CountryStats class provides the PeristToFile and LoadFromFile methods that can be used to persist all collected statistics to a file on your server and later reload these statistics back into memory so that additional lookups performed by CountryHawk will be added to the existing results.

Syntax:

 chStatsObj.PersistToFile([pathAndFileName])

pathAndFileName: Optional. If specified, the statistics are written to the path and file name specified by this parameter. If omitted (default), the statistics are written to the path and file name specified by the country.stats.file property listed in the countries.properties file. See the important note below regarding required permissions.

Returns:

This method does not return any result. Upon successfully execution all in-memory statistics are written to the statistics file for future loading implicitly the next time the CountryObj class is loaded into memory after application shutdown, or explicitly by the LoadFromFile method. If an error occurs during its operation it raises a run-time error with a description of the problem.

VB.NET Example:

 

CountryStats.PersistToFile()

C# Example:

 

CountryStats.PersistToFile();

 

Important note: Unlike all other files used by CountryHawk, your security settings must provide read and write permissions to the file used by this method. Typically in a tightened security environment only read access would be required. However write access is also required so that the component can write the data out to the file. If you used the default CountryHawk installation you should not need to take any special steps to enable write access for this file. If you installed CountryHawk manually or have changed permissions around after installation, be sure to grant the user account which CountryHawk is running through (typically IUSR_XXXX for IIS users) these permissions. In any event if CountryHawk does not have the proper security settings it will indicate so in a detailed error message when this method is called.

Tip: This method is best used by ASP.NET developers from global.asax in the Application OnStart event. See the detailed discussion in the Persisting Statistics topic for more information.

 

Note: This method requires the Enterprise Edition of CountryHawk.

See Also:

LoadFromFile Method (.NET)