private bool SaveNewScript(string scriptFilePath, SaveNewScriptType saveNewScriptType)
        {
            bool success = false;

            string scriptTemplateFileName = null;

            if (saveNewScriptType == SaveNewScriptType.TaskScript)
            {
                scriptTemplateFileName = TEMPLATE_TASK_SCRIPT_FILENAME;
            }
            else if (saveNewScriptType == SaveNewScriptType.PreProcessingScript)
            {
                scriptTemplateFileName = TEMPLATE_PREPROCESSING_SCRIPT_FILENAME;
            }
            else if (saveNewScriptType == SaveNewScriptType.PostProcessingScript)
            {
                scriptTemplateFileName = TEMPLATE_POSTPROCESSING_SCRIPT_FILENAME;
            }

            var scriptTemplateFilePath = Path.Combine(BatchRvt.GetBatchRvtScriptsFolderPath(), scriptTemplateFileName);

            var scriptContents = File.ReadAllText(scriptTemplateFilePath);

            try
            {
                File.WriteAllText(scriptFilePath, scriptContents);
                success = true;
            }
            catch (Exception e)
            {
                success = false;
            }

            return(success);
        }
        private void readBatchRvtOutput_Timer_Tick(object sender, EventArgs e)
        {
            var linesAndPendingTask = StreamIOUtil.ReadAvailableLines(this.batchRvtProcess.StandardOutput, this.pendingOutputReadLineTask);

            this.pendingOutputReadLineTask = linesAndPendingTask.Item2;
            var lines = linesAndPendingTask.Item1;

            foreach (var line in lines)
            {
                var fullLine = line + Environment.NewLine;

                if (!BatchRvt.IsBatchRvtLine(line))
                {
                    var timestamp = DateTime.Now.ToString("HH:mm:ss");

                    fullLine = timestamp + " : [ REVIT MESSAGE ] : " + fullLine;
                }

                if (BatchRvt.IsBatchRvtLine(line)) // Do not show non-BatchRvt-related output. (TODO: reconsider?)
                {
                    this.batchRvtOutputTextBox.AppendText(fullLine);
                }
            }

            linesAndPendingTask           = StreamIOUtil.ReadAvailableLines(this.batchRvtProcess.StandardError, this.pendingErrorReadLineTask);
            this.pendingErrorReadLineTask = linesAndPendingTask.Item2;
            lines = linesAndPendingTask.Item1;

            foreach (var line in lines)
            {
                if (line.StartsWith("log4cplus:")) // ignore pesky log4cplus messages (an Autodesk thing?)
                {
                    continue;
                }

                this.batchRvtOutputTextBox.AppendText("[ REVIT ERROR MESSAGE ] : " + line + Environment.NewLine);
            }

            if (isBatchRvtRunning)
            {
                this.batchRvtProcess.Refresh();
                if (this.batchRvtProcess.HasExited)
                {
                    this.isBatchRvtRunning = false;
                    this.startButton.Text  = "Done!";
                }
            }
        }
        private void startButton_Click(object sender, EventArgs e)
        {
            this.UIConfiguration.UpdateConfig();

            bool validated = ValidateConfig();

            if (validated)
            {
                bool isSaved = SaveSettings();

                // TODO: show error message if save failed!!

                var settingsFilePath = BatchRvtSettings.GetDefaultSettingsFilePath();

                this.batchRvtProcess = BatchRvt.StartBatchRvt(settingsFilePath);

                this.readBatchRvtOutput_Timer = new Timer()
                {
                    Interval = READ_OUTPUT_INTERVAL_IN_MS
                };
                this.readBatchRvtOutput_Timer.Tick += readBatchRvtOutput_Timer_Tick;

                this.isBatchRvtRunning              = true;
                this.settingsGroupBox.Enabled       = false;
                this.importSettingsButton.Enabled   = false;
                this.startButton.Enabled            = false;
                this.startButton.Text               = "Running...";
                this.batchRvtOutputGroupBox.Visible = true;
                this.MinimumSize = RUNNING_MINIMUM_SIZE;
                this.MaximumSize = RUNNING_MAXIMUM_SIZE;
                this.Size        = RUNNING_INITIAL_SIZE;
                this.MaximizeBox = true;

                UpdateAdvancedSettings();

                AdjustWindowSizeForDisplaySetting();

                readBatchRvtOutput_Timer.Start();
            }
        }