From 2a4d39f43acdc661a3bddb0ba871a49522ef02da Mon Sep 17 00:00:00 2001 From: Richard Murillo Date: Wed, 31 May 2017 10:51:28 -0700 Subject: [PATCH 1/2] Add R# annotations, use Lib const - Add JetBrains.Annotations for items - Argument checks use same const values as TFS lib --- src/Qwiq.Core/IdentityDescriptor.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Qwiq.Core/IdentityDescriptor.cs b/src/Qwiq.Core/IdentityDescriptor.cs index ec80dab0..9dffb184 100644 --- a/src/Qwiq.Core/IdentityDescriptor.cs +++ b/src/Qwiq.Core/IdentityDescriptor.cs @@ -1,11 +1,13 @@ using Microsoft.VisualStudio.Services.Identity; using System; +using JetBrains.Annotations; +using Microsoft.VisualStudio.Services.Common; namespace Microsoft.Qwiq { public class IdentityDescriptor : IIdentityDescriptor, IComparable, IEquatable { - private string _identifier; + [NotNull] private string _identifier; /// /// @@ -21,7 +23,7 @@ public class IdentityDescriptor : IIdentityDescriptor, IComparable - public IdentityDescriptor(string identityType, string identifier) + public IdentityDescriptor([NotNull] string identityType, [NotNull] string identifier) { IdentityType = identityType; Identifier = identifier; @@ -33,7 +35,7 @@ public string Identifier private set { if (string.IsNullOrEmpty(value)) throw new ArgumentNullException(nameof(value)); - if (value.Length > 256) throw new ArgumentOutOfRangeException(nameof(value)); + if (value.Length > IdentityConstants.MaxIdLength) throw new ArgumentOutOfRangeException(nameof(value)); _identifier = value; } } @@ -44,12 +46,12 @@ public string IdentityType private set { if (string.IsNullOrEmpty(value)) throw new ArgumentNullException(nameof(value)); - if (value.Length > 128) throw new ArgumentOutOfRangeException(nameof(value)); + if (value.Length > IdentityConstants.MaxTypeLength) throw new ArgumentOutOfRangeException(nameof(value)); IdentityTypeId = IdentityTypeMapper.Instance.GetTypeIdFromName(value); } } - protected internal byte IdentityTypeId { get; set; } + protected internal byte IdentityTypeId { get; private set; } public int CompareTo(IdentityDescriptor other) { From d873382a8a772cbfd795ffd280de4aacd171b9e7 Mon Sep 17 00:00:00 2001 From: Richard Murillo Date: Wed, 26 Jul 2017 10:44:39 -0700 Subject: [PATCH 2/2] Catch `DeniedOrNotExistException` when accessing field during map While mapping a `Microsoft.Qwiq.DeniedOrNotExistException` may be encountered while attempting to read a value from `IWorkItem` of a field that does not exist. This change captures the exception and throws an `AttributeMapException` indicating the work item ID, WIT field, and destination property that triggered the error. Resolves #150 --- .../Attributes/AttributeMapperStrategy.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Qwiq.Mapper/Attributes/AttributeMapperStrategy.cs b/src/Qwiq.Mapper/Attributes/AttributeMapperStrategy.cs index 3865be94..0d81cfe8 100644 --- a/src/Qwiq.Mapper/Attributes/AttributeMapperStrategy.cs +++ b/src/Qwiq.Mapper/Attributes/AttributeMapperStrategy.cs @@ -133,7 +133,18 @@ protected internal virtual void MapImpl(Type targetWorkItemType, IWorkItem sourc var fieldName = a.FieldName; var convert = a.RequireConversion; var nullSub = a.NullSubstitute; - var fieldValue = sourceWorkItem[fieldName]; + object fieldValue; + try + { + fieldValue = sourceWorkItem[fieldName]; + } + catch (DeniedOrNotExistException e) + { + var tm = new TypePair(sourceWorkItem, targetWorkItemType); + var pm = new PropertyMap(property, fieldName); + var message = $"Unable to get field value on {sourceWorkItem.Id}."; + throw new AttributeMapException(message, e, tm, pm); + } AssignFieldValue(targetWorkItemType, sourceWorkItem, targetWorkItem, property, fieldName, convert, nullSub, fieldValue); }