예제 #1
0
        public ClassInfoCompareResult ExtractDifferences(ClassInfo newCI, bool update)
        {
            string attributeName;
            ClassAttributeInfo cai1;
            ClassAttributeInfo cai2;

            var result = new ClassInfoCompareResult(FullClassName);
            IOdbList<ClassAttributeInfo> attributesToRemove = new OdbList<ClassAttributeInfo>(10);
            IOdbList<ClassAttributeInfo> attributesToAdd = new OdbList<ClassAttributeInfo>(10);

            var attributesCount = _attributes.Count;
            for (var id = 0; id < attributesCount; id++)
            {
                // !!!WARNING : ID start with 1 and not 0
                cai1 = _attributes[id];
                if (cai1 == null)
                    continue;
                attributeName = cai1.GetName();
                cai2 = newCI.GetAttributeInfoFromId(cai1.GetId());
                if (cai2 == null)
                {
                    result.AddCompatibleChange(string.Format("Field '{0}' has been removed", attributeName));
                    if (update)
                    {
                        // Simply remove the attribute from meta-model
                        attributesToRemove.Add(cai1);
                    }
                }
                else
                {
                    if (!OdbType.TypesAreCompatible(cai1.GetAttributeType(), cai2.GetAttributeType()))
                    {
                        result.AddIncompatibleChange(
                            string.Format("Type of Field '{0}' has changed : old='{1}' - new='{2}'", attributeName,
                                          cai1.GetFullClassname(), cai2.GetFullClassname()));
                    }
                }
            }

            var nbNewAttributes = newCI._attributes.Count;
            for (var id = 0; id < nbNewAttributes; id++)
            {
                // !!!WARNING : ID start with 1 and not 0
                cai2 = newCI._attributes[id];
                if (cai2 == null)
                    continue;
                attributeName = cai2.GetName();
                cai1 = GetAttributeInfoFromId(cai2.GetId());
                if (cai1 == null)
                {
                    result.AddCompatibleChange("Field '" + attributeName + "' has been added");
                    if (update)
                    {
                        // Sets the right id of attribute
                        cai2.SetId(MaxAttributeId + 1);
                        MaxAttributeId++;
                        // Then adds the new attribute to the meta-model
                        attributesToAdd.Add(cai2);
                    }
                }
            }
            _attributes.RemoveAll(attributesToRemove);
            _attributes.AddAll(attributesToAdd);
            FillAttributesMap();
            return result;
        }
예제 #2
0
        public ClassInfoCompareResult ExtractDifferences(ClassInfo newCI, bool update)
        {
            string             attributeName;
            ClassAttributeInfo cai1;
            ClassAttributeInfo cai2;

            var result = new ClassInfoCompareResult(FullClassName);
            IOdbList <ClassAttributeInfo> attributesToRemove = new OdbList <ClassAttributeInfo>(10);
            IOdbList <ClassAttributeInfo> attributesToAdd    = new OdbList <ClassAttributeInfo>(10);

            var attributesCount = _attributes.Count;

            for (var id = 0; id < attributesCount; id++)
            {
                // !!!WARNING : ID start with 1 and not 0
                cai1 = _attributes[id];
                if (cai1 == null)
                {
                    continue;
                }
                attributeName = cai1.GetName();
                cai2          = newCI.GetAttributeInfoFromId(cai1.GetId());
                if (cai2 == null)
                {
                    result.AddCompatibleChange(string.Format("Field '{0}' has been removed", attributeName));
                    if (update)
                    {
                        // Simply remove the attribute from meta-model
                        attributesToRemove.Add(cai1);
                    }
                }
                else
                {
                    if (!OdbType.TypesAreCompatible(cai1.GetAttributeType(), cai2.GetAttributeType()))
                    {
                        result.AddIncompatibleChange(
                            string.Format("Type of Field '{0}' has changed : old='{1}' - new='{2}'", attributeName,
                                          cai1.GetFullClassname(), cai2.GetFullClassname()));
                    }
                }
            }

            var nbNewAttributes = newCI._attributes.Count;

            for (var id = 0; id < nbNewAttributes; id++)
            {
                // !!!WARNING : ID start with 1 and not 0
                cai2 = newCI._attributes[id];
                if (cai2 == null)
                {
                    continue;
                }
                attributeName = cai2.GetName();
                cai1          = GetAttributeInfoFromId(cai2.GetId());
                if (cai1 == null)
                {
                    result.AddCompatibleChange("Field '" + attributeName + "' has been added");
                    if (update)
                    {
                        // Sets the right id of attribute
                        cai2.SetId(MaxAttributeId + 1);
                        MaxAttributeId++;
                        // Then adds the new attribute to the meta-model
                        attributesToAdd.Add(cai2);
                    }
                }
            }
            _attributes.RemoveAll(attributesToRemove);
            _attributes.AddAll(attributesToAdd);
            FillAttributesMap();
            return(result);
        }