static void Main(string[] args) { try { MergeLog.Loginformation("Main - Start"); //Create Mutex object & its related varibale to avoid running multiple instances const string appName = "SingleCSVInstanceApp"; bool createdNew; mutex = new Mutex(true, appName, out createdNew); MergeLog.Loginformation("Mutex thread created."); if (!createdNew) { //Prompt the message to enduser and close the current instance MessageBox.Show("Application is already running."); MergeLog.Loginformation("Mutex thread identified already win form instance is running."); return; } //Identify the Windows form exe is launched with/without parameters if (args.Length > 0) { //Declare client object and which will create all required object at runtime BusinessClient businessClient = new BusinessClient(); //Read the saved selection of CSV files and destination paths MergeCSVData data = PackageConfig.ReadMergeCSVData(); //Validating saved tool configuration values if (string.IsNullOrEmpty(data.CSVFilePath1.Trim()) || string.IsNullOrEmpty(data.CSVFilePath2.Trim()) || string.IsNullOrEmpty(data.HeaderExists.Trim()) || string.IsNullOrEmpty(data.JsonFilePath.Trim())) { //Prompt the validation message to enduser and close the current instance MessageBox.Show("Invalid Configuration values. Please use UI execution.", "MergeCSVTool"); MergeLog.Loginformation("Invalid Configuration values."); return; } // Call the merge method businessClient.MergeCsvToJson(data); MessageBox.Show("Given CSV files are merged successfully.", "MergeCSVTool"); } else { //Open Merge win form Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MergeCSVToJson()); } MergeLog.Loginformation("Main - End"); } catch (Exception ex) { MergeLog.LogError(ex); MessageBox.Show(ex.Message, "MergeCSVTool"); } }
private void btnSaveConfig_Click(object sender, EventArgs e) { try { if (ValidateFields()) { DialogResult dialogResult = MessageBox.Show("You opted CSV files are " + (chkHeader.Checked ? "having " : "not having ") + " header. Are you sure you want to Save?", "Confirm to begin save", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (dialogResult == DialogResult.No) { return; } CollectAndSaveConfigDetails(); MergeLog.Loginformation("End user selection details are saved successfully."); MessageBox.Show("Form input details are saved successfully.", "MergeCSVTool"); } } catch (Exception ex) { MergeLog.LogError(ex); MessageBox.Show(ex.Message, "MergeCSVTool"); } }