示例#1
0
        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");
            }
        }
示例#2
0
        private void MergeCSVToJson_Load(object sender, EventArgs e)
        {
            openCSVFileDlg.Filter   = "CSV files (*.csv)|*.csv";
            openCSVFileDlg.FileName = "";

            MergeCSVData data = PackageConfig.ReadMergeCSVData();

            txtCSVFilePath1.Text   = data.CSVFilePath1;
            txtCSVFilePath2.Text   = data.CSVFilePath2;
            txtJsonFolderPath.Text = data.JsonFilePath;
            chkHeader.Checked      = (data.HeaderExists == string.Empty) ? false : Convert.ToBoolean(data.HeaderExists);
        }