Skip to content

Commit

Permalink
Bugfix regarding non existant file selection
Browse files Browse the repository at this point in the history
+ A bit of refractoring and exception now shows up.
  • Loading branch information
Parozzz committed Apr 1, 2022
1 parent 8eb6dd6 commit 69270ed
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 64 deletions.
Binary file modified .vs/TiaAddIn-Spin/v17/.suo
Binary file not shown.
116 changes: 58 additions & 58 deletions TiaAddIn-Spin/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ private void ExportBlockClick(MenuSelectionProvider selectionProvider)
{
Filter = "xml files (*.xml)|*.xml",
CheckFileExists = false,
CheckPathExists = false,
Multiselect = false,
Title = "Export BLOCK " + block.Name,
ShowHelp = true,
FileName = block.Name
};

if (fileDialog.ShowDialog(Util.CreateForm()) == DialogResult.OK)
{
ExportUtil.Export(block.Export, fileDialog.FileName);
Expand All @@ -83,28 +83,20 @@ private void ImportBlockClick(MenuSelectionProvider selectionProvider)
{
foreach (PlcBlock block in selectionProvider.GetSelection())
{
var group = (PlcBlockGroup)block.Parent;

var fileDialog = new OpenFileDialog
{
Filter = "xml files (*.xml)|*.xml",
CheckFileExists = false,
CheckFileExists = true,
CheckPathExists = true,
Multiselect = true
};

if (fileDialog.ShowDialog(Util.CreateForm()) == DialogResult.OK)
{
var files = fileDialog.FileNames;
foreach (var fileName in files)
foreach (var fileName in fileDialog.FileNames)
{
var blockGroup = (PlcBlockGroup)block.Parent;
try
{
var fileInfo = new FileInfo(fileName);
blockGroup.Blocks.Import(fileInfo, ImportOptions.Override,
SWImportOptions.IgnoreMissingReferencedObjects |
SWImportOptions.IgnoreStructuralChanges |
SWImportOptions.IgnoreUnitAttributes);
}
catch { }
ImportBlock(group, fileName);
}
}

Expand All @@ -116,34 +108,40 @@ private void ImportBlockFolderClick(MenuSelectionProvider selectionProvider)
{
foreach (PlcBlock block in selectionProvider.GetSelection())
{
var folderDialog = new FolderBrowserDialog();
var group = (PlcBlockGroup)block.Parent;

var folderDialog = new FolderBrowserDialog();
if (folderDialog.ShowDialog(Util.CreateForm()) == DialogResult.OK)
{
string[] files = Directory.GetFiles(folderDialog.SelectedPath);

foreach (var fileName in files)
foreach (var fileName in Directory.GetFiles(folderDialog.SelectedPath))
{
if (fileName.EndsWith(".xml"))
{
var blockGroup = (PlcBlockGroup)block.Parent;
try
{
var fileInfo = new FileInfo(fileName);
blockGroup.Blocks.Import(fileInfo, ImportOptions.Override,
SWImportOptions.IgnoreMissingReferencedObjects |
SWImportOptions.IgnoreStructuralChanges |
SWImportOptions.IgnoreUnitAttributes);
}
catch { }
}
ImportBlock(group, fileName);
}
}

break;
}
}

private void ImportBlock(PlcBlockGroup group, string fileName)
{
if (fileName.EndsWith(".xml"))
{
try
{
var fileInfo = new FileInfo(fileName);
group.Blocks.Import(fileInfo, ImportOptions.Override,
SWImportOptions.IgnoreMissingReferencedObjects |
SWImportOptions.IgnoreStructuralChanges |
SWImportOptions.IgnoreUnitAttributes);
}
catch(Exception ex)
{
Util.ShowExceptionMessage(ex);
}
}
}

private void ExportTagTableClick(MenuSelectionProvider selectionProvider)
{
foreach (PlcTagTable tagTable in selectionProvider.GetSelection())
Expand All @@ -152,12 +150,12 @@ private void ExportTagTableClick(MenuSelectionProvider selectionProvider)
{
Filter = "xml files (*.xml)|*.xml",
CheckFileExists = false,
CheckPathExists = false,
Multiselect = false,
Title = "Export tagtable " + tagTable.Name,
ShowHelp = true,
FileName = tagTable.Name
};

if (fileDialog.ShowDialog(Util.CreateForm()) == DialogResult.OK)
{
ExportUtil.Export(tagTable.Export, fileDialog.FileName);
Expand All @@ -182,25 +180,20 @@ private void ImportTagTableClick(MenuSelectionProvider selectionProvider)
{
foreach (PlcTagTable tagTable in selectionProvider.GetSelection())
{
var group = (PlcTagTableGroup)tagTable.Parent;

var fileDialog = new OpenFileDialog
{
Filter = "xml files (*.xml)|*.xml",
CheckFileExists = false,
CheckFileExists = true,
CheckPathExists = true,
Multiselect = true
};

if (fileDialog.ShowDialog(Util.CreateForm()) == DialogResult.OK)
{
var files = fileDialog.FileNames;
foreach (var fileName in files)
foreach (var fileName in fileDialog.FileNames)
{
var group = (PlcTagTableGroup)tagTable.Parent;
try
{
var fileInfo = new FileInfo(fileName);
group.TagTables.Import(fileInfo, ImportOptions.Override);
}
catch { }
ImportTagTable(group, fileName);
}
}
}
Expand All @@ -210,29 +203,36 @@ private void ImportTagTableFolderClick(MenuSelectionProvider selectionProvider)
{
foreach (PlcTagTable tagTable in selectionProvider.GetSelection())
{
var folderDialog = new FolderBrowserDialog();
var group = (PlcTagTableGroup)tagTable.Parent;

var folderDialog = new FolderBrowserDialog();
if (folderDialog.ShowDialog(Util.CreateForm()) == DialogResult.OK)
{
string[] files = Directory.GetFiles(folderDialog.SelectedPath);

foreach (var fileName in files)
foreach (var fileName in Directory.GetFiles(folderDialog.SelectedPath))
{
if (fileName.EndsWith(".xml"))
{
var group = (PlcTagTableGroup)tagTable.Parent;
try
{
var fileInfo = new FileInfo(fileName);
group.TagTables.Import(fileInfo, ImportOptions.Override);
}
catch { }
}
ImportTagTable(group, fileName);
}
}

break;
}
}

private void ImportTagTable(PlcTagTableGroup group, string fileName)
{
if (fileName.EndsWith(".xml"))
{
try
{
var fileInfo = new FileInfo(fileName);
group.TagTables.Import(fileInfo, ImportOptions.Override);
}
catch (Exception ex)
{
Util.ShowExceptionMessage(ex);
}
}
}

}
}
6 changes: 2 additions & 4 deletions TiaAddIn-Spin/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public static string DesktopFolder()

public static void ShowExceptionMessage(Exception ex)
{
string message = "Message: " + ex.Message + " \r\n StackTrace: " + ex.StackTrace;
string message = "Message: " + ex.Message + "\r\nStackTrace: " + ex.StackTrace;
string caption = "An exception occoured while executing Spin Addin!";

MessageBox.Show(message, caption);
MessageBox.Show(Util.CreateForm(), message, caption);
}
}

Expand All @@ -113,8 +113,6 @@ public static bool Export(ExportDelegate exportDelegate, string filePath, Export
catch (Exception ex)
{
Util.ShowExceptionMessage(ex);

//Trace.TraceError("Exception during export:" + Environment.NewLine + ex);
return false;
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions TiaAddIn-Spin/bin/Release/PostBuildLog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
C:\Program Files\Siemens\Automation\Portal V16\PublicAPI\V16.AddIn\Siemens.Engineering.AddIn.Publisher.exe --> 31/03/2022 12:39:49 UTC
C:\Program Files\Siemens\Automation\Portal V16\PublicAPI\V16.AddIn\Siemens.Engineering.AddIn.Publisher.exe --> 01/04/2022 08:47:55 UTC

Calling Arguments:
--configuration :C:\Users\PARONETTO G\Documents\GitHub\TiaAddIn-Spin\TiaAddIn-Spin\Config.xml
Expand Down Expand Up @@ -38,4 +38,4 @@ Packaging Permission 'System.Security.Permissions.EnvironmentPermission'.
Packaging Permission 'System.Net.Mail.SmtpPermission'.
Packaging Permission 'TIA.ReadWrite'.

--> S U C C E E D E D <-- (0,149s)
--> S U C C E E D E D <-- (0,146s)
Binary file modified TiaAddIn-Spin/bin/Release/SpinAddIn.addin
Binary file not shown.
Binary file modified TiaAddIn-Spin/bin/Release/SpinAddIn.dll
Binary file not shown.
Binary file modified TiaAddIn-Spin/obj/Release/SpinAddIn.dll
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ C:\Users\Jack\Documents\GitHub\TiaAddIn-Spin\TiaAddIn-Spin\obj\Release\TiaAddIn-
C:\Users\Paronetto g\Documents\GitHub\TiaAddIn-Spin\TiaAddIn-Spin\bin\Release\SpinAddIn.dll
C:\Users\Paronetto g\Documents\GitHub\TiaAddIn-Spin\TiaAddIn-Spin\obj\Release\TiaAddIn-Spin.csproj.CoreCompileInputs.cache
C:\Users\Paronetto g\Documents\GitHub\TiaAddIn-Spin\TiaAddIn-Spin\obj\Release\SpinAddIn.dll
C:\Users\PARONETTO G\Documents\GitHub\TiaAddIn-Spin\TiaAddIn-Spin\obj\Release\TiaAddIn-Spin.csproj.AssemblyReference.cache

0 comments on commit 69270ed

Please sign in to comment.