public Task <bool> TryDelete(
            string entityId,
            DateTime version,
            Tcontext context,
            IEntitySynchronizationLogger logger)
        {
            var entityWithId = Get(new[] { entityId }, NullLoadEntityLogger.Instance, default(Tcontext)).Result.SingleOrDefault();

            if (entityWithId == null)
            {
                return(Task.FromResult(true));
            }

            using (var contact = entityWithId.Entity)
            {
                if (!contact.Inner.Anniversary.Equals(OutlookUtility.OUTLOOK_DATE_NONE))
                {
                    try
                    {
                        Byte[] ba = contact.Inner.GetPropertySafe(PR_ASSOCIATED_ANNIVERSARY_APPOINTMENT_ID);
                        string anniversaryAppointmentItemID       = BitConverter.ToString(ba).Replace("-", string.Empty);
                        IAppointmentItemWrapper anniveraryWrapper = _comWrapperFactory.Create(_session.GetAppointmentItem(anniversaryAppointmentItemID),
                                                                                              entryId => _session.GetAppointmentItem(anniversaryAppointmentItemID));
                        anniveraryWrapper.Inner.Delete();
                    }
                    catch (COMException ex)
                    {
                        s_logger.Error("Could not delete associated Anniversary Appointment.", ex);
                        logger.LogError("Could not delete associated Anniversary Appointment.", ex);
                    }
                }

                if (!contact.Inner.Birthday.Equals(OutlookUtility.OUTLOOK_DATE_NONE))
                {
                    try
                    {
                        Byte[] ba = contact.Inner.GetPropertySafe(PR_ASSOCIATED_BIRTHDAY_APPOINTMENT_ID);
                        string birthdayAppointmentItemID        = BitConverter.ToString(ba).Replace("-", string.Empty);
                        IAppointmentItemWrapper birthdayWrapper = _comWrapperFactory.Create(_session.GetAppointmentItem(birthdayAppointmentItemID),
                                                                                            entryId => _session.GetAppointmentItem(birthdayAppointmentItemID));
                        birthdayWrapper.Inner.Delete();
                    }
                    catch (COMException ex)
                    {
                        s_logger.Error("Could not delete associated Birthday Appointment.", ex);
                        logger.LogError("Could not delete associated Birthday Appointment.", ex);
                    }
                }

                contact.Inner.Delete();
            }

            return(Task.FromResult(true));
        }
        public string MapHtmlColorToCategoryOrNull(string htmlColor, IEntitySynchronizationLogger logger)
        {
            var categoryColor = ColorMapper.MapHtmlColorToCategoryColor(htmlColor);

            if (_categoryByHtmlColor.TryGetValue(htmlColor, out var mapping))
            {
                var mappedCategory = mapping.PreferredCategory;

                if (_outlookColorByCategory.TryGetValue(mappedCategory, out var colorOfPreferredCategory))
                {
                    if (colorOfPreferredCategory == categoryColor)
                    {
                        return(mappedCategory);
                    }
                }
            }

            string category = null;

            foreach (var entry in _outlookColorByCategory)
            {
                if (entry.Value == categoryColor)
                {
                    category = entry.Key;
                    break;
                }
            }

            if (category == null)
            {
                // No category with the required color exists. Create one with the corresponding html color name.
                category = ColorMapper.MapCategoryColorToHtmlColor(categoryColor);
                var(addCategoryResult, existingColorNameOrNull) = _outlookSession.AddCategoryNoThrow(category, categoryColor);
                switch (addCategoryResult)
                {
                case CreateCategoryResult.DidAlreadyExist:
                    logger.LogWarning($"Did not map html color '{htmlColor}' to category '{category}', since category already exists with the wrong color ('{existingColorNameOrNull}').");
                    return(null);

                case CreateCategoryResult.Error:
                    logger.LogError($"Error while trying to create category '{category}'.");
                    return(null);

                case CreateCategoryResult.Ok:
                    _outlookColorByCategory.Add(category, categoryColor);
                    break;
                }
            }

            ColorCategoryMapping newMapping = new ColorCategoryMapping
            {
                HtmlColor         = htmlColor,
                PreferredCategory = category
            };

            _categoryByHtmlColor[htmlColor] = newMapping;
            _colorMappingsDataAccess.Save(_categoryByHtmlColor.Values);

            return(category);
        }