Files
ssh-access-tui/outlook-bulk-sender/BulkArchiveMailer.AddIn/RibbonController.cs
T
redlineoandClaude Sonnet 5 f50624023a Show full exception detail in error dialogs instead of just Message
An operator hit "Значение не может быть неопределенным. Имя параметра:
source" (ArgumentNullException, ParamName=source) opening the bulk
sender window on a real Outlook install. A full read-through of every
LINQ call reachable from that path found nothing that could receive a
null source, and this dev machine has no Outlook to reproduce against
- so the next occurrence needs a real stack trace to diagnose instead
of guessing from ex.Message alone.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-24 10:19:09 +03:00

96 lines
3.2 KiB
C#

using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using BulkArchiveMailer.AddIn.UI;
using BulkArchiveMailer.Core;
using Office = Microsoft.Office.Core;
namespace BulkArchiveMailer.AddIn
{
/// <summary>
/// Backs the single "Массовая рассылка" ribbon button declared in
/// Ribbon.xml (raw Ribbon XML + callbacks approach, not the Ribbon
/// Designer visual item - keeps everything in one small readable
/// file). Wired up via ThisAddIn.CreateRibbonExtensibilityObject().
/// </summary>
[System.Runtime.InteropServices.ComVisible(true)]
public class RibbonController : Office.IRibbonExtensibility
{
private Office.IRibbonUI ribbon;
public string GetCustomUI(string ribbonId)
{
return GetEmbeddedResourceText("BulkArchiveMailer.AddIn.Ribbon.xml");
}
public void Ribbon_Load(Office.IRibbonUI ribbonUi)
{
ribbon = ribbonUi;
}
/// <summary>
/// The button's onAction callback. Opens SettingsForm first if the
/// archive folder is not configured yet (or does not exist);
/// otherwise jumps straight to PreviewForm. Kept deliberately
/// simple - see README.md for the reasoning.
/// </summary>
public void OnOpenBulkSenderButtonClick(Office.IRibbonControl control)
{
try
{
var settings = AppSettings.Load();
var outlookApplication = Globals.ThisAddIn.OutlookApplication;
if (string.IsNullOrWhiteSpace(settings.ArchiveFolder) || !Directory.Exists(settings.ArchiveFolder))
{
using (var settingsForm = new SettingsForm(outlookApplication))
{
settingsForm.ShowDialog();
}
return;
}
using (var previewForm = new PreviewForm(outlookApplication))
{
previewForm.ShowDialog();
}
}
catch (Exception ex)
{
MessageBox.Show(
"Не удалось открыть окно массовой рассылки: " + ex.ToString(),
"BulkArchiveMailer",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private static string GetEmbeddedResourceText(string resourceName)
{
var asm = Assembly.GetExecutingAssembly();
foreach (var name in asm.GetManifestResourceNames())
{
if (string.Equals(name, resourceName, StringComparison.OrdinalIgnoreCase))
{
using (var stream = asm.GetManifestResourceStream(name))
{
if (stream == null)
{
return null;
}
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}
return null;
}
}
}