Programming Reference for VirtualLab Fusion  2026.1
Loading...
Searching...
No Matches
FileHandlingSupport Class Reference

This class is subject to change. Programs using this class may require changes with a new version of VirtualLab.
Class providing support methods for loading & importing of files. More...

Static Public Member Functions

static string AddExtension (string fileName, string extension)
 Adds an extension to the given file name.
 
static string AppendDateTimeToFileName (string fileName)
 Appends the date and the time to the end of the given file name.
 
static IStorableOnHDD GenericLoad (string fileName, out ListOfSavedViewSettings viewSettings)
 Loads an object from HDD.
 
static Bitmap GetImageForDocumentType (DocumentType documentType)
 Gets the type of the image matching the given document type.
 
static void ImportAndShowFile (string fileName)
 Method to import various file types and show the imported data as new document. This method is not thread-safe.
 
static bool IsDoumentsWithoutViewSettingsSaveMechanism (Type typeOfFormDcoument)
 Method which defined which types of document windows shall not use the saving algorithm for view settings.
 
static IDocument LoadDocument (string fileName)
 Loads a document, but not the corresponding view settings.
 
static IDocument LoadDocument (string fileName, out ListOfSavedViewSettings viewSettings)
 Loads a document.
 
static async void LoadDocument_GUISupport (string fileName, string documentName="", bool addToRecentFileList=true)
 Loads a document to the GUI asynchronously. This method does the following steps:
 
static string MakeFileNameValid (string fileName)
 Makes the given file name valid, i.e. all characters not allowed in file names are replaced by an underscore.
 
static void OpenFolderInExplorer (string folder)
 Opens the given folder in Windows File Explorer.
 
static void SaveCompressed (List< IStorableOnHDD > documentsToSave, string filePath)
 Saves the given documents as a zip file.
 
static void SaveCompressed (this IStorableOnHDD documentToSave, string filePath, ListOfSavedViewSettings viewSettings=null)
 Saves the given document as a zip file.
 
static string[] UnpackFile (string filePathArchive)
 Unpacks the given zip file to a temporary folder.
 

Detailed Description

This class is subject to change. Programs using this class may require changes with a new version of VirtualLab.
Class providing support methods for loading & importing of files.

Member Function Documentation

◆ AddExtension()

static string AddExtension ( string fileName,
string extension )
static

Adds an extension to the given file name.

Parameters
fileNameThe file name.
extensionThe extension.
Returns
The file name with the added extension. If the extension does not contain a leading period (.), a period is added. In contrast to Path.ChangeExtension, "filename.3" + ".ext" becomes "filename.3.ext", not "filename.ext". If the file name already ends with the given extension, it is not added anew.

◆ AppendDateTimeToFileName()

static string AppendDateTimeToFileName ( string fileName)
static

Appends the date and the time to the end of the given file name.

Parameters
fileNameThe file name including path and extension.
Returns
The altered file name with the date and time added in brackets and in ISO format, e.g. (C:\myfile (2018-11-09T134257).txt").

◆ GenericLoad()

static IStorableOnHDD GenericLoad ( string fileName,
out ListOfSavedViewSettings viewSettings )
static

Loads an object from HDD.

Parameters
fileNameThe file name of the object to load. It is checked whether the file exists and whether the extension of that file is a supported document type of VirtualLab.
viewSettingsOut parameter to return the view settings (e.g. size of the document window) saved together with the actual document.
Returns
The loaded document. Can be null if no view settings were stored alongside the actual object.

◆ GetImageForDocumentType()

static Bitmap GetImageForDocumentType ( DocumentType documentType)
static

Gets the type of the image matching the given document type.

Parameters
documentTypeThe document type for which the matching image shall be returned.
Returns
Retrieves the correct image matching the given document type.
Exceptions
System.ArgumentExceptionNo suitable image could be found for the given document type.

◆ ImportAndShowFile()

static void ImportAndShowFile ( string fileName)
static

Method to import various file types and show the imported data as new document. This method is not thread-safe.

Parameters
fileNameThe full name including the path of the file to be imported.
Exceptions
FileLoadExceptionFile format unsupported

◆ IsDoumentsWithoutViewSettingsSaveMechanism()

static bool IsDoumentsWithoutViewSettingsSaveMechanism ( Type typeOfFormDcoument)
static

Method which defined which types of document windows shall not use the saving algorithm for view settings.

Parameters
typeOfFormDcoumentThe type of the corresponding document window.
Returns
True for IFTA Optimization and module documents as these do not support the view settings mechanism.

◆ LoadDocument() [1/2]

static IDocument LoadDocument ( string fileName)
static

Loads a document, but not the corresponding view settings.

Parameters
fileNameThe file name of the document to load. It is checked whether the file exists and whether the extension of that file is a supported document type of VirtualLab.
Returns
The loaded document.

◆ LoadDocument() [2/2]

static IDocument LoadDocument ( string fileName,
out ListOfSavedViewSettings viewSettings )
static

Loads a document.

Parameters
fileNameThe file name of the document to load. It is checked whether the file exists and whether the extension of that file is a supported document type of VirtualLab.
viewSettingsOut parameter to return the view settings (e.g. size of the document window) saved together with the actual document.
Returns
The loaded document.

◆ LoadDocument_GUISupport()

static async void LoadDocument_GUISupport ( string fileName,
string documentName = "",
bool addToRecentFileList = true )
static

Loads a document to the GUI asynchronously. This method does the following steps:

  1. Enable the hour glass cursor.
  2. Load the file.
  3. Add the file to the "Recent Files" list.
  4. Displays the document window (including the loaded view settings, if applicable)
  5. Disable the hourglass cursor.
Parameters
fileNameThe file name of the document to load. It is checked whether the file exists and whether the extension of that file is a supported document type of VirtualLab.
documentNameIf this optional parameter is specified it gives the caption of the document. Otherwise the file name is used to this end.
addToRecentFileListBy default the loaded document is added to the list of recently used files. However if you set this optional parameter to false, this is not the case.
Returns
The shown document window.
Exceptions
ArgumentExceptionNo main form is given.

◆ MakeFileNameValid()

static string MakeFileNameValid ( string fileName)
static

Makes the given file name valid, i.e. all characters not allowed in file names are replaced by an underscore.

Parameters
fileNameThe file name to make valid.
Returns
The changed file name.

◆ OpenFolderInExplorer()

static void OpenFolderInExplorer ( string folder)
static

Opens the given folder in Windows File Explorer.

Parameters
folderThe folder to open.

◆ SaveCompressed() [1/2]

static void SaveCompressed ( List< IStorableOnHDD > documentsToSave,
string filePath )
static

Saves the given documents as a zip file.

Parameters
documentsToSaveThe documents to save.
filePathThe file path under which the document shall be saved.

◆ SaveCompressed() [2/2]

static void SaveCompressed ( this IStorableOnHDD documentToSave,
string filePath,
ListOfSavedViewSettings viewSettings = null )
static

Saves the given document as a zip file.

Parameters
documentToSaveThe document to save.
filePathThe file path under which the document shall be saved.
viewSettingsIf this optional parameter is set, the given view settings are also stored in the compressed file.

◆ UnpackFile()

static string[] UnpackFile ( string filePathArchive)
static

Unpacks the given zip file to a temporary folder.

Parameters
filePathArchiveThe complete file path of the archive file.
Returns
Array with the complete file paths of all files extracted to the temporary directory.