示例#1
0
        // Computes the diffing for IEnumerable<object>.
        // For BHoMObjects, it assumes that they all have a HashFragment assigned (like when they have been passed through a Revision).
        // For non-BHoMObjects, it performs the VennDiagram comparision with a HashComparer.
        // Results for BHoMObjects and non are concatenated.
        private static Diff DiffRevisionObjects(IEnumerable <object> pastRevisionObjs, IEnumerable <object> followingRevisionObjs, DiffConfig diffConfig = null)
        {
            // Set configurations if diffConfig is null. Clone it for immutability in the UI.
            DiffConfig diffConfigCopy = diffConfig == null ? new DiffConfig() : diffConfig.DeepClone() as DiffConfig;

            // Dispatch the objects in BHoMObjects and generic objects.
            IEnumerable <IBHoMObject> prevObjs_BHoM = pastRevisionObjs.OfType <IBHoMObject>();
            IEnumerable <IBHoMObject> currObjs_BHoM = followingRevisionObjs.OfType <IBHoMObject>();

            // If all objects are bhomobjects, just call the appropriate method
            if (pastRevisionObjs.Count() != 0 && pastRevisionObjs.Count() == prevObjs_BHoM.Count() && followingRevisionObjs.Count() == currObjs_BHoM.Count())
            {
                return(DiffRevisionObjects(prevObjs_BHoM, currObjs_BHoM, diffConfigCopy));
            }

            IEnumerable <object> prevObjs_nonBHoM = pastRevisionObjs.Where(o => !(o is IBHoMObject));
            IEnumerable <object> currObjs_nonBHoM = followingRevisionObjs.Where(o => !(o is IBHoMObject));

            // Compute the specific Diffing for the BHoMObjects.
            Diff diff = Compute.DiffRevisionObjects(prevObjs_BHoM, currObjs_BHoM, diffConfigCopy);

            // Compute the generic Diffing for the other objects.
            // This is left to the VennDiagram with a HashComparer.
            VennDiagram <object> vd = Engine.Data.Create.VennDiagram(prevObjs_nonBHoM, currObjs_nonBHoM, new DiffingHashComparer <object>(diffConfig));

            // Concatenate the results of the two diffing operations.
            List <object> allPrevObjs      = new List <object>();
            List <object> allCurrObjs      = new List <object>();
            List <object> allUnchangedObjs = new List <object>();

            allCurrObjs.AddRange(diff.AddedObjects);
            allCurrObjs.AddRange(vd.OnlySet1);

            allPrevObjs.AddRange(diff.RemovedObjects);
            allPrevObjs.AddRange(vd.OnlySet2);

            // Create the final, actual diff.
            Diff finalDiff = new Diff(allCurrObjs, allPrevObjs, diff.ModifiedObjects, diffConfigCopy, diff.ModifiedPropsPerObject, diff.UnchangedObjects);

            return(finalDiff);
        }