Table of Contents

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

fileName string

The 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

fileName string

The 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.

viewSettings ListOfSavedViewSettings

Out 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 null if 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

documentType DocumentType

The 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

fileName string

The 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

typeOfFormDcoument Type

The type of the corresponding document window.

Returns

bool

True for 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

fileName string

The 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

fileName string

The 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.

viewSettings ListOfSavedViewSettings

Out 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:

  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.
public static void LoadDocument_GUISupport(string fileName, string documentName = "", bool addToRecentFileList = true)

Parameters

fileName string

The 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.

documentName string

If this optional parameter is specified it gives the caption of the document. Otherwise the file name is used to this end.

addToRecentFileList bool

By 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

fileName string

The 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

folder string

The 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

documentsToSave List<IStorableOnHDD>

The documents to save.

filePath string

The 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

documentToSave IStorableOnHDD

The document to save.

filePath string

The file path under which the document shall be saved.

viewSettings ListOfSavedViewSettings

If 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

filePathArchive string

The complete file path of the archive file.

Returns

string[]

Array with the complete file paths of all files extracted to the temporary directory.