Nevron .NET Vision Documentation
Temporary File Management

Overview

Choosing an appropriate temporary file management strategy is important, because the security level and performance of your application depend on it. This topic will list the possible temporary file cleanup strategies you can use with Nevron Chart or Diagram for .NET.

No automatic clean up of the temporary directory.

You can safely disable temporary file clean up if you use the direct stream image to browser feature of the control because in this mode the component does not generate any temporary files and does not check for expired ones. This approach has two major advantages - no additional hard disk space is needed and a higher level of security for the image content is provided because there is actually no possibility an unauthorized user to access the images.

This approach is not recommended for response types that generate files on the server because you'll end up with a large amount of unused files in the temporary directory which you'll eventually have to clean up manually.

The following code disables the automatic file clean up of the control:

C#
Copy Code
//[theComponent] is the name of the Nevron component - being it a Chart or a Diagram
NTemporaryFileSettings tempFileSettings = theComponent].ServerSettings.TemporaryFileSettings;

tempFileSettings.EnableAutoDelete = false;
Visual Basic
Copy Code
'[theComponent] is the name of the Nevron component - being it a Chart or a Diagram

Dim tempFileSettings As NTemporaryFileSettings = [theComponent].ServerSettings.TemporaryFileSettings

tempFileSettings.EnableAutoDelete = False

You may also sometimes want to disable the automatic clean up to improve performance. A typical case is if you have to generate multiple chart images on a single page. In this case turning off and after rendering the images back on the automatic cleanup will increase the performance. This is because the control will not have to iterate through the temporary directory searching for expired files for each generated image.

Delete expired files (default)

The built-in clean up technique in Nevron Chart and Diagram for .NET determines when a file is expired by comparing the file time stamp against the current time. If the time span between the file creation and the current time is bigger than the ExpireSpan property of the NTemporaryFileSettings object the file is considered expired and will be deleted if EnableAutoDelete is set to true. The default value of the ExpireSpan property is one minute. The following code changes the expire span to 1 day:

C#
Copy Code
//[theComponent] is the name of the Nevron component - being it a Chart or a Diagram

NTemporaryFileSettings tempFileSettings = theComponent].ServerSettings.TemporaryFileSettings;
tempFileSettings.EnableAutoDelete = false;
tempFileSettings.ExpireSpan = new TimeSpan(1, 0, 0);
Visual Basic
Copy Code
'[theComponent] is the name of the Nevron component - being it a Chart or a Diagram

Dim tempFileSettings As NTemporaryFileSettings = [theComponent].ServerSettings.TemporaryFileSettings
tempFileSettings.EnableAutoDelete = False
tempFileSettings.ExpireSpan = new TimeSpan(1, 0, 0)

Besides monitoring for expired files when EnableAutoDelete is set to true the component will also check whether the temporary directory exceeds the size limit controlled by the MaxTempDirectorySize property (specified in KB) and a file count limit controlled by the MaxTempFilesCount property. When either of the limits is exceeded the chart will delete files until both limits are met starting from the oldest files in the directory.

The default values for the MaxTempDirectorySize and MaxTempFilesCount are 2048KB and 100 files respectively. The following code modifies the MaxTempDirectorySize and MaxTempFilesCount properties:

C#
Copy Code
//[theComponent] is the name of the Nevron component - being it a Chart or a Diagram

NTemporaryFileSettings tempFileSettings = theComponent].ServerSettings.TemporaryFileSettings;
tempFileSettings.EnableAutoDelete = true;
tempFileSettings.ExpireSpan = new TimeSpan(1, 0, 0);
tempFileSettings.MaxTempDirectorySize = 1048576;
tempFileSettings.MaxTempFilesCount = 10000;
Visual Basic
Copy Code
'[theComponent] is the name of the Nevron component - being it a Chart or a Diagram
Dim tempFileSettings As NTemporaryFileSettings = [theComponent].ServerSettings.TemporaryFileSettings
tempFileSettings.EnableAutoDelete = True
tempFileSettings.ExpireSpan = New TimeSpan(1, 0, 0)
tempFileSettings.MaxTempDirectorySize = 1048576
tempFileSettings.MaxTempFilesCount = 10000

Remarks: You must assign the appropriate permissions if you want to be able to insert messages in the system log.

 

The advantages of this technique are that it does not require you to manually check whether the temporary directory exceeds some limits or whether it contains expired files. The drawback is that it reduces the server performance because each time the control generates a temporary file it also checks for expired temporary files. Another concern is that it requires the ASPNET account to have list folder contents and modify permissions for the temporary directory which can compromise the security.

See Also

 

 


©2017. Nevron Software LLC.

Send Feedback