Beispiel #1
0
        private void BtnOk_Click(object sender, EventArgs e)
        {
            Enabled = false;
            IReadOnlyDictionary <string, List <string> > lockedFiles;

            do
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    lockedFiles    = m_viewModel.ExportNow(m_checkOpenForMe.Checked);
                    if (!lockedFiles.Any())
                    {
                        DialogResult = DialogResult.OK;
                        Close();
                        return;
                    }
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }

                var bldr = new StringBuilder(String.Format(LocalizationManager.GetString("DialogBoxes.ExportDlg.CouldNotExport",
                                                                                         "Export failed to write one or more files. Try closing any applications that have these files open, and then click {0}. Details:",
                                                                                         "Param is \"Retry\" button label."),
                                                           MessageBoxStrings.RetryButton));
                foreach (var key in lockedFiles.Keys)
                {
                    bldr.Append("\r\n\r\n");
                    bldr.AppendFormat(LocalizationManager.GetString("DialogBoxes.ExportDlg.CouldNotExportProblemExplanationLabel",
                                                                    "Error: {0}"), key);
                    if (lockedFiles[key].Count > 1 || !key.Contains(lockedFiles[key][0]))
                    {
                        bldr.Append("\r\n");
                        bldr.Append(LocalizationManager.GetString("DialogBoxes.ExportDlg.CouldNotExportProblemFilesLabel",
                                                                  "Files affected:"));
                        foreach (var file in lockedFiles[key])
                        {
                            bldr.Append("\r\n\t");
                            bldr.Append(file);
                        }
                    }
                }

                if (MessageBox.Show(bldr.ToString(), Text, MessageBoxButtons.RetryCancel) == DialogResult.Cancel)
                {
                    Enabled = true;
                    m_viewModel.OpenExportFileOrLocation();
                    return;
                }
            } while (true);
        }