mirror of
https://github.com/Kopano-dev/kopano-ol-extension.git
synced 2023-10-10 13:37:40 +02:00
Fixed ownership issue in folder watching startup
This commit is contained in:
parent
026f537dae
commit
9e0603e22f
@ -29,5 +29,6 @@ namespace Acacia.Stubs
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
new IAddressBook Clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,5 +112,7 @@ namespace Acacia.Stubs
|
|||||||
// TODO: remove this. It's a quick hack to find the events associated with this folder for ZPushWatcher.
|
// TODO: remove this. It's a quick hack to find the events associated with this folder for ZPushWatcher.
|
||||||
// make event watching part of the folder instead
|
// make event watching part of the folder instead
|
||||||
ZPushFolder ZPush { get; set; }
|
ZPushFolder ZPush { get; set; }
|
||||||
|
|
||||||
|
IFolder Clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,17 @@ namespace Acacia.Stubs.OutlookWrappers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: it would be nice if this could return IAddressBook
|
||||||
|
public override IFolder Clone()
|
||||||
|
{
|
||||||
|
return new AddressBookWrapper(CloneComObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
IAddressBook IAddressBook.Clone()
|
||||||
|
{
|
||||||
|
return new AddressBookWrapper(CloneComObject());
|
||||||
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
foreach(dynamic item in _item.Items.RawEnum())
|
foreach(dynamic item in _item.Items.RawEnum())
|
||||||
|
@ -39,6 +39,22 @@ namespace Acacia.Stubs.OutlookWrappers
|
|||||||
base.DoRelease();
|
base.DoRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected NSOutlook.MAPIFolder CloneComObject()
|
||||||
|
{
|
||||||
|
using (ComRelease com = new ComRelease())
|
||||||
|
{
|
||||||
|
NSOutlook.Application app = com.Add(_item.Application);
|
||||||
|
NSOutlook.NameSpace session = com.Add(app.Session);
|
||||||
|
NSOutlook.MAPIFolder folder = session.GetFolderFromID(EntryID);
|
||||||
|
return folder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual public IFolder Clone()
|
||||||
|
{
|
||||||
|
return new FolderWrapper(CloneComObject());
|
||||||
|
}
|
||||||
|
|
||||||
internal NSOutlook.Folder RawItem { get { return _item; } }
|
internal NSOutlook.Folder RawItem { get { return _item; } }
|
||||||
|
|
||||||
protected override NSOutlook.PropertyAccessor GetPropertyAccessor()
|
protected override NSOutlook.PropertyAccessor GetPropertyAccessor()
|
||||||
|
@ -85,7 +85,7 @@ namespace Acacia.ZPush
|
|||||||
// Recurse the children
|
// Recurse the children
|
||||||
foreach (IFolder subfolder in _folder.SubFolders)
|
foreach (IFolder subfolder in _folder.SubFolders)
|
||||||
{
|
{
|
||||||
Tasks.Task(null, "WatchChild", () => WatchChild(subfolder));
|
Tasks.Task(null, "WatchChild", () => WatchChild(subfolder, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ namespace Acacia.ZPush
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logger.Instance.Debug(this, "Folder added in {0}: {1}", Name, folder.Name);
|
Logger.Instance.Debug(this, "Folder added in {0}: {1}", Name, folder.Name);
|
||||||
WatchChild(folder.Duplicate());
|
WatchChild(folder, false);
|
||||||
}
|
}
|
||||||
catch (System.Exception e) { Logger.Instance.Error(this, "Exception in SubFolders_FolderAdd: {0}: {1}", Name, e); }
|
catch (System.Exception e) { Logger.Instance.Error(this, "Exception in SubFolders_FolderAdd: {0}: {1}", Name, e); }
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ namespace Acacia.ZPush
|
|||||||
// Create it now
|
// Create it now
|
||||||
// This will send a discover notification if required, which is just as good as a change notification
|
// This will send a discover notification if required, which is just as good as a change notification
|
||||||
Logger.Instance.Debug(this, "Folder change on unreported folder in {0}: {1}, {2}, {3}", Name, folder.Name, folder.EntryID, folder.StoreDisplayName);
|
Logger.Instance.Debug(this, "Folder change on unreported folder in {0}: {1}, {2}, {3}", Name, folder.Name, folder.EntryID, folder.StoreDisplayName);
|
||||||
WatchChild(folder.Duplicate());
|
WatchChild(folder, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (System.Exception e) { Logger.Instance.Error(this, "Exception in SubFolders_FolderChange: {0}: {1}", Name, e); }
|
catch (System.Exception e) { Logger.Instance.Error(this, "Exception in SubFolders_FolderChange: {0}: {1}", Name, e); }
|
||||||
@ -259,7 +259,7 @@ namespace Acacia.ZPush
|
|||||||
/// Watches the child folder.
|
/// Watches the child folder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="child">The child folder. Ownership will be taken.</param>
|
/// <param name="child">The child folder. Ownership will be taken.</param>
|
||||||
private void WatchChild(IFolder child)
|
private void WatchChild(IFolder child, bool takeOwnership)
|
||||||
{
|
{
|
||||||
if (!_children.ContainsKey(child.EntryID))
|
if (!_children.ContainsKey(child.EntryID))
|
||||||
{
|
{
|
||||||
@ -267,9 +267,10 @@ namespace Acacia.ZPush
|
|||||||
{
|
{
|
||||||
Logger.Instance.Trace(this, "Registering child on {0}: {1}", this, child.FullFolderPath);
|
Logger.Instance.Trace(this, "Registering child on {0}: {1}", this, child.FullFolderPath);
|
||||||
|
|
||||||
// Make sure we register the entry id actually before registering any listerners.
|
// Make sure we register the entry id actually before registering any listeners.
|
||||||
// That will cause change notifications, which require the entryid to be registered.
|
// That will cause change notifications, which require the entryid to be registered.
|
||||||
ZPushFolder folder = new ZPushFolder(_watcher, this, child);
|
IFolder childEffective = takeOwnership ? child : child.Clone();
|
||||||
|
ZPushFolder folder = new ZPushFolder(_watcher, this, childEffective);
|
||||||
_children.Add(child.EntryID, folder);
|
_children.Add(child.EntryID, folder);
|
||||||
folder.Initialise();
|
folder.Initialise();
|
||||||
return;
|
return;
|
||||||
@ -280,8 +281,11 @@ namespace Acacia.ZPush
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (takeOwnership)
|
||||||
|
{
|
||||||
// Release the folder if not used
|
// Release the folder if not used
|
||||||
child.Dispose();
|
child.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user