Esempio n. 1
0
        /// <summary>
        /// Gets a property by its identifier
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static EveProperty GetPropertyById(int id)
        {
            EveProperty property = null;

            m_propertiesByID.TryGetValue(id, out property);
            return(property);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a property by its name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static EveProperty GetPropertyByName(string name)
        {
            EveProperty property = null;

            m_propertiesByName.TryGetValue(name, out property);
            return(property);
        }
Esempio n. 3
0
        /// <summary>
        /// Searches _properties for a property with the given property name and
        /// returns its value. If the property isn't found, it returns the given
        /// default value. If the property occurs more than once, only the first
        /// occurance is considered.
        /// </summary>
        /// <param name="property">The property name to look for.</param>
        /// <param name="defaultValue">The value to return if the property isn't found.</param>
        /// <returns>Either the value of the named property, or the given default value.</returns>
        private String FindProperty(EveProperty property, String defaultValue)
        {
            String result = defaultValue;

            foreach (EvePropertyValue prop in Properties)
            {
                if (prop.Property != property)
                {
                    continue;
                }

                result = prop.Value;
                break;
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a property from its name. If not found, return null.
        /// </summary>
        /// <param name="property">The property we're searching for.</param>
        /// <returns>The wanted property when found; null otherwise.</returns>
        public Nullable <EvePropertyValue> this[EveProperty property]
        {
            get
            {
                foreach (var prop in m_items)
                {
                    if (prop.Property == null)
                    {
                        return(null);
                    }

                    if (prop.Property == property)
                    {
                        return(prop);
                    }
                }
                return(null);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="serial"></param>
        internal EveProperty(EvePropertyCategory owner, SerializableProperty serial)
        {
            m_owner = owner;
            m_id = serial.ID;
            m_icon = serial.Icon;
            m_unit = serial.Unit;
            m_unitID = serial.UnitID;
            m_description = serial.Description;
            m_defaultValue = serial.DefaultValue;
            m_higherIsBetter = serial.HigherIsBetter;

            m_name = serial.Name;

            switch (m_id)
            {
                case DBConstants.CPUNeedPropertyID:
                    s_cpuProperty = this;
                    break;
                case DBConstants.PGNeedPropertyID:
                    s_powergridProperty = this;
                    break;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="serial"></param>
        internal EveProperty(EvePropertyCategory owner, SerializableProperty serial)
        {
            m_owner          = owner;
            m_id             = serial.ID;
            m_icon           = serial.Icon;
            m_unit           = serial.Unit;
            m_unitID         = serial.UnitID;
            m_description    = serial.Description;
            m_defaultValue   = serial.DefaultValue;
            m_higherIsBetter = serial.HigherIsBetter;

            m_name = serial.Name;

            switch (m_id)
            {
            case DBConstants.CPUNeedPropertyID:
                s_cpuProperty = this;
                break;

            case DBConstants.PGNeedPropertyID:
                s_powergridProperty = this;
                break;
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Deserialization constructor
 /// </summary>
 /// <param name="src"></param>
 internal EvePropertyValue(SerializablePropertyValue src)
 {
     m_property = StaticProperties.GetPropertyById(src.ID);
     m_value    = String.Intern(src.Value);
 }
        /// <summary>
        /// Adds the value for selected objects.
        /// </summary>
        /// <param name="prop">The evaluated EveProperty.</param>
        /// <param name="item">The list of items.</param>
        /// <param name="labels">The labels.</param>
        /// <param name="values">The values.</param>
        private void AddValueForSelectedObjects(EveProperty prop, ListViewItem item, IList<String> labels, IList<Double> values)
        {
            Double min = 0f;
            Double max = 0f;
            bool allEqual = true;

            if (values.Any())
            {
                min = values.Min();
                max = values.Max();
                allEqual = values.All(x => Math.Abs(x - min) < float.Epsilon);
                if (prop != null && !prop.HigherIsBetter)
                {
                    Double temp = min;
                    min = max;
                    max = temp;
                }
            }

            // Add the value for every selected item
            for (int index = 0; index < SelectControl.SelectedObjects.Count(); index++)
            {
                // Create the subitem and choose its forecolor
                ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(item, labels[index]);
                if (!allEqual)
                {
                    if (Math.Abs(values[index] - max) < float.Epsilon)
                        subItem.ForeColor = Color.DarkGreen;
                    else if (Math.Abs(values[index] - min) < float.Epsilon)
                        subItem.ForeColor = Color.DarkRed;

                    item.UseItemStyleForSubItems = false;
                }
                else if (SelectControl.SelectedObjects.Count() > 1)
                {
                    subItem.ForeColor = Color.DarkGray;
                    item.UseItemStyleForSubItems = false;
                }

                item.SubItems.Add(subItem);
            }
        }
        /// <summary>
        /// Adds the property value.
        /// </summary>
        /// <param name="items">The list of items.</param>
        /// <param name="group">The listGroup.</param>
        /// <param name="prop">The property.</param>
        private void AddPropertyValue(ICollection<ListViewItem> items, ListViewGroup group, EveProperty prop)
        {
            String[] labels = SelectControl.SelectedObjects.Select(prop.GetLabelOrDefault).ToArray();
            Double[] values = SelectControl.SelectedObjects.Select(prop.GetNumericValue).ToArray();

            // Create the list view item
            ListViewItem item = new ListViewItem(group) { ToolTipText = prop.Description, Text = prop.Name, Tag = prop };
            items.Add(item);

            AddValueForSelectedObjects(prop, item, labels, values);
        }
        /// <summary>
        /// Adds the list view item.
        /// </summary>
        /// <param name="prop">The prop.</param>
        /// <param name="items">The items.</param>
        /// <param name="group">The group.</param>
        /// <param name="item">The item.</param>
        /// <param name="materials">The materials.</param>
        private void AddListViewItem(EveProperty prop, ICollection<ListViewItem> items, ListViewGroup group, Item item,
            IEnumerable<Material> materials)
        {
            // Create the list of labels and values
            List<String> labels = new List<String>();
            List<Double> values = new List<Double>();
            foreach (Material material in materials)
            {
                // Add default labels and values for non existing materials
                if (material == null)
                {
                    labels.Add("0 ");
                    values.Add(0f);
                    continue;
                }

                labels.Add($"{material.Quantity:N0} {prop?.Unit}");
                values.Add(material.Quantity);
            }

            // Create the list view item
            ListViewItem lvItem = new ListViewItem(group)
            {
                ToolTipText = item.Description,
                Text = item.Name,
                Tag = item
            };
            items.Add(lvItem);

            AddValueForSelectedObjects(prop, lvItem, labels, values);
        }
        /// <summary>
        /// Adds the items and sub items.
        /// </summary>
        /// <param name="prop">The prop.</param>
        /// <param name="items">The items.</param>
        /// <param name="resourcesGroup">The resources group.</param>
        /// <param name="reactionMaterials">The reaction materials.</param>
        private void AddItemsAndSubItems(EveProperty prop, ICollection<ListViewItem> items, ListViewGroup resourcesGroup,
            IList<SerializableReactionInfo> reactionMaterials)
        {
            foreach (Item item in StaticItems.AllItems.OrderBy(x => x.ID))
            {
                if (reactionMaterials.All(x => x.ID != item.ID))
                    continue;

                // Create the list of materials we need to scroll through
                List<Material> materials = new List<Material>();
                foreach (Item obj in SelectControl.SelectedObjects)
                {
                    // Compensate for missing entries
                    if (!obj.ReactionMaterial.Any())
                    {
                        materials.Add(null);
                        continue;
                    }

                    materials.Add(obj.ReactionMaterial.Where(
                        x => x.ID == item.ID && reactionMaterials.Any(y => y == x)).Select(
                            x => new ReactionMaterial(x)).FirstOrDefault());
                }

                AddListViewItem(prop, items, resourcesGroup, item, materials);
            }

            PropertiesList.Groups.Add(resourcesGroup);
        }
Esempio n. 12
0
        /// <summary>
        /// Searches _properties for a property with the given property name and
        /// returns its value. If the property isn't found, it returns the given
        /// default value. If the property occurs more than once, only the first
        /// occurance is considered.
        /// </summary>
        /// <param name="property">The property name to look for.</param>
        /// <param name="defaultValue">The value to return if the property isn't found.</param>
        /// <returns>Either the value of the named property, or the given default value.</returns>
        private String FindProperty(EveProperty property, String defaultValue)
        {
            String result = defaultValue;
            foreach (EvePropertyValue prop in m_properties)
            {
                if (prop.Property != property)
                    continue;

                result = prop.Value;
                break;
            }
            return result;
        }