コード例 #1
0
        // TODO: FOr colors, money usw.: only one range for all attributes
        private static void GetSettingsFromItems(ItemMapperSettings settings, IEnumerable <LostAndFoundIndexedItem> items)
        {
            var colorConverter = new ColorConverter();

            foreach (var item in items)
            {
                if (settings.OldestDate > item.DateOfIncident)
                {
                    settings.OldestDate = item.DateOfIncident;
                }
                if (settings.NewestDate < item.DateOfIncident)
                {
                    settings.OldestDate = item.DateOfIncident;
                }

                foreach (var attribute in item.Attributes)
                {
                    if (attribute is ColorValueAttribute)
                    {
                        var convertFromInvariantString = colorConverter.ConvertFromInvariantString(attribute.GetValue().ToString()) as Color?;
                        if (convertFromInvariantString == null)
                        {
                            continue;
                        }

                        var colorObject = convertFromInvariantString.Value;
                        var rgb         = new Rgb {
                            R = colorObject.R, G = colorObject.G, B = colorObject.B
                        };
                        var lab = rgb.To <Lab>();

                        IColorAttributeMapperSettings colorAttributeSettings;
                        if (settings.ColorAttributes.ContainsKey(attribute.ID))
                        {
                            colorAttributeSettings = settings.ColorAttributes[attribute.ID];
                        }
                        else
                        {
                            colorAttributeSettings = new ColorAttributeMapperSettings();
                            settings.ColorAttributes.Add(attribute.ID, colorAttributeSettings);
                        }

                        if (lab.L < colorAttributeSettings.LuminescenceSettings.MinValue)
                        {
                            colorAttributeSettings.LuminescenceSettings.MinValue = lab.L;
                        }
                        if (lab.L > colorAttributeSettings.LuminescenceSettings.MaxValue)
                        {
                            colorAttributeSettings.LuminescenceSettings.MaxValue = lab.L;
                        }
                        if (lab.A < colorAttributeSettings.ASettings.MinValue)
                        {
                            colorAttributeSettings.ASettings.MinValue = lab.A;
                        }
                        if (lab.A > colorAttributeSettings.ASettings.MaxValue)
                        {
                            colorAttributeSettings.ASettings.MaxValue = lab.A;
                        }
                        if (lab.B < colorAttributeSettings.BSettings.MinValue)
                        {
                            colorAttributeSettings.BSettings.MinValue = lab.B;
                        }
                        if (lab.B > colorAttributeSettings.BSettings.MaxValue)
                        {
                            colorAttributeSettings.BSettings.MaxValue = lab.B;
                        }

                        continue;
                    }

                    IAttributeMapperSettings attributeSettings;
                    if (settings.Attributes.ContainsKey(attribute.ID))
                    {
                        attributeSettings = settings.Attributes[attribute.ID];
                    }
                    else
                    {
                        attributeSettings = new AttributeMapperSettings();
                        settings.Attributes.Add(attribute.ID, attributeSettings);
                    }
                    attributeSettings.DataCount++;

                    var value = attribute.GetValue();

                    if (value is string)
                    {
                        continue;
                    }

                    var moneyValue = value as MoneyValue;
                    if (moneyValue != null)
                    {
                        if (Convert.ToDouble(moneyValue.Value) < attributeSettings.MinValue)
                        {
                            attributeSettings.MinValue = Convert.ToDouble(moneyValue.Value);
                        }
                        if (Convert.ToDouble(moneyValue.Value) > attributeSettings.MaxValue)
                        {
                            attributeSettings.MaxValue = Convert.ToDouble(moneyValue.Value);
                        }
                        continue;
                    }

                    var convertible = value as IConvertible;
                    if (convertible == null)
                    {
                        continue;
                    }

                    var doubleValue = convertible.ToDouble(CultureInfo.InvariantCulture);
                    if (doubleValue < attributeSettings.MinValue)
                    {
                        attributeSettings.MinValue = doubleValue;
                    }
                    if (doubleValue > attributeSettings.MaxValue)
                    {
                        attributeSettings.MaxValue = doubleValue;
                    }
                }
            }

            settings.DateRange = settings.NewestDate - settings.OldestDate;
        }
コード例 #2
0
 public ColorAttributeMapperSettings()
 {
     LuminescenceSettings = new AttributeMapperSettings();
     ASettings            = new AttributeMapperSettings();
     BSettings            = new AttributeMapperSettings();
 }