Beispiel #1
0
        /// <summary>
        ///    Check if the value are equals for the given property and the two objects.
        ///    First implementation was using an expression but the call to compile was way to long comparing to the actual
        ///    comparison
        /// </summary>
        /// <typeparam name="TInput">Input type</typeparam>
        /// <typeparam name="TOuput">Output type</typeparam>
        /// <param name="funcEvaluation">
        ///    The actual function being evaluated. We could compile the property name expression but
        ///    this would have an impact on performance
        /// </param>
        /// <param name="propertyName">Name of property being compared</param>
        /// <param name="comparison">Comparison</param>
        /// <param name="areEquals">Method used to compare the two values of type TOutput</param>
        /// <param name="formatter">Formatter used to format the output value</param>
        protected void CompareValues <TInput, TOuput>(Func <TInput, TOuput> funcEvaluation, string propertyName, IComparison <TInput> comparison, Func <TOuput, TOuput, bool> areEquals, Func <TInput, TOuput, string> formatter) where TInput : class
        {
            var object1 = comparison.Object1;
            var object2 = comparison.Object2;

            var value1 = funcEvaluation(object1);
            var value2 = funcEvaluation(object2);

            if (areEquals(value1, value2))
            {
                return;
            }

            var formattedValue1 = formatter(object1, value1);
            var formattedValue2 = formatter(object2, value2);


            var diffItem = new PropertyValueDiffItem
            {
                Object1         = comparison.Object1,
                Object2         = comparison.Object2,
                CommonAncestor  = comparison.CommonAncestor,
                PropertyName    = propertyName,
                FormattedValue1 = formattedValue1,
                FormattedValue2 = formattedValue2,
                Description     = Captions.Diff.PropertyDiffers(propertyName, formattedValue1, formattedValue2)
            };

            comparison.Add(diffItem);
        }
        public void CompareEnumerables <TParent, TItem>(IComparison <TParent> comparison,
                                                        Func <TParent, IEnumerable <TItem> > getEnumeration,
                                                        Func <TItem, TItem, bool> equalityFunc,
                                                        Func <TItem, string> identifierRetrieverFunc,
                                                        Func <TItem, string> presentObjectDetailsFunc = null,
                                                        string missingItemType = null)
            where TParent : class
            where TItem : class
        {
            var object1 = comparison.Object1;
            var object2 = comparison.Object2;
            var list1   = getEnumeration(object1).ToList();
            var list2   = getEnumeration(object2).ToList();

            foreach (var entity1 in list1)
            {
                var entity2 = list2.FirstOrDefault(item => equalityFunc(item, entity1));
                if (entity2 != null)
                {
                    var childComparison = new Comparison <TItem>(entity1, entity2, comparison.Settings, comparison.Report, object1);
                    _objectComparer.Compare(childComparison);
                }
                else
                {
                    var missingObjectType    = missingItemType ?? _objectTypeResolver.TypeFor(entity1);
                    var presentObjectDetails = presentObjectDetailsFunc?.Invoke(entity1) ?? string.Empty;
                    comparison.Add(missingItem(object1, object2, entity1, null, missingObjectType, identifierRetrieverFunc(entity1), presentObjectDetails));
                }
            }

            //all common entity have been added. Add missing entity from object1 base on object2
            foreach (var entity2 in list2)
            {
                if (list1.Any(item => equalityFunc(item, entity2)))
                {
                    continue;
                }

                var missingObjectType    = missingItemType ?? _objectTypeResolver.TypeFor(entity2);
                var presentObjectDetails = presentObjectDetailsFunc?.Invoke(entity2) ?? string.Empty;
                comparison.Add(missingItem(object1, object2, null, entity2, missingObjectType, identifierRetrieverFunc(entity2), presentObjectDetails));
            }
        }
Beispiel #3
0
 private static void addVersionDiffitem(IComparison <IBuildingBlockInfo> comparison, string buildingBlock1, string buildingBlock2)
 {
     comparison.Add(new PropertyValueDiffItem()
     {
         Object1         = comparison.Object1,
         Object2         = comparison.Object2,
         CommonAncestor  = comparison.CommonAncestor,
         PropertyName    = AppConstants.Diff.Version,
         FormattedValue1 = buildingBlock1,
         FormattedValue2 = buildingBlock2,
         Description     = AppConstants.Diff.VersionDescription(buildingBlock1)
     });
 }
Beispiel #4
0
        private void addMissingItem(IComparison <IEnumerable <UsedBuildingBlock> > comparison, UsedBuildingBlock buildingBlock1, UsedBuildingBlock buildingBlock2, PKSimBuildingBlockType buildingBlockType)
        {
            var missingObject = buildingBlock1 ?? buildingBlock2;
            var missingItem   = new MissingDiffItem
            {
                Object1           = buildingBlock1,
                Object2           = buildingBlock2,
                MissingObject1    = buildingBlock1,
                MissingObject2    = buildingBlock2,
                CommonAncestor    = comparison.CommonAncestor,
                MissingObjectName = missingObject.Name,
                MissingObjectType = buildingBlockType.ToString()
            };

            comparison.Add(missingItem);
        }
        private void compareNeighbors(IComparison <INeighborhoodBase> comparison)
        {
            var firstNeigbor1Path  = _entityPathResolver.PathFor(comparison.Object1.FirstNeighbor);
            var secondNeigbor1Path = _entityPathResolver.PathFor(comparison.Object1.SecondNeighbor);
            var firstNeigbor2Path  = _entityPathResolver.PathFor(comparison.Object2.FirstNeighbor);
            var secondNeigbor2Path = _entityPathResolver.PathFor(comparison.Object2.SecondNeighbor);

            if (firstNeigbor1Path.Equals(firstNeigbor2Path) && secondNeigbor1Path.Equals(secondNeigbor2Path) ||
                firstNeigbor1Path.Equals(secondNeigbor2Path) && secondNeigbor1Path.Equals(firstNeigbor2Path))
            {
                return;
            }

            comparison.Add(new PropertyValueDiffItem
            {
                CommonAncestor  = comparison.Object1,
                FormattedValue1 = Captions.Diff.ConnectionBetween(firstNeigbor1Path, secondNeigbor1Path),
                FormattedValue2 = Captions.Diff.ConnectionBetween(firstNeigbor2Path, secondNeigbor2Path),
                PropertyName    = Captions.Diff.Connection,
                Description     = Captions.Diff.PropertyDiffers(Captions.Diff.Connection, Captions.Diff.ConnectionBetween(firstNeigbor1Path, secondNeigbor1Path), Captions.Diff.ConnectionBetween(firstNeigbor2Path, secondNeigbor2Path))
            });
        }