- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现 Adrian Brown 非常好的 Outlook Add-In code 3 次中有 2 次有效。 ItemAdd
和 ItemChange
事件按预期触发,但 MAPIFolderEvents_12_Event.BeforeItemMove
的事件处理程序似乎没有做任何事情 - 我没有甚至在事件处理程序的第一行命中断点。
这是 CalendarMonitor 类;它监视文件夹的 Items 集合上的 ItemAdd、ItemChange 事件,以及 MAPIFolder 上的 BeforeItemMove:
public class CalendarMonitor
{
private Explorer _explorer;
private List<string> _folderPaths;
private List<MAPIFolder> _calendarFolders;
private List<Items> _calendarItems;
private MAPIFolder _deletedItemsFolder;
public event EventHandler<EventArgs<AppointmentItem>> AppointmentAdded;
public event EventHandler<EventArgs<AppointmentItem>> AppointmentModified;
public event EventHandler<CancelEventArgs<AppointmentItem>> AppointmentDeleting;
public CalendarMonitor(Explorer explorer)
{
_folderPaths = new List<string>();
_calendarFolders = new List<MAPIFolder>();
_calendarItems = new List<Items>();
_explorer = explorer;
_explorer.BeforeFolderSwitch += Explorer_BeforeFolderSwitch;
var session = _explorer.Session;
try
{
_deletedItemsFolder = session.GetDefaultFolder(OlDefaultFolders.olFolderDeletedItems);
HookupDefaultCalendarEvents(session);
}
finally
{
Marshal.ReleaseComObject(session);
session = null;
}
}
private void HookupDefaultCalendarEvents(_NameSpace session)
{
var folder = session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
if (folder == null) return;
try
{
HookupCalendarEvents(folder);
}
finally
{
Marshal.ReleaseComObject(folder);
folder = null;
}
}
private void Explorer_BeforeFolderSwitch(object obj, ref bool cancel)
{
var folder = (obj as MAPIFolder);
if (folder == null) return;
try
{
// Hookup events to any other Calendar folder opened.
if (folder.DefaultItemType == OlItemType.olAppointmentItem)
HookupCalendarEvents(folder);
}
finally
{
Marshal.ReleaseComObject(folder);
folder = null;
}
}
private void HookupCalendarEvents(MAPIFolder calendarFolder)
{
if (calendarFolder.DefaultItemType != OlItemType.olAppointmentItem)
{
throw new ArgumentException("The MAPIFolder must use AppointmentItems as the default type.");
}
// Ignore other user's calendars.
if (_folderPaths.Contains(calendarFolder.FolderPath) || (!IsUsersCalendar(calendarFolder))) return;
var items = calendarFolder.Items;
// Store folder path to prevent repeating listeners
_folderPaths.Add(calendarFolder.FolderPath);
// Store a reference to the folder & items to prevent garbage collection
_calendarFolders.Add(calendarFolder);
_calendarItems.Add(items);
// Add listeners
((MAPIFolderEvents_12_Event)calendarFolder).BeforeItemMove += Calendar_BeforeItemMove;
items.ItemChange += CalendarItems_ItemChange;
items.ItemAdd += CalendarItems_ItemAdd;
}
private void CalendarItems_ItemAdd(object obj)
{
var appointment = (obj as AppointmentItem);
if (appointment == null) return;
try
{
if (AppointmentAdded != null)
AppointmentAdded(this, new EventArgs<AppointmentItem>(appointment));
}
finally
{
Marshal.ReleaseComObject(appointment);
appointment = null;
}
}
private void CalendarItems_ItemChange(object obj)
{
var appointment = (obj as AppointmentItem);
if (appointment == null) return;
try
{
if (AppointmentModified != null)
AppointmentModified(this, new EventArgs<AppointmentItem>(appointment));
}
finally
{
Marshal.ReleaseComObject(appointment);
appointment = null;
}
}
private void Calendar_BeforeItemMove(object obj, MAPIFolder moveToFolder, ref bool cancel)
{
if ((moveToFolder != null) && (!IsDeletedItemsFolder(moveToFolder))) return;
var appointment = (obj as AppointmentItem);
if (appointment == null) return;
try
{
if (AppointmentDeleting == null) return;
// Listeners to the AppointmentDeleting event can cancel the move operation if moving
// to the deleted items folder.
var args = new CancelEventArgs<AppointmentItem>(appointment);
AppointmentDeleting(this, args);
cancel = args.Cancel;
}
finally
{
Marshal.ReleaseComObject(appointment);
appointment = null;
}
}
private bool IsUsersCalendar(MAPIFolder folder)
{
// This is based purely on my observations so far - a better way?
return (folder.Store != null);
}
private bool IsDeletedItemsFolder(MAPIFolder folder)
{
return (folder.EntryID == _deletedItemsFolder.EntryID);
}
public AppointmentItem Item { get; set; }
}
我已经完成了一些额外的“故障排除”并提供了更多信息:一时兴起,我在 Outlook 中创建了一个新日历(在调试时),你看 BeforeItemMove
事件就像我希望在删除新日历中的约会时可以,但它在原来的日历中仍然不起作用。
如果我退出调试 session 并重新启动,日历的事件都不会按预期运行,尽管之前工作正常。任何新日历的 BeforeItemMove
事件都可以正常工作,直到我关闭 Outlook - 然后它又回到无响应状态。
我希望这些额外的信息能为比我聪明的人提供见解。非常感谢任何帮助。
最佳答案
calFolder 变量必须在全局/类级别声明以避免被垃圾收集器释放。
关于c# - Outlook 2013 和 Outlook 加载项::MAPIFolder Events_12_Event.BeforeReMove 未触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32419177/
我已经开始学习 Backbone.js。目前我的 JavaScript 技能不太好。我开始检查 backbone.js 文件,发现一行奇怪的代码,我无法弄清楚其用途。代码示例(如果您需要更多上下文,请
正在搜索 backbone我看到它被使用了 12 次并且总是附加到 Backbone.Events 中的 this。 它仅仅是 Backbone.Events 的一个属性吗?如果是这样,为什么它有下划
我正在将插件从Grails 2.4迁移到Grails3。我正面临以下问题。 我试图在eventCreateWarStart中使用_Events.groovy。就像我们以前在插件的_Events.gro
我想检查一个变量 e是 threading.Event 的一个实例.但是,当我创建 e ,它实际上创建了一个 protected 类实例threading._Event .例如: import thr
我想将外部目录作为资源映射到部署在 tomcat 7 上的应用程序。 我已经通过这里的线程并尝试了几种方法: 我添加了 _Events.groovy,它在我的开发机器 (windows 7) 上工作得
在 Grails 2.3.7我正在使用 _Events.groovy钩入WAR打包做一些特殊处理: _Events.groovy import demo.utils.XmlUtil e
当尝试使用kivy-module时,我得到以下提示: [INFO ] [Logger ] Record log in /home/paul/.kivy/logs/kivy_22-01-0
当尝试使用kivy-module时,我得到以下提示: [INFO ] [Logger ] Record log in /home/paul/.kivy/logs/kivy_22-01-0
我是一名优秀的程序员,十分优秀!