Example #1
0
        public static OlCategoryColor FindMatchingCategoryColor(ArgbColor argbColor)
        {
            var color = Color.FromArgb(argbColor.ArgbValue);

            double          minDistance           = double.MaxValue;
            OlCategoryColor matchingCategoryColor = OlCategoryColor.olCategoryColorNone;

            foreach (var cat in CategoryColors)
            {
                Color catColor = Color.FromArgb(cat.Value.ArgbValue);

                var a = new Rgb {
                    R = color.R, G = color.G, B = color.B
                };
                var b = new Rgb {
                    R = catColor.R, G = catColor.G, B = catColor.B
                };

                double curDistance = a.Compare(b, new ColorMine.ColorSpaces.Comparisons.CieDe2000Comparison());

                if (curDistance < minDistance)
                {
                    minDistance           = curDistance;
                    matchingCategoryColor = cat.Key;
                }
            }

            return(matchingCategoryColor);
        }
        public CreateCategoryResult AddCategoryNoThrow(string name, OlCategoryColor color)
        {
            try
            {
                using (var categoriesWrapper = GenericComObjectWrapper.Create(_nameSpace.Categories))
                {
                    // Here a hashset has to be used with an case-insensitive comparer, because the indexer cannot be used to check if the
                    // category already exists, since it is case sensitive (but outlook requires case insensitive uniqueness)
                    var categoryNames = new HashSet <string>(
                        categoriesWrapper.Inner.ToSafeEnumerable <Category>().Select(c => c.Name),
                        CategoryNameComparer);

                    if (!categoryNames.Contains(name))
                    {
                        categoriesWrapper.Inner.Add(name, color);
                        return(CreateCategoryResult.Ok);
                    }
                    else
                    {
                        return(CreateCategoryResult.DidAlreadyExist);
                    }
                }
            }
            catch (System.Exception e)
            {
                s_logger.Error($"Can't create category '{name}' with color '{color}'", e);
                return(CreateCategoryResult.Error);
            }
        }
Example #3
0
    public static string GetColorName(OlCategoryColor color, Language language)
    {
        var englishColorName =
            outlookColor.Key.ToString().Remove(0, "olCategoryColor".Length);

        if (language == Language.English)
        {
            return(englishColorName);
        }
        else if (language == Language.Italian)
        {
            if (eng2ItalianColor.ContainsKey(englishColorName))
            {
                return(eng2ItalianColor[englishColorName]);
            }
            else
            {
                throw new ArgumentException(
                          "missing translation from english to italian for color: " + englishColorName);
            }
        }
        else
        {
            throw new ArgumentException("unsupported language: " + language);
        }
    }
Example #4
0
        /// <remarks>
        /// InitializeData has to set fields instead of properties, since properties can interfer with each other!
        /// </remarks>
        private void InitializeData(EventMappingConfiguration mappingConfiguration)
        {
            _categoryShortcutKey                          = mappingConfiguration.CategoryShortcutKey;
            _createEventsInUtc                            = mappingConfiguration.CreateEventsInUTC;
            _useIanaTz                                    = mappingConfiguration.UseIanaTz;
            _eventTz                                      = mappingConfiguration.EventTz;
            _includeHistoricalData                        = mappingConfiguration.IncludeHistoricalData;
            _useGlobalAppointmentId                       = mappingConfiguration.UseGlobalAppointmentID;
            _eventCategory                                = mappingConfiguration.EventCategory;
            _eventCategoryColor                           = mappingConfiguration.EventCategoryColor;
            _includeEmptyEventCategoryFilter              = mappingConfiguration.IncludeEmptyEventCategoryFilter;
            _invertEventCategoryFilter                    = mappingConfiguration.InvertEventCategoryFilter;
            _mapAttendees                                 = mappingConfiguration.MapAttendees;
            _mapBody                                      = mappingConfiguration.MapBody;
            _mapRtfBodyToXAltDesc                         = mappingConfiguration.MapRtfBodyToXAltDesc;
            _mapXAltDescToRtfBody                         = mappingConfiguration.MapXAltDescToRtfBody;
            _mapClassConfidentialToSensitivityPrivate     = mappingConfiguration.MapClassConfidentialToSensitivityPrivate;
            _mapClassPublicToSensitivityPrivate           = mappingConfiguration.MapClassPublicToSensitivityPrivate;
            _mapReminder                                  = mappingConfiguration.MapReminder;
            _mapSensitivityPrivateToClassConfidential     = mappingConfiguration.MapSensitivityPrivateToClassConfidential;
            _scheduleAgentClient                          = mappingConfiguration.ScheduleAgentClient;
            _sendNoAppointmentNotifications               = mappingConfiguration.SendNoAppointmentNotifications;
            _useEventCategoryColorAndMapFromCalendarColor = mappingConfiguration.UseEventCategoryColorAndMapFromCalendarColor;
            _cleanupDuplicateEvents                       = mappingConfiguration.CleanupDuplicateEvents;
            _mapCustomProperties                          = mappingConfiguration.MapCustomProperties;

            if (mappingConfiguration.UserDefinedCustomPropertyMappings != null)
            {
                Array.ForEach(mappingConfiguration.UserDefinedCustomPropertyMappings, m => Mappings.Add(new PropertyMappingModel(m)));
            }
        }
        public void AddOrUpdateCategoryNoThrow(string name, OlCategoryColor color, bool useColor, OlCategoryShortcutKey shortcutKey, bool useShortcutKey)
        {
            try
            {
                using (var categoriesWrapper = GenericComObjectWrapper.Create(_nameSpace.Categories))
                {
                    // Here a dictionary has to be used with an case-insensitive comparer, because the indexer cannot be used to fetch
                    // the category, since it is case sensitive (but outlook requires case insensitive uniqueness)
                    var caseSensitiveNameByCaseInsensitiveName = new Dictionary <string, string>();

                    foreach (var existingCategory in categoriesWrapper.Inner.ToSafeEnumerable <Category>())
                    {
                        // unassign shortcutKey from existing categories to make shortcut unique
                        if (useShortcutKey && existingCategory.ShortcutKey == shortcutKey)
                        {
                            existingCategory.ShortcutKey = OlCategoryShortcutKey.olCategoryShortcutKeyNone;
                        }

                        caseSensitiveNameByCaseInsensitiveName.Add(existingCategory.Name, existingCategory.Name);
                    }

                    if (caseSensitiveNameByCaseInsensitiveName.TryGetValue(name, out var caseSensitiveName))
                    {
                        using (var categoryWrapper = GenericComObjectWrapper.Create(categoriesWrapper.Inner[caseSensitiveName]))
                        {
                            if (useColor)
                            {
                                categoryWrapper.Inner.Color = color;
                            }
                            if (useShortcutKey)
                            {
                                categoryWrapper.Inner.ShortcutKey = shortcutKey;
                            }
                        }
                    }
                    else
                    {
                        categoriesWrapper.Inner.Add(
                            name,
                            useColor ? color : OlCategoryColor.olCategoryColorNone,
                            useShortcutKey ? shortcutKey : OlCategoryShortcutKey.olCategoryShortcutKeyNone);
                    }
                }
            }
            catch (System.Exception e)
            {
                s_logger.Error($"Can't update category '{name}' with color '{color}' and shortcut '{shortcutKey}'", e);
            }
        }
Example #6
0
        public static Outlook.OlCategoryColor GetOutlookColorFromRgb(string rgb)
        {
            if (!string.IsNullOrEmpty(rgb) && (rgb = rgb.Trim()).Length != 9)
            {
                return(OlCategoryColor.olCategoryColorNone);
            }

            string rStr = rgb.Substring(3, 2);
            string gStr = rgb.Substring(5, 2);
            string bStr = rgb.Substring(7, 2);

            int r;
            int g;
            int b;

            try
            {
                r = Int32.Parse(rStr, System.Globalization.NumberStyles.HexNumber);
                g = Int32.Parse(gStr, System.Globalization.NumberStyles.HexNumber);
                b = Int32.Parse(bStr, System.Globalization.NumberStyles.HexNumber);

                OlCategoryColor olColor = OlCategoryColor.olCategoryColorNone;

                //calculate nearest color with two algorithms
                double minDistance = double.MaxValue;
                foreach (var olColorRgb in OutlookColorsRgb)
                {
                    int rDiff = r - olColorRgb.Value.R;
                    int gDiff = g - olColorRgb.Value.G;
                    int bDiff = b - olColorRgb.Value.B;

                    //1. consider RGB as a three-dimensional space and get the nearest color
                    double curDistance = Math.Sqrt(rDiff * rDiff + gDiff * gDiff + bDiff * bDiff);
                    //2. count the total difference of color and choose the nearest one
                    curDistance += Math.Abs(rDiff) + Math.Abs(gDiff) + Math.Abs(bDiff);
                    if (curDistance < minDistance)
                    {
                        minDistance = curDistance;
                        olColor     = olColorRgb.Key;
                    }
                }

                return(olColor);
            }
            catch (System.Exception)
            {
                return(OlCategoryColor.olCategoryColorNone);
            }
        }
Example #7
0
        public void TestRoundtrip1To2(OlCategoryColor outlookColor)
        {
            var originalCategory = "cat1";

            _outlookCategories[originalCategory] = new OutlookCategory(originalCategory, outlookColor, OlCategoryShortcutKey.olCategoryShortcutKeyNone);
            CreateMapper();

            var htmlColor            = _mapper.MapCategoryToHtmlColorOrNull(originalCategory);
            var roundTrippedCategory = _mapper.MapHtmlColorToCategoryOrNull(htmlColor, NullEntityMappingLogger.Instance);

            Assert.That(roundTrippedCategory, Is.EqualTo(originalCategory));

            // try a second roundtrip
            htmlColor            = _mapper.MapCategoryToHtmlColorOrNull(originalCategory);
            roundTrippedCategory = _mapper.MapHtmlColorToCategoryOrNull(htmlColor, NullEntityMappingLogger.Instance);
            Assert.That(roundTrippedCategory, Is.EqualTo(originalCategory));
        }
        /// <remarks>
        /// InitializeData has to set fields instead of properties, since properties can interfer with each other!
        /// </remarks>
        private void InitializeData(EventMappingConfiguration mappingConfiguration)
        {
            _createEventsInUtc                        = mappingConfiguration.CreateEventsInUTC;
            _useIanaTz                                = mappingConfiguration.UseIanaTz;
            _eventTz                                  = mappingConfiguration.EventTz;
            _includeHistoricalData                    = mappingConfiguration.IncludeHistoricalData;
            _useGlobalAppointmentId                   = mappingConfiguration.UseGlobalAppointmentID;
            _eventCategory                            = mappingConfiguration.EventCategory;
            _includeEmptyEventCategoryFilter          = mappingConfiguration.IncludeEmptyEventCategoryFilter;
            _invertEventCategoryFilter                = mappingConfiguration.InvertEventCategoryFilter;
            _mapAttendees                             = mappingConfiguration.MapAttendees;
            _mapBody                                  = mappingConfiguration.MapBody;
            _mapRtfBodyToXAltDesc                     = mappingConfiguration.MapRtfBodyToXAltDesc;
            _mapXAltDescToRtfBody                     = mappingConfiguration.MapXAltDescToRtfBody;
            _mapClassConfidentialToSensitivityPrivate = mappingConfiguration.MapClassConfidentialToSensitivityPrivate;
            _mapClassPublicToSensitivityPrivate       = mappingConfiguration.MapClassPublicToSensitivityPrivate;
            _mapReminder                              = mappingConfiguration.MapReminder;
            _mapSensitivityPrivateToClassConfidential = mappingConfiguration.MapSensitivityPrivateToClassConfidential;
            _mapSensitivityPublicToDefault            = mappingConfiguration.MapSensitivityPublicToDefault;
            _scheduleAgentClient                      = mappingConfiguration.ScheduleAgentClient;
            _sendNoAppointmentNotifications           = mappingConfiguration.SendNoAppointmentNotifications;
            _organizerAsDelegate                      = mappingConfiguration.OrganizerAsDelegate;
            _cleanupDuplicateEvents                   = mappingConfiguration.CleanupDuplicateEvents;
            _mapEventColorToCategory                  = mappingConfiguration.MapEventColorToCategory;
            _mapCustomProperties                      = mappingConfiguration.MapCustomProperties;
            _isCategoryFilterSticky                   = mappingConfiguration.IsCategoryFilterSticky;
            _eventColorToCategoryMappings             = mappingConfiguration.EventColorToCategoryMappings;

            if (mappingConfiguration.UserDefinedCustomPropertyMappings != null)
            {
                Array.ForEach(mappingConfiguration.UserDefinedCustomPropertyMappings, m => Mappings.Add(new PropertyMappingModel(m)));
            }

            if (!string.IsNullOrEmpty(_eventCategory))
            {
                if (_sessionData.CategoriesById.TryGetValue(_eventCategory, out var category))
                {
                    _oneTimeSetCategoryShortcutKey = category.ShortcutKey;
                    _oneTimeSetEventCategoryColor  = category.Color;
                }
            }
        }
        void ComboboxColor_DrawItem(object sender, DrawItemEventArgs e)
        {
            ComboBox cbColour  = sender as ComboBox;
            int      indexItem = e.Index;

            if (indexItem < 0 || indexItem >= cbColour.Items.Count)
            {
                return;
            }

            KeyValuePair <OutlookOgcs.Categories.ColourInfo, String> kvp = (KeyValuePair <OutlookOgcs.Categories.ColourInfo, String>)cbColour.Items[indexItem];

            if (kvp.Key != null)
            {
                // Get the colour
                OlCategoryColor olColour = kvp.Key.OutlookCategory;
                Brush           brush    = new SolidBrush(OutlookOgcs.Categories.Map.RgbColour(olColour));

                DrawComboboxItemColour(cbColour, brush, kvp.Value, e);
            }
        }
 public CreateCategoryResult AddCategoryNoThrow(string name, OlCategoryColor color)
 {
     throw new System.NotImplementedException();
 }
 public void AddOrUpdateCategoryNoThrow(string name, OlCategoryColor color, bool useColor, OlCategoryShortcutKey shortcutKey, bool useShortcutKey)
 {
     throw new System.NotImplementedException();
 }
Example #12
0
        public void TestRoundtrip2To1WithNonStandardHtmlColorName(string originalhtmlColor, string expectedRoundTrippedHtmlColor, OlCategoryColor expectedOutlookColor)
        {
            var category = _mapper.MapHtmlColorToCategoryOrNull(originalhtmlColor, NullEntityMappingLogger.Instance);
            var roundTrippedHtmlColor = _mapper.MapCategoryToHtmlColorOrNull(category);

            Assert.That(roundTrippedHtmlColor, Is.EqualTo(expectedRoundTrippedHtmlColor));
            Assert.That(_outlookCategories[category].Color, Is.EqualTo(expectedOutlookColor));

            category = _mapper.MapHtmlColorToCategoryOrNull(originalhtmlColor, NullEntityMappingLogger.Instance);
            roundTrippedHtmlColor = _mapper.MapCategoryToHtmlColorOrNull(category);
            Assert.That(roundTrippedHtmlColor, Is.EqualTo(expectedRoundTrippedHtmlColor));
            Assert.That(_outlookCategories[category].Color, Is.EqualTo(expectedOutlookColor));
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AppointmentState"/> class.
 /// </summary>
 /// <param name="value">The value</param>
 /// <param name="name">The name</param>
 /// <param name="color">The color</param>
 private AppointmentState(int value, string name, OlCategoryColor color)
 {
     this.Name  = name;
     this.Value = value;
     this.Color = color;
 }
Example #14
0
        public (CreateCategoryResult Result, string ExistingColorNameForLoggingOrNull) AddCategoryNoThrow(string name, OlCategoryColor color)
        {
            try
            {
                using (var categoriesWrapper = GenericComObjectWrapper.Create(_nameSpace.Categories))
                {
                    // Here a dictionary has to be used with an case-insensitive comparer, because the indexer cannot be used to check if the
                    // category already exists, since it is case sensitive (but outlook requires case insensitive uniqueness)
                    var categoryColorByName = new Dictionary <string, OlCategoryColor>(StringComparer.InvariantCultureIgnoreCase);
                    foreach (var category in GetCategories())
                    {
                        // Use assignment via indexer to prevent exceptions if outlook retursn duplicate categories
                        categoryColorByName[category.Name] = category.Color;
                    }

                    if (!categoryColorByName.TryGetValue(name, out var existingColor))
                    {
                        categoriesWrapper.Inner.Add(name, color);
                        return(CreateCategoryResult.Ok, null);
                    }
                    else
                    {
                        return(CreateCategoryResult.DidAlreadyExist, existingColor.ToString());
                    }
                }
            }
            catch (System.Exception e)
            {
                s_logger.Error($"Can't create category '{name}' with color '{color}'", e);
                return(CreateCategoryResult.Error, null);
            }
        }
Example #15
0
 public CreateCategoryResult AddCategoryNoThrow(string name, OlCategoryColor color)
 {
     _parent._outlookCategories.Add(name, new OutlookCategory(name, color, OlCategoryShortcutKey.olCategoryShortcutKeyNone));
     return(CreateCategoryResult.Ok);
 }
Example #16
0
 public static string MapCategoryColorToHtmlColor(OlCategoryColor color)
 {
     return(HtmlColorByOutlookColor[color].Name);
 }
 public OutlookCategory(string name, OlCategoryColor color, OlCategoryShortcutKey shortcutKey)
 {
     Name        = name;
     Color       = color;
     ShortcutKey = shortcutKey;
 }
 public (CreateCategoryResult Result, string ExistingColorNameForLoggingOrNull) AddCategoryNoThrow(string name, OlCategoryColor color)
 {
     _parent._outlookCategories.Add(name, new OutlookCategory(name, color, OlCategoryShortcutKey.olCategoryShortcutKeyNone));
     return(CreateCategoryResult.Ok, null);
 }
 public ColorInfo (string text, Color color, OlCategoryColor key)
 {
   Text = text;
   Color = color;
   Key = key;
 }
 public ColourInfo(OlCategoryColor category, Color colour, String name = "")
 {
     this.Text            = string.IsNullOrEmpty(name) ? OutlookOgcs.Categories.FriendlyCategoryName(category) : name;
     this.Colour          = colour;
     this.OutlookCategory = category;
 }
 public ColorInfo(string text, Color color, OlCategoryColor key)
 {
     Text  = text;
     Color = color;
     Key   = key;
 }
 public (CreateCategoryResult Result, string ExistingColorNameForLoggingOrNull) AddCategoryNoThrow(string name, OlCategoryColor color)
 {
     throw new NotImplementedException();
 }