public Task Run()

in DTDLValidator/DTDLValidator/Interactive/CompareCommand.cs [21:111]


        public Task Run(Interactive p)
        {
            if (FirstModelId == null || SecondModelId == null)
            {
                Log.Error("Please specify two valid model ids as parameters");
                return Task.FromResult<object>(null);
            }

            bool firstValid = false;
            bool secondValid = false;

            Dtmi first = ValidateAndCreateDtmi(FirstModelId);
            Dtmi second = ValidateAndCreateDtmi(SecondModelId);
            DTInterfaceInfo dt1 = null;
            DTInterfaceInfo dt2 = null;

            if (first!=null && p.Models.TryGetValue(first, out dt1))
                firstValid = true;
            if (second != null && p.Models.TryGetValue(second, out dt2))
                secondValid = true;

            if (firstValid == false || secondValid == false)
            {
                if (first == null)
                    Log.Error($"First model not a valid dtmi");
                if (first!=null && firstValid == false)
                    Log.Error($"First model not found in loaded models");
                if (second == null)
                    Log.Error($"Second model not a valid dtmi");
                if (second != null && secondValid == false)
                    Log.Error($"Second model not found in loaded models");
                return Task.FromResult<object>(null);
            }

            IReadOnlyDictionary<string, DTContentInfo> con1 = dt1.Contents;
            IReadOnlyDictionary<string, DTContentInfo> con2 = dt2.Contents;
            
            var props1 = con1
                            .Where(p => p.Value.EntityKind == DTEntityKind.Property)
                            .Select(p => p.Value as DTPropertyInfo);

            var props2 = con2
                            .Where(p => p.Value.EntityKind == DTEntityKind.Property)
                            .Select(p => p.Value as DTPropertyInfo);

            IEnumerable<DTPropertyInfo> duplicates = props1.Intersect(props2, new DTPropertyInfoComparer());
            IEnumerable<DTPropertyInfo> diff1 = props1.Except(props2, new DTPropertyInfoComparer());
            IEnumerable<DTPropertyInfo> diff2 = props2.Except(props1, new DTPropertyInfoComparer());

            Log.Alert("Common Properties (comparing name and schema, ignoring explicit ids)");
            Console.WriteLine(listFormatBoth, "Property Name", "Schema");
            Console.WriteLine(listFormatBoth, "-------------", "------");
            foreach (var pi in duplicates)
                Console.WriteLine(listFormatBoth, pi.Name, pi.Schema);

            Console.WriteLine();
            PrintDifference(dt1, diff1);
            Console.WriteLine();
            PrintDifference(dt2, diff2);

            var rels1 = con1
                            .Where(p => p.Value.EntityKind == DTEntityKind.Relationship)
                            .Select(p => p.Value as DTRelationshipInfo);

            var rels2 = con2
                            .Where(p => p.Value.EntityKind == DTEntityKind.Relationship)
                            .Select(p => p.Value as DTRelationshipInfo);

            IEnumerable<DTRelationshipInfo> dupRels = rels1.Intersect(rels2, new DTRelationshipInfoComparer());
            IEnumerable<DTRelationshipInfo> diffRels1 = rels1.Except(rels2, new DTRelationshipInfoComparer());
            IEnumerable<DTRelationshipInfo> diffRels2 = rels2.Except(rels1, new DTRelationshipInfoComparer());

            Console.WriteLine();
            Log.Alert("Common Relationships (comparing name and target - not checking properties, ignoring explicit ids)");
            Console.WriteLine(listFormatBoth, "Relationship Name", "Target");
            Console.WriteLine(listFormatBoth, "-----------------", "------");
            foreach (var pi in dupRels)
            {
                string target = "<any>";
                if (pi.Target != null)
                    target = pi.Target.ToString();
                Console.WriteLine(listFormatBoth, pi.Name, target);
            }

            Console.WriteLine();
            PrintDifference(dt1, diffRels1);
            Console.WriteLine();
            PrintDifference(dt2, diffRels2);

            return Task.FromResult<object>(null);
        }