From b952f46ff926279b0294e8e6e8f79959c3ef75ff Mon Sep 17 00:00:00 2001 From: Patrick Simpson Date: Tue, 7 Feb 2017 13:49:26 +0100 Subject: [PATCH] Cleaned up user property handling, to prevent leaking COM objects --- .../AcaciaZPushPlugin.csproj | 6 +- .../Features/GAB/GABHandler.cs | 23 +++--- .../AcaciaZPushPlugin/Stubs/IBase.cs | 4 +- .../{IUserProperty.cs => IComWrapper.cs} | 16 +--- .../AcaciaZPushPlugin/Stubs/IItem.cs | 18 ++++- .../OutlookWrappers/AppointmentItemWrapper.cs | 6 +- .../{DisposableWrapper.cs => ComWrapper.cs} | 6 +- .../OutlookWrappers/ContactItemWrapper.cs | 6 +- .../DistributionListWrapper.cs | 6 +- .../Stubs/OutlookWrappers/MailItemWrapper.cs | 6 +- .../Stubs/OutlookWrappers/NoteItemWrapper.cs | 5 +- .../OutlookWrappers/OutlookItemWrapper.cs | 57 ++++++++++++++ .../Stubs/OutlookWrappers/OutlookWrapper.cs | 2 +- .../OutlookWrappers/StorageItemWrapper.cs | 6 +- .../Stubs/OutlookWrappers/StoreWrapper.cs | 2 +- .../Stubs/OutlookWrappers/TaskItemWrapper.cs | 6 +- .../OutlookWrappers/UserPropertyWrapper.cs | 76 ------------------- .../ZPush/Connect/ZPushConnection.cs | 2 +- .../ZPush/ZPushLocalStore.cs | 2 +- 19 files changed, 118 insertions(+), 137 deletions(-) rename src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/{IUserProperty.cs => IComWrapper.cs} (77%) rename src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/{DisposableWrapper.cs => ComWrapper.cs} (91%) create mode 100644 src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookItemWrapper.cs delete mode 100644 src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/UserPropertyWrapper.cs diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj index c9058aa..64518df 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj @@ -279,6 +279,8 @@ + + @@ -310,7 +312,7 @@ - + UserControl @@ -396,7 +398,6 @@ - @@ -411,7 +412,6 @@ - Form diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/GABHandler.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/GABHandler.cs index a4edb4f..9562b9e 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/GABHandler.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/GABHandler.cs @@ -297,7 +297,7 @@ namespace Acacia.Features.GAB { using (IStorageItem index = GetIndexItem()) { - return index?.GetUserProperty(PROP_CURRENT_SEQUENCE)?.Value; + return index?.GetUserProperty(PROP_CURRENT_SEQUENCE); } } set @@ -306,7 +306,7 @@ namespace Acacia.Features.GAB { if (value != null) { - index.GetUserProperty(PROP_CURRENT_SEQUENCE, true).Value = value.Value; + index.SetUserProperty(PROP_CURRENT_SEQUENCE, value.Value); } else { @@ -353,7 +353,8 @@ namespace Acacia.Features.GAB { Logger.Instance.Trace(this, "Newest chunk: {0}", newestChunkIndex.Value); - if (!CurrentSequence.HasValue || CurrentSequence.Value != newestChunkIndex?.numberOfChunks) + int? currentSequence = CurrentSequence; + if (!currentSequence.HasValue || currentSequence.Value != newestChunkIndex?.numberOfChunks) { // Sequence has changed. Delete contacts Logger.Instance.Trace(this, "Rechunked, deleting contacts"); @@ -373,8 +374,8 @@ namespace Acacia.Features.GAB int numberOfChunks = newestChunkIndex.Value.numberOfChunks; using (IStorageItem index = GetIndexItem()) { - index.GetUserProperty(PROP_CURRENT_SEQUENCE, true).Value = numberOfChunks; - index.GetUserProperty(PROP_LAST_PROCESSED, true).Value = CreateChunkStateString(numberOfChunks); + index.SetUserProperty(PROP_CURRENT_SEQUENCE, numberOfChunks); + index.SetUserProperty(PROP_LAST_PROCESSED, CreateChunkStateString(numberOfChunks)); index.Save(); } } @@ -404,7 +405,7 @@ namespace Acacia.Features.GAB { if (item == null) return null; - string state = item.GetUserProperty(PROP_LAST_PROCESSED)?.Value; + string state = item.GetUserProperty(PROP_LAST_PROCESSED); if (string.IsNullOrEmpty(state)) return null; @@ -422,7 +423,7 @@ namespace Acacia.Features.GAB { using (IStorageItem item = GetIndexItem()) { - string state = item.GetUserProperty(PROP_LAST_PROCESSED)?.Value; + string state = item.GetUserProperty(PROP_LAST_PROCESSED); string[] parts; if (string.IsNullOrEmpty(state)) parts = new string[index.numberOfChunks]; @@ -436,7 +437,7 @@ namespace Acacia.Features.GAB parts[index.chunk] = partState; string combined = string.Join(";", parts); - item.GetUserProperty(PROP_LAST_PROCESSED, true).Value = combined; + item.SetUserProperty(PROP_LAST_PROCESSED, combined); item.Save(); } } @@ -623,9 +624,9 @@ namespace Acacia.Features.GAB private void SetItemStandard(IItem item, string id, Dictionary value, ChunkIndex index) { // Set the chunk data - item.GetUserProperty(PROP_SEQUENCE, true).Value = index.numberOfChunks; - item.GetUserProperty(PROP_CHUNK, true).Value = index.chunk; - item.GetUserProperty(PROP_GAB_ID, true).Value = id; + item.SetUserProperty(PROP_SEQUENCE, index.numberOfChunks); + item.SetUserProperty(PROP_CHUNK, index.chunk); + item.SetUserProperty(PROP_GAB_ID, id); } private void AddGroupMember(IDistributionList group, IItem item) diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IBase.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IBase.cs index 8cfa0a9..e41772f 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IBase.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IBase.cs @@ -22,7 +22,7 @@ using System.Threading.Tasks; namespace Acacia.Stubs { - public interface IBase : IDisposable + public interface IBase : IComWrapper { #region MAPI properties @@ -49,8 +49,6 @@ namespace Acacia.Stubs string StoreDisplayName { get; } void Delete(); - bool MustRelease { get; set; } - string ToString(); } } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IUserProperty.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IComWrapper.cs similarity index 77% rename from src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IUserProperty.cs rename to src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IComWrapper.cs index 44db833..dfb0514 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IUserProperty.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IComWrapper.cs @@ -1,4 +1,4 @@ -/// Copyright 2016 Kopano b.v. +/// Copyright 2017 Kopano b.v. /// /// This program is free software: you can redistribute it and/or modify /// it under the terms of the GNU Affero General Public License, version 3, @@ -13,7 +13,6 @@ /// along with this program.If not, see. /// /// Consult LICENSE file for details - using System; using System.Collections.Generic; using System.Linq; @@ -22,17 +21,8 @@ using System.Threading.Tasks; namespace Acacia.Stubs { - public interface IUserProperty + public interface IComWrapper : IDisposable { - #region Properties - - Type Value - { - get; - set; - } - - #endregion + bool MustRelease { get; set; } } - } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IItem.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IItem.cs index fea2a9a..30ed2a0 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IItem.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IItem.cs @@ -39,11 +39,21 @@ namespace Acacia.Stubs #region User properties /// - /// Retrieves the user property with the specified name. + /// Retrieves the item's user property with the specified name. /// - /// If true, the property is created if it does not exist. - /// If false, null is returned in this case - IUserProperty GetUserProperty(string name, bool create = false); + /// The property type. + /// The name of the property. + /// The property's value, if it exists. If it does not exist, the type's default value is returned. + /// A nullable type can be specified to return null if the property does not exist. + Type GetUserProperty(string name); + + /// + /// Sets the property. + /// + /// The property type + /// + /// + void SetUserProperty(string name, Type value); #endregion diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AppointmentItemWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AppointmentItemWrapper.cs index c50382f..7a3263e 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AppointmentItemWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AppointmentItemWrapper.cs @@ -24,7 +24,7 @@ using Acacia.Utils; namespace Acacia.Stubs.OutlookWrappers { - class AppointmentItemWrapper : OutlookWrapper, IAppointmentItem, IZPushItem + class AppointmentItemWrapper : OutlookItemWrapper, IAppointmentItem, IZPushItem { internal AppointmentItemWrapper(AppointmentItem item) @@ -79,9 +79,9 @@ namespace Acacia.Stubs.OutlookWrappers #region Methods - public IUserProperty GetUserProperty(string name, bool create = false) + protected override UserProperties GetUserProperties() { - return UserPropertyWrapper.Get(_item.UserProperties, name, create); + return _item.UserProperties; } public void Delete() { _item.Delete(); } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/DisposableWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ComWrapper.cs similarity index 91% rename from src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/DisposableWrapper.cs rename to src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ComWrapper.cs index ee2bded..e5b150e 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/DisposableWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ComWrapper.cs @@ -25,19 +25,19 @@ using System.Threading.Tasks; namespace Acacia.Stubs.OutlookWrappers { - public abstract class DisposableWrapper : IDisposable + public abstract class ComWrapper : IComWrapper { /// /// Creates a wrapper. /// - internal DisposableWrapper() + internal ComWrapper() { Interlocked.Increment(ref Statistics.CreatedWrappers); this._createdTrace = new System.Diagnostics.StackTrace(); } - ~DisposableWrapper() + ~ComWrapper() { Interlocked.Increment(ref Statistics.DeletedWrappers); if (!_isDisposed) diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ContactItemWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ContactItemWrapper.cs index 8b888ee..01db56f 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ContactItemWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ContactItemWrapper.cs @@ -24,7 +24,7 @@ using System.Threading.Tasks; namespace Acacia.Stubs.OutlookWrappers { - class ContactItemWrapper : OutlookWrapper, IContactItem + class ContactItemWrapper : OutlookItemWrapper, IContactItem { internal ContactItemWrapper(ContactItem item) : @@ -200,9 +200,9 @@ namespace Acacia.Stubs.OutlookWrappers public string StoreId { get { return _item.Parent?.Store?.StoreID; } } public string StoreDisplayName { get { return _item.Parent?.Store?.DisplayName; } } - public IUserProperty GetUserProperty(string name, bool create = false) + protected override UserProperties GetUserProperties() { - return UserPropertyWrapper.Get(_item.UserProperties, name, create); + return _item.UserProperties; } public void Delete() { _item.Delete(); } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/DistributionListWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/DistributionListWrapper.cs index b5b06cc..2754c93 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/DistributionListWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/DistributionListWrapper.cs @@ -24,7 +24,7 @@ using Acacia.Utils; namespace Acacia.Stubs.OutlookWrappers { - class DistributionListWrapper : OutlookWrapper, IDistributionList + class DistributionListWrapper : OutlookItemWrapper, IDistributionList { internal DistributionListWrapper(DistListItem item) : @@ -90,9 +90,9 @@ namespace Acacia.Stubs.OutlookWrappers #region Methods - public IUserProperty GetUserProperty(string name, bool create = false) + protected override UserProperties GetUserProperties() { - return UserPropertyWrapper.Get(_item.UserProperties, name, create); + return _item.UserProperties; } public void Delete() { _item.Delete(); } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/MailItemWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/MailItemWrapper.cs index 9af5487..10edd5e 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/MailItemWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/MailItemWrapper.cs @@ -24,7 +24,7 @@ using Acacia.Utils; namespace Acacia.Stubs.OutlookWrappers { - class MailItemWrapper : OutlookWrapper, IMailItem + class MailItemWrapper : OutlookItemWrapper, IMailItem { internal MailItemWrapper(MailItem item) : @@ -132,9 +132,9 @@ namespace Acacia.Stubs.OutlookWrappers #region Methods - public IUserProperty GetUserProperty(string name, bool create = false) + protected override UserProperties GetUserProperties() { - return UserPropertyWrapper.Get(_item.UserProperties, name, create); + return _item.UserProperties; } public void Delete() { _item.Delete(); } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/NoteItemWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/NoteItemWrapper.cs index a18f307..0b8a55a 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/NoteItemWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/NoteItemWrapper.cs @@ -24,7 +24,7 @@ using System.Threading.Tasks; namespace Acacia.Stubs.OutlookWrappers { - public class NoteItemWrapper : OutlookWrapper, INoteItem + public class NoteItemWrapper : OutlookItemWrapper, INoteItem { internal NoteItemWrapper(NoteItem item) : @@ -62,8 +62,9 @@ namespace Acacia.Stubs.OutlookWrappers #region Methods - public IUserProperty GetUserProperty(string name, bool create = false) + protected override UserProperties GetUserProperties() { + // Note item doesn't have user properties throw new NotSupportedException(); } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookItemWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookItemWrapper.cs new file mode 100644 index 0000000..683e28c --- /dev/null +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookItemWrapper.cs @@ -0,0 +1,57 @@ +using Acacia.Utils; +using Microsoft.Office.Interop.Outlook; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Acacia.Stubs.OutlookWrappers +{ + abstract public class OutlookItemWrapper : OutlookWrapper + { + public OutlookItemWrapper(ItemType item) + : + base(item) + { + } + + public Type GetUserProperty(string name) + { + using (ComRelease com = new ComRelease()) + { + UserProperties userProperties = com.Add(GetUserProperties()); + UserProperty prop = com.Add(userProperties.Find(name, true)); + if (prop == null) + return default(Type); + + if (typeof(Type).IsEnum) + return typeof(Type).GetEnumValues().GetValue(prop.Value); + return prop.Value; + } + } + + public void SetUserProperty(string name, Type value) + { + using (ComRelease com = new ComRelease()) + { + UserProperties userProperties = com.Add(GetUserProperties()); + UserProperty prop = com.Add(userProperties.Find(name, true)); + if (prop == null) + prop = userProperties.Add(name, Mapping.OutlookPropertyType()); + + if (typeof(Type).IsEnum) + { + int i = Array.FindIndex(typeof(Type).GetEnumNames(), n => n.Equals(value.ToString())); + prop.Value = typeof(Type).GetEnumValues().GetValue(i); + } + else + { + prop.Value = value; + } + } + } + + abstract protected UserProperties GetUserProperties(); + } +} diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs index 36e4bcf..86221aa 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs @@ -29,7 +29,7 @@ namespace Acacia.Stubs.OutlookWrappers /// /// Helper for Outlook wrapper implementations /// - abstract public class OutlookWrapper : DisposableWrapper + abstract public class OutlookWrapper : ComWrapper { #region Construction / Destruction diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StorageItemWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StorageItemWrapper.cs index adea510..c148bf1 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StorageItemWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StorageItemWrapper.cs @@ -24,7 +24,7 @@ using System.Threading.Tasks; namespace Acacia.Stubs.OutlookWrappers { - public class StorageItemWrapper : OutlookWrapper, IStorageItem + public class StorageItemWrapper : OutlookItemWrapper, IStorageItem { public StorageItemWrapper(StorageItem item) : @@ -62,9 +62,9 @@ namespace Acacia.Stubs.OutlookWrappers #region Methods - public IUserProperty GetUserProperty(string name, bool create = false) + protected override UserProperties GetUserProperties() { - return UserPropertyWrapper.Get(_item.UserProperties, name, create); + return _item.UserProperties; } public void Delete() { _item.Delete(); } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoreWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoreWrapper.cs index a4270f8..e17b4c4 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoreWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoreWrapper.cs @@ -24,7 +24,7 @@ using Acacia.Utils; namespace Acacia.Stubs.OutlookWrappers { - public class StoreWrapper : DisposableWrapper, IStore + public class StoreWrapper : ComWrapper, IStore { public static IStore Wrap(Store store) { diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/TaskItemWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/TaskItemWrapper.cs index bb16a93..cc05464 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/TaskItemWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/TaskItemWrapper.cs @@ -24,7 +24,7 @@ using System.Threading.Tasks; namespace Acacia.Stubs.OutlookWrappers { - public class TaskItemWrapper : OutlookWrapper, ITaskItem + public class TaskItemWrapper : OutlookItemWrapper, ITaskItem { internal TaskItemWrapper(TaskItem item) : @@ -62,9 +62,9 @@ namespace Acacia.Stubs.OutlookWrappers #region Methods - public IUserProperty GetUserProperty(string name, bool create = false) + protected override UserProperties GetUserProperties() { - throw new NotSupportedException(); + return _item.UserProperties; } public void Delete() { _item.Delete(); } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/UserPropertyWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/UserPropertyWrapper.cs deleted file mode 100644 index ed23ba2..0000000 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/UserPropertyWrapper.cs +++ /dev/null @@ -1,76 +0,0 @@ -/// Copyright 2016 Kopano b.v. -/// -/// This program is free software: you can redistribute it and/or modify -/// it under the terms of the GNU Affero General Public License, version 3, -/// as published by the Free Software Foundation. -/// -/// This program is distributed in the hope that it will be useful, -/// but WITHOUT ANY WARRANTY; without even the implied warranty of -/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the -/// GNU Affero General Public License for more details. -/// -/// You should have received a copy of the GNU Affero General Public License -/// along with this program.If not, see. -/// -/// Consult LICENSE file for details - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Office.Interop.Outlook; - -namespace Acacia.Stubs.OutlookWrappers -{ - class UserPropertyWrapper : IUserProperty - { - private readonly UserProperty _prop; - - private UserPropertyWrapper(UserProperty prop) - { - this._prop = prop; - } - - #region IUserProperty implementation - - public PropType Value - { - get - { - if (typeof(PropType).IsEnum) - return typeof(PropType).GetEnumValues().GetValue(_prop.Value); - return _prop.Value; - } - set - { - if (typeof(PropType).IsEnum) - { - int i = Array.FindIndex(typeof(PropType).GetEnumNames(), n => n.Equals(value.ToString())); - _prop.Value = typeof(PropType).GetEnumValues().GetValue(i); - } - else - _prop.Value = value; - } - } - - #endregion - - #region Helpers - - internal static IUserProperty Get(UserProperties userProperties, string name, bool create) - { - UserProperty prop = userProperties.Find(name, true); - if (prop == null) - { - if (!create) - return null; - prop = userProperties.Add(name, Mapping.OutlookPropertyType()); - } - - return new UserPropertyWrapper(prop); - } - - #endregion - } -} diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/Connect/ZPushConnection.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/Connect/ZPushConnection.cs index 4ea9fc8..57ce3a0 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/Connect/ZPushConnection.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/Connect/ZPushConnection.cs @@ -252,7 +252,7 @@ namespace Acacia.ZPush.Connect } } - private class Request : DisposableWrapper + private class Request : ComWrapper { private const string ACTIVESYNC_URL = "https://{0}/Microsoft-Server-ActiveSync?DeviceId={1}&Cmd={2}&User={3}&DeviceType={4}"; diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushLocalStore.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushLocalStore.cs index 39c7a3d..7674a63 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushLocalStore.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/ZPushLocalStore.cs @@ -31,7 +31,7 @@ namespace Acacia.ZPush /// Manages a local store in which Z-Push data is stored. /// /// TODO: merge with Store where possible - public class ZPushLocalStore : DisposableWrapper + public class ZPushLocalStore : ComWrapper { private Store _store;