Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 31951f4

Browse files
committed
Merge pull request #40 from dclaux/Fixes
Bug fixes
2 parents 2f06138 + 66d9fd5 commit 31951f4

File tree

5 files changed

+58
-14
lines changed

5 files changed

+58
-14
lines changed

ComplexProperties/DictionaryProperty.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ internal void InternalRemove(TKey key)
218218
}
219219

220220
this.addedEntries.Remove(key);
221-
this.modifiedEntries.Remove (key);
221+
this.modifiedEntries.Remove(key);
222222
}
223223

224224
/// <summary>
@@ -525,4 +525,4 @@ bool ICustomUpdateSerializer.WriteDeleteUpdateToJson(ExchangeService service, Se
525525

526526
#endregion
527527
}
528-
}
528+
}

Core/EwsUtilities.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal static class EwsUtilities
7878
/// Dictionary of enum type to ExchangeVersion maps.
7979
/// </summary>
8080
private static LazyMember<Dictionary<Type, Dictionary<Enum, ExchangeVersion>>> enumVersionDictionaries = new LazyMember<Dictionary<Type, Dictionary<Enum, ExchangeVersion>>>(
81-
() => new Dictionary<Type, Dictionary<Enum, ExchangeVersion>>()
81+
() => new Dictionary<Type, Dictionary<Enum, ExchangeVersion>>()
8282
{
8383
{ typeof(WellKnownFolderName), BuildEnumDict(typeof(WellKnownFolderName)) },
8484
{ typeof(ItemTraversal), BuildEnumDict(typeof(ItemTraversal)) },
@@ -93,7 +93,7 @@ internal static class EwsUtilities
9393
/// Dictionary of enum type to schema-name-to-enum-value maps.
9494
/// </summary>
9595
private static LazyMember<Dictionary<Type, Dictionary<string, Enum>>> schemaToEnumDictionaries = new LazyMember<Dictionary<Type, Dictionary<string, Enum>>>(
96-
() => new Dictionary<Type, Dictionary<string, Enum>>
96+
() => new Dictionary<Type, Dictionary<string, Enum>>
9797
{
9898
{ typeof(EventType), BuildSchemaToEnumDict(typeof(EventType)) },
9999
{ typeof(MailboxType), BuildSchemaToEnumDict(typeof(MailboxType)) },
@@ -106,7 +106,7 @@ internal static class EwsUtilities
106106
/// Dictionary of enum type to enum-value-to-schema-name maps.
107107
/// </summary>
108108
private static LazyMember<Dictionary<Type, Dictionary<Enum, string>>> enumToSchemaDictionaries = new LazyMember<Dictionary<Type, Dictionary<Enum, string>>>(
109-
() => new Dictionary<Type, Dictionary<Enum, string>>
109+
() => new Dictionary<Type, Dictionary<Enum, string>>
110110
{
111111
{ typeof(EventType), BuildEnumToSchemaDict(typeof(EventType)) },
112112
{ typeof(MailboxType), BuildEnumToSchemaDict(typeof(MailboxType)) },
@@ -119,7 +119,7 @@ internal static class EwsUtilities
119119
/// Dictionary to map from special CLR type names to their "short" names.
120120
/// </summary>
121121
private static LazyMember<Dictionary<string, string>> typeNameToShortNameMap = new LazyMember<Dictionary<string, string>>(
122-
() => new Dictionary<string, string>
122+
() => new Dictionary<string, string>
123123
{
124124
{ "Boolean", "bool" },
125125
{ "Int16", "short" },
@@ -720,6 +720,30 @@ internal static T Parse<T>(string value)
720720
}
721721
}
722722

723+
/// <summary>
724+
/// Tries to parses the specified value to the specified type.
725+
/// </summary>
726+
/// <typeparam name="T">The type into which to cast the provided value.</typeparam>
727+
/// <param name="value">The value to parse.</param>
728+
/// <param name="result">The value cast to the specified type, if TryParse succeeds. Otherwise, the value of result is indeterminate.</param>
729+
/// <returns>True if value could be parsed; otherwise, false.</returns>
730+
internal static bool TryParse<T>(string value, out T result)
731+
{
732+
try
733+
{
734+
result = EwsUtilities.Parse<T>(value);
735+
736+
return true;
737+
}
738+
//// Catch all exceptions here, we're not interested in the reason why TryParse failed.
739+
catch (Exception)
740+
{
741+
result = default(T);
742+
743+
return false;
744+
}
745+
}
746+
723747
/// <summary>
724748
/// Converts the specified date and time from one time zone to another.
725749
/// </summary>

Core/ServiceObjects/Folders/Folder.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,12 +663,33 @@ public ArchiveTag ArchiveTag
663663
}
664664

665665
/// <summary>
666-
/// Gets the name of the well known folder.
666+
/// Gets the well known name of this folder, if any, as a string.
667667
/// </summary>
668-
/// <value>The name of the well known folder.</value>
668+
/// <value>The well known name of this folder as a string, or null if this folder isn't a well known folder.</value>
669+
public string WellKnownFolderNameAsString
670+
{
671+
get { return (string)this.PropertyBag[FolderSchema.WellKnownFolderName]; }
672+
}
673+
674+
/// <summary>
675+
/// Gets the well known name of this folder, if any.
676+
/// </summary>
677+
/// <value>The well known name of this folder, or null if this folder isn't a well known folder.</value>
669678
public WellKnownFolderName? WellKnownFolderName
670679
{
671-
get { return (WellKnownFolderName?)this.PropertyBag[FolderSchema.WellKnownFolderName]; }
680+
get
681+
{
682+
WellKnownFolderName result;
683+
684+
if (EwsUtilities.TryParse<WellKnownFolderName>(this.WellKnownFolderNameAsString, out result))
685+
{
686+
return result;
687+
}
688+
else
689+
{
690+
return null;
691+
}
692+
}
672693
}
673694

674695
#endregion

Core/ServiceObjects/Schemas/FolderSchema.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,11 @@ private static class FieldUris
171171
/// </summary>
172172
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Immutable type")]
173173
public static readonly PropertyDefinition WellKnownFolderName =
174-
new GenericPropertyDefinition<WellKnownFolderName>(
174+
new StringPropertyDefinition(
175175
XmlElementNames.DistinguishedFolderId,
176176
FieldUris.DistinguishedFolderId,
177177
PropertyDefinitionFlags.CanSet | PropertyDefinitionFlags.CanFind,
178-
ExchangeVersion.Exchange2013,
179-
true);
178+
ExchangeVersion.Exchange2013);
180179

181180
/// <summary>
182181
/// Defines the PolicyTag property.

Notifications/StreamingSubscriptionConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,12 @@ public void Close()
262262
/// <param name="ex">The exception that caused the disconnection. May be null.</param>
263263
private void InternalOnDisconnect(Exception ex)
264264
{
265+
this.currentHangingRequest = null;
266+
265267
if (this.OnDisconnect != null)
266268
{
267269
this.OnDisconnect(this, new SubscriptionErrorEventArgs(null, ex));
268270
}
269-
270-
this.currentHangingRequest = null;
271271
}
272272

273273
/// <summary>

0 commit comments

Comments
 (0)