Export
Zunächst wird den Variablen svdFile und destination der Inhalt der jeweiligen Textbox zugeordnet. Anschließend wird überprüft, ob der Benutzer beide Pfade richtig eingegeben hat.
Danach wird die Konfigurationsdatei (.svdx-Datei) in ein ScopeProject geladen.
Ist die Konfiguration geladen, wird der Pfad, in dem die neue Datei gespeichert werden soll, überprüft. Ist der Pfad erreichbar, wird dem ShowProgress Property ein Fenster übergeben, welches den Status des Exports anzeigt und danach kann mit der Export Methode der Export gestartet werden.
private void btnExport_Click(object sender, EventArgs e)
{
ScopeProject scopeProject = new ScopeProject();
string svdxFile = textBox_SVDX.Text;
string destination = @textBox_Export.Text;
try
{
//Checking the existence of the path
if (destination == null)
{
destination = Environment.CurrentDirectory;
}
else if (string.IsNullOrEmpty(svdxFile) || !File.Exists(svdxFile))
{
MessageBox.Show("SVDX File could not be found!", "SVDX Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
scopeProject.SetFromFile(svdxFile);
}
if (string.IsNullOrEmpty(destination))
{
MessageBox.Show("No destination file defined!", "Destination Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
try
{
//search the method with the right export
scopeProject.ShowProgress = (string header, TwinCAT.Scope2.Tools.ProgressBox.WorkDelegate work) => { return TwinCAT.Scope2.Tools.ProgressBox.Show(this, header, 100, work) == DialogResult.OK; };
scopeProject.Export(destination);
}
catch (Exception)
{
System.Diagnostics.Debug.Write("Could not save file");
}
}
//Disconnect the .svdx File
scopeProject.Disconnect(true);
scopeProject.Dispose();
}
catch (Exception ex)
{
Console.Write(ex.ToString());
Console.ReadLine();
scopeProject.Disconnect(true);
}
}