Пример #1
0
        public CoverCollection Get(int valeur)
        {
            if (Valeur > valeur)
            {
                return(null);
            }

            var evts = Engine.CoverCollectionEvents.Where(x => x.CoverCollectionId.Equals(Id)).OrderBy(o => o.ValeurDate).ThenBy(t => t.RegisterDate);

            var values = new Dictionary <string, int>(Values);

            var result = new CoverCollection(AgreementId, values, Valeur, Id);

            foreach (var evt in evts)
            {
                if (evt.ValeurDate > valeur)
                {
                    break;
                }
                result = ApplyChange(result, evt);
            }
            var agr = Engine.GetAgreement(AgreementId, valeur);

            MergeValues(agr, result);
            if (agr.ValeurDate > result.Valeur)
            {
                result.Valeur = agr.ValeurDate;
            }


            return(result);
        }
Пример #2
0
 private static void MergeValues(Agreement agr, CoverCollection result)
 {
     foreach (var val in agr.Values)
     {
         if (!result.Values.ContainsKey(val.Key))
         {
             result.Values.Add(val.Key, val.Value);
         }
     }
 }
Пример #3
0
        public CoverCollection CreateCoverCollection(int agrId, Dictionary <string, int> values, int valeur)
        {
            var agr      = Engine.GetAgreement(agrId, valeur);
            var ccValues = values.Where(val => !agr.Values.ContainsKey(val.Key) || !agr.Values[val.Key].Equals(val.Value)).ToDictionary(val => val.Key, val => val.Value);

            var cc = new CoverCollection(agr.Id, ccValues, valeur);

            Engine.CoverCollections.Add(cc);
            return(cc.Get(valeur));
        }
Пример #4
0
        private CoverCollection ApplyChange(CoverCollection result, BaseEvent evt)
        {
            var cc = new CoverCollection(AgreementId, new Dictionary <string, int>(result.Values), evt.ValeurDate)
            {
                Id = Id
            };

            foreach (var change in evt.Changes)
            {
                if (cc.Values.ContainsKey(change.Key))
                {
                    if (evt is ChangeCoverCollectionEvent)
                    {
                        cc.Values[change.Key] = change.Value;
                    }
                }
                else
                {
                    cc.Values.Add(change.Key, change.Value);
                }
            }
            return(cc);
        }
Пример #5
0
 private static bool CheckCoverCollection(CoverCollection cc, int x, int y, int a, int valeur)
 {
     return(cc.Values.ContainsKey("x") && cc.Values["x"] == x && cc.Values.ContainsKey("y") && cc.Values["y"] == y && cc.Values.ContainsKey("a") && cc.Values["a"] == a && cc.Valeur == valeur);
 }