static void Main(string[] args) { foreach (string arg in args) { string file = arg; // Attempt to accomodate for relative or absolute directories if (file[0] != '/' && file[1] != ':') { file = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + file; } string filenameNoExt = file.Substring(0, file.LastIndexOf('.')); bool errorOccured = false; try { CogneroTest test = CogneroXMLReader.ParseFile(file); Test2Doc.CreateDocsFromTest(test, filenameNoExt); } catch (Exception ex) { Console.Error.WriteLine("\nFAILED TO CONVERT " + file + "\nEXCEPTION:\n" + ex.Message + "\n"); errorOccured = true; } finally { if (!errorOccured) { Console.WriteLine("CONVERT " + file + " OPERATION OK"); } } } }
void MainWindow_DragDrop(object sender, DragEventArgs e) { bool errorOccured = false; string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { string filenameNoExt = file.Substring(0, file.LastIndexOf('.')); try { CogneroTest test = CogneroXMLReader.ParseFile(file); Test2Doc.CreateDocsFromTest(test, filenameNoExt); } catch (Exception ex) { MessageBox.Show("Failed to convert " + file + " to docx. Ensure it is a well-formed XML file and you have R/W permissions for the folder.\n\nException:\n" + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); errorOccured = true; } } if (!errorOccured) { ShowNonBlockingMessageBox("Operation Succeeded", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { ShowNonBlockingMessageBox("Errors occured during operation. Some or all file conversions may have failed.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }