Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            ACondition other = obj as ACondition;

            if (other == null)
            {
                throw new ArgumentException();
            }

            var val      = GetValue();
            var valOther = other.GetValue();

            bool equal = Id.Equals(other.Id) && Assignment.Equals(other.Assignment);

            if (val != null)
            {
                equal &= val.Equals(valOther);
            }

            return(equal);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set condition by proxy.
        /// </summary>
        /// <param name="mappingSettings">Format.MappingSettings needed by proxy for creation of condition</param>
        /// <param name="number">Number of condition</param>
        /// <param name="proxy">ConditionProxy or null to reset condition.</param>
        /// <returns>True if condition was changed.</returns>
        internal bool SetCondition(Format.MappingSettings mappingSettings, ConditionNumber number, ConditionProxy proxy)
        {
            ACondition condition = (proxy != null) ? proxy.Create(mappingSettings, number) : null;

            if (condition != null)
            {
                condition.Assignment = condition.AssignmentOptions.Keys.First();
                condition.SetValue(condition.GetValueOptions().Keys.First());
            }
            return(setCondition(number, condition));
        }
Ejemplo n.º 3
0
        public void Swap()
        {
            Format.MappingSettings rawSettings = (Condition1 != null) ? Condition1.RawSettings : (Condition2 != null) ? Condition2.RawSettings : null;
            if (rawSettings == null)
            {
                return;
            }

            ACondition swap = (Condition1 == null) ? null : Condition1.Copy(ConditionNumber.One);

            SetCondition(rawSettings, ConditionNumber.One, Condition2);
            SetCondition(rawSettings, ConditionNumber.Two, swap);
        }
Ejemplo n.º 4
0
        /// This one is dumb and must not be called from other classes. RawMapping.Settings are ignored!
        private bool setCondition(ConditionNumber number, ACondition condition)
        {
            bool changed = false;

            if (number == ConditionNumber.One)
            {
                changed = (Condition1 != null && !Condition1.Equals(condition)) || (condition != null && !condition.Equals(Condition1));
                if (changed)
                {
                    Condition1 = condition;
                }
            }
            else
            {
                changed = (Condition2 != null && !Condition2.Equals(condition)) || (condition != null && !condition.Equals(Condition2));
                if (changed)
                {
                    Condition2 = condition;
                }
            }

            return(changed);
        }
Ejemplo n.º 5
0
 public ConditionTuple(ACondition c1, ACondition c2)
 {
     Condition1 = c1;
     Condition2 = c2;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Set condition by another condition.
        /// </summary>
        /// <param name="mappingSettings">Format.MappingSettings needed by proxy for creation of condition</param>
        /// <param name="number">Number of condition</param>
        /// <param name="condition">ACondition or null to reset condition.</param>
        /// <returns>True if condition was changed.</returns>
        internal bool SetCondition(Format.MappingSettings mappingSettings, ConditionNumber number, ACondition condition)
        {
            if (condition == null)
            {
                return(setCondition(number, condition));
            }
            else
            {
                bool changed = false;

                var targetCondition = (number == ConditionNumber.One) ? Condition1 : Condition2;

                if (targetCondition == null || targetCondition.Id != condition.Id)
                {
                    changed         = SetCondition(mappingSettings, number, Conditions.All.GetConditionProxy(condition.Id));
                    targetCondition = (number == ConditionNumber.One) ? Condition1 : Condition2; // needed?
                }

                // set assignment
                if (!changed)
                {
                    changed |= targetCondition.Assignment != condition.Assignment;
                }
                targetCondition.Assignment = condition.Assignment;

                // set value
                var newValue = condition.GetValue();
                if (!changed)
                {
                    changed |= targetCondition.GetValue() != newValue;
                }
                targetCondition.SetValue(newValue);

                return(changed);
            }
        }