Export
First, the content of the respective text box is assigned to the variables svdFile and destination. The system then checks whether the user has entered both paths correctly.
After that the configuration file (.svdx file) is loaded into a ScopeProject.
Once the configuration has been loaded, the path via which the new file is to be saved is checked. If the path is reachable, a window is transferred to the ShowProgress property that displays the status of the export and the export can then be started with the Export method.
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);
}
}