DownloadCounter

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.0.7
  • Enterprise
  • Community
  • Planned

Overview

This page contains information for developers about the Application Programming Interface (API) for logging document downloads on the portal.

DownloadCounter API was created to allow 3rd party developers to execute a custom code on any portal event when a document is downloaded.

Details

DownloadCounter module does not do anything on its own. It provides a simple interface for executing custom code when a document is downloaded. The event fires when a user accesses a file through http download or WebDAV, either from the repository or file system cache.

To take advantage of the module you simply need to create a new class that implements the IDownloadCounter interface. There are two methods to implement here:

  • void Increment(int fileId)
  • void Increment(string filePath)

You can execute any custom code in these methods that takes advantage of the given file id or path - e.g. log the download event into a custom database.

Note that as of now these methods run synchronously in the system. Try not to write any long-running code here that can slow down document download on the portal.

Note that the API is implemented in a way that you can have only one custom download counter in the system.

The DownloadCounter module can be switched on or off with the following web.config setting (default is false):

<add key="DownloadCounterEnabled" value="false" />

Examples

The following class is an example of an implementation of a custom download counter.

public class MyCustomDownloadCounter : IDownloadCounter
{
    public void Increment(int fileId) 
	{ 
		using (var dc = new MyCustomDataContext())
		{
			dc.LogDownload(fileId);
		}
	}
 
    public void Increment(string filePath) 
	{ 
		using (var dc = new MyCustomDataContext())
		{
			dc.LogDownload(filePath);
		}
	}
}

Related links

References