Class FileHandlingSupport
- Namespace
- VirtualLabAPI.Core.BasicFunctions
- Assembly
- VirtualLabAPI.dll
Class providing support methods for loading & importing of files.
public static class FileHandlingSupport
- Inheritance
-
FileHandlingSupport
- Inherited Members
Methods
AppendDateTimeToFileName(string)
Appends the date and the time to the end of the given file name.
public static string AppendDateTimeToFileName(string fileName)
Parameters
fileNamestringThe file name including path and extension.
Returns
- string
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(string, out ListOfSavedViewSettings)
Loads an object from hard disc.
public static IStorableOnHDD GenericLoad(string fileName, out ListOfSavedViewSettings viewSettings)
Parameters
fileNamestringThe 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.
viewSettingsListOfSavedViewSettingsOut parameter to return the view settings (e.g. size of the document window) saved together with the actual document.
Returns
- IStorableOnHDD
The loaded document. Can be
nullif no view settings were stored alongside the actual object.
GetImageForDocumentType(DocumentType)
Gets the type of the image matching the given document type.
public static Bitmap GetImageForDocumentType(DocumentType documentType)
Parameters
documentTypeDocumentTypeThe document type for which the matching image shall be returned.
Returns
- Bitmap
Retrieves the correct image matching the given document type.
Exceptions
- ArgumentException
No suitable image could be found for the given document type.
ImportAndShowFile(string)
Method to import various file types and show the imported data as new document. This method is not thread-safe.
public static void ImportAndShowFile(string fileName)
Parameters
fileNamestringThe full name including the path of the file to be imported.
Exceptions
- FileLoadException
File format unsupported
IsDoumentsWithoutViewSettingsSaveMechanism(Type)
Method which defined which types of document windows shall not use the saving algorithm for view settings
public static bool IsDoumentsWithoutViewSettingsSaveMechanism(Type typeOfFormDcoument)
Parameters
typeOfFormDcoumentTypeThe type of the corresponding document window.
Returns
- bool
Truefor IFTA Optimization and module documents as these do not support the view settings mechanism.
LoadDocument(string)
Loads a document, but not the corresponding view settings.
public static IDocument LoadDocument(string fileName)
Parameters
fileNamestringThe 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
- IDocument
The loaded document.
LoadDocument(string, out ListOfSavedViewSettings)
Loads a document.
public static IDocument LoadDocument(string fileName, out ListOfSavedViewSettings viewSettings)
Parameters
fileNamestringThe 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.
viewSettingsListOfSavedViewSettingsOut parameter to return the view settings (e.g. size of the document window) saved together with the actual document.
Returns
- IDocument
The loaded document.
LoadDocument_GUISupport(string, string, bool)
Loads a document to the GUI asynchronously. This method does the following steps:
- Enable the hour glass cursor.
- Load the file.
- Add the file to the "Recent Files" list.
- Displays the document window (including the loaded view settings, if applicable)
- Disable the hourglass cursor.
public static void LoadDocument_GUISupport(string fileName, string documentName = "", bool addToRecentFileList = true)
Parameters
fileNamestringThe 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.
documentNamestringIf this optional parameter is specified it gives the caption of the document. Otherwise the file name is used to this end.
addToRecentFileListboolBy 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.
Exceptions
- ArgumentException
No main form is given.
MakeFileNameValid(string)
Makes the given file name valid, i.e. all characters not allowed in file names are replaced by an underscore.
public static string MakeFileNameValid(string fileName)
Parameters
fileNamestringThe file name to make valid.
Returns
- string
The changed file name.
OpenFolderInExplorer(string)
Opens the given folder in Windows File Explorer.
public static void OpenFolderInExplorer(string folder)
Parameters
folderstringThe folder to open.
SaveCompressed(List<IStorableOnHDD>, string)
Saves the given documents as a zip file.
public static void SaveCompressed(List<IStorableOnHDD> documentsToSave, string filePath)
Parameters
documentsToSaveList<IStorableOnHDD>The documents to save.
filePathstringThe file path under which the document shall be saved.
SaveCompressed(IStorableOnHDD, string, ListOfSavedViewSettings)
Saves the given document as a zip file.
public static void SaveCompressed(this IStorableOnHDD documentToSave, string filePath, ListOfSavedViewSettings viewSettings = null)
Parameters
documentToSaveIStorableOnHDDThe document to save.
filePathstringThe file path under which the document shall be saved.
viewSettingsListOfSavedViewSettingsIf this optional parameter is set, the given view settings are also stored in the compressed file.
UnpackFile(string)
Unpacks the given zip file to a temporary folder.
public static string[] UnpackFile(string filePathArchive)
Parameters
filePathArchivestringThe complete file path of the archive file.
Returns
- string[]
Array with the complete file paths of all files extracted to the temporary directory.