// Callback that fires when execution completes.
        private void backgroundWorker1_RunWorkerCompleted(object sender,
                                                          RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                Debug.WriteLine("CANCELED");
                DialogResult = DialogResult.Cancel;
            }
            else if (e.Error != null)
            {
                // Unexpected -- shell command execution shouldn't throw exceptions.
                MessageBox.Show(this, e.Error.ToString(), Properties.Resources.OPERATION_FAILED,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                DialogResult = DialogResult.Cancel;
            }
            else
            {
                // Make results available in properties.
                Results = e.Result as AssemblerResults;
                Debug.WriteLine("Asm complete, exit=" + Results.ExitCode);
                DialogResult = DialogResult.OK;
            }

            // Whatever the case, we're done.
            this.Close();
        }
        // NOTE: executes on work thread.  DO NOT do any UI work here.  DO NOT access
        // the Results property directly.
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            AssemblerResults results = mAssembler.RunAssembler(worker);

            if (worker.CancellationPending)
            {
                e.Cancel = true;
            }
            else
            {
                e.Result = results;
            }
        }
Esempio n. 3
0
        private void runAssemblerButton_Click(object sender, EventArgs e)
        {
            IAssembler asm = AssemblerInfo.GetAssembler(mSelectedAssemblerId);

            if (asm == null)
            {
                Debug.WriteLine("Unable to get assembler for " + mSelectedAssemblerId);
                return;
            }

            asm.Configure(mGenerationResults, mWorkDirectory);
            AssemblerProgress dlg = new AssemblerProgress(asm);

            dlg.ShowDialog();
            Debug.WriteLine("Dialog returned: " + dlg.DialogResult);
            if (dlg.DialogResult != DialogResult.OK)
            {
                // Cancelled, or failed to even run the assembler.
                return;
            }

            AssemblerResults results = dlg.Results;

            if (results == null)
            {
                Debug.WriteLine("Dialog returned OK, but no assembler results found");
                Debug.Assert(false);
                return;
            }

            StringBuilder sb =
                new StringBuilder(results.Stdout.Length + results.Stderr.Length + 200);

            sb.Append(results.CommandLine);
            sb.Append("\r\n");
            sb.AppendFormat("ExitCode={0} - ", results.ExitCode);
            if (results.ExitCode == 0)
            {
                FileInfo fi = new FileInfo(results.OutputPathName);
                if (!fi.Exists)
                {
                    MessageBox.Show(this, Properties.Resources.ASM_OUTPUT_NOT_FOUND,
                                    Properties.Resources.ASM_MISMATCH_CAPTION,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    sb.Append(Properties.Resources.ASM_MATCH_FAILURE);
                }
                else if (!CommonUtil.FileUtil.CompareBinaryFile(mProject.FileData,
                                                                results.OutputPathName, out int offset, out byte fileVal))
                {
                    if (fi.Length != mProject.FileData.Length &&
                        offset == fi.Length || offset == mProject.FileData.Length)
                    {
                        // The files matched up to the point where one ended.
                        string msg = string.Format(Properties.Resources.ASM_MISMATCH_LENGTH_FMT,
                                                   fi.Length, mProject.FileData.Length);
                        MessageBox.Show(this, msg, Properties.Resources.ASM_MISMATCH_CAPTION,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        sb.Append(msg);
                    }
                    else
                    {
                        string msg = string.Format(Properties.Resources.ASM_MISMATCH_DATA_FMT,
                                                   offset, fileVal, mProject.FileData[offset]);
                        MessageBox.Show(this, msg, Properties.Resources.ASM_MISMATCH_CAPTION,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        sb.Append(msg);
                    }
                }
                else
                {
                    sb.Append(Properties.Resources.ASM_MATCH_SUCCESS);
                }
            }