Class TempFileManager
Creates and manages a tempoary file ensuring that it is deleted when no longer required.
Inheritance
Implements
Inherited Members
Namespace: Sdl.FileTypeSupport.Framework
Assembly: Sdl.FileTypeSupport.Framework.Core.dll
Syntax
public class TempFileManager : IDisposable
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
Constructors
TempFileManager()
Creates a temp file with a random name and manages it.
See Temp
Declaration
public TempFileManager()
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
TempFileManager(String)
Creates the named temp file in a random temp directory or named sub-directory and manages it.
See Temp
Declaration
public TempFileManager(string filePath)
Parameters
Type | Name | Description |
---|---|---|
String | filePath | A temp filename to create or empty for a random filename to be generated. |
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
TempFileManager(String, Boolean)
Creates a temp file and manages it.
Declaration
public TempFileManager(string filePath, bool lockFile)
Parameters
Type | Name | Description |
---|---|---|
String | filePath | A temp filename to create or empty for a random filename to be generated. |
Boolean | lockFile | If set to |
Remarks
If an empty file name is given then a random temp file is created. If only a file name is given then a temp folder is created and a file with the file name is created. If a full or partial path is given the then a temp folder with the last folder name in the path is created and a file with the file name is created within it.
Properties
CancelDelete
If true
then this managed file is not deleted when this instance is disposed.
Declaration
public bool CancelDelete { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
Deleted
If true
then this managed file was sucessfully deleted.
Declaration
public bool Deleted { get; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
DeleteDirectoryIfEmpty
If true
a check will be made after the file
has been deleted, and if no other files exist in the
same directory that directory will also be deleted.
Declaration
public bool DeleteDirectoryIfEmpty { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
FilePath
Full path to the file to be deleted.
Declaration
public string FilePath { get; }
Property Value
Type | Description |
---|---|
String |
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
FileProcess
Can be set to a running process' System.
Declaration
public Process FileProcess { get; set; }
Property Value
Type | Description |
---|---|
Process |
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
Locked
Set to create (if it does not exist) and then to lock the temp file.
The locked System.
Declaration
public bool Locked { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
LockedFileStream
Returns the locked System.
Declaration
public FileStream LockedFileStream { get; set; }
Property Value
Type | Description |
---|---|
File |
Remarks
The System.
ReadOnly
If set to true
the managed temp file's readonly file system flag is set.
Declaration
public bool ReadOnly { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
The file must exist or be subsequently locked by setting Locked for this property to have any effect.
Methods
AutoDeleteNonLockedFiles()
Deletes all Temp
Declaration
public static void AutoDeleteNonLockedFiles()
Remarks
This public static method is designed to be called when the using applicatin starts up so that all tempoary files that have been created by a previous invocation of the applicaion that could not be automatically delted can be deleted when the using application restarts.
This also employs a locking mechanism so that if two instances of the application are launched only the first instance will delete temp files that were left from a previous instance of the applicaiton.
Dispose()
Deletes the file, if it exists.
Declaration
public void Dispose()
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
Dispose(Boolean)
Implementation of the recommended dispose protocol. Deletes the file if possible.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing | true if this method is called from IDisposable.Dispose() and false if called from Finalizer |
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
Finalize()
Deletes the file, if possible.
Declaration
protected void Finalize()
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.
TakeOverManagedFile(ref TempFileManager, TempFileManager)
This method handles the logic of handing over the management of a TempFileManager managed file to a new managed file
Declaration
public static void TakeOverManagedFile(ref TempFileManager managedFile, TempFileManager value)
Parameters
Type | Name | Description |
---|---|---|
Temp |
managedFile | |
Temp |
value |
Remarks
The temp file's file system readonly flag can also be set using Read
This class uses the File
The class also implements the IDisposable
interface, and deletes the
FileJanitor managed file in the Dispose()
implementation.
If the file for some reason cannot be deleted no error is raised.
Note that the .NET Framework does not guarantee that finalizers will be called, so there is always a possibility that the file does not get deleted.
The TempFileManager class also has a static method AutoDeleteNonLockedFiles() that can be called during applicaiton startup to delete any temp files that may not have been deleted previously.