Beispiel #1
0
        private void UpdateOptionComparisons()
        {
            var currentHashCodes  = new HashSet <int>(OptionComparisons.Select(c => c.GetHashCode()));
            var proposedHashCodes = new HashSet <int>();

            foreach (var crit in Criteria.Items)
            {
                for (int i = 0; i < Options.Items.Count(); i++)
                {
                    for (int j = i + 1; j < Options.Items.Count(); j++)
                    {
                        var oc = new OptionComparison(crit, Options.Items.ElementAt(i), Options.Items.ElementAt(j));
                        oc.OnWeightChange += OnWeightChange;
                        var hashCode = oc.GetHashCode();
                        proposedHashCodes.Add(hashCode);
                        if (!currentHashCodes.Contains(hashCode))
                        {
                            OptionComparisons.Add(oc);
                        }
                    }
                }
            }

            foreach (var exitstingOc in OptionComparisons.ToList())
            {
                if (!proposedHashCodes.Contains(exitstingOc.GetHashCode()))
                {
                    exitstingOc.OnWeightChange -= OnWeightChange;
                    OptionComparisons.Remove(exitstingOc);
                }
            }

            OptionComparisons = OptionComparisons.OrderBy(b => b.Criterion).ToList();
        }
Beispiel #2
0
 public SerializedDecision Serialize()
 {
     return(new SerializedDecision
     {
         Id = Id,
         Name = Name,
         DateCreatedUtc = DateCreatedUtc,
         Options = Options.Items.ToArray(),
         Criteria = Criteria.Items.ToArray(),
         CriteriaComparisons = CriteriaComparisons.Select(cc => new SerializedCriteriaComparison
         {
             CriterionOne = cc.CriterionOne,
             CriterionTwo = cc.CriterionTwo,
             Weight = cc.Weight
         }).ToArray(),
         OptionComparisons = OptionComparisons.Select(oc => new SerializedOptionComparison
         {
             Criterion = oc.Criterion,
             OptionOne = oc.OptionOne,
             OptionTwo = oc.OptionTwo,
             Weight = oc.Weight
         }).ToArray()
     });
 }