public static Dictionary <DMSType, ModelCode> GetTypeToModelCodeMap() { Dictionary <DMSType, ModelCode> d = new Dictionary <DMSType, ModelCode>(TypeIdsInInsertOrder.Length); foreach (ModelCode mc in Enum.GetValues(typeof(ModelCode))) { DMSType type = ModelCodeHelper.GetTypeFromModelCode(mc); if (ModelCodeHelper.IsClass(mc) && type != 0) { d.Add(type, mc); } } return(d); }
public static Dictionary <DMSType, List <ModelCode> > GetTypeToPropertiesMap() { Dictionary <DMSType, List <ModelCode> > d = new Dictionary <DMSType, List <ModelCode> >(TypeIdsInInsertOrder.Length); Dictionary <DMSType, ModelCode> typeToMC = new Dictionary <DMSType, ModelCode>(); List <ModelCode> abstractType = new List <ModelCode>(); foreach (DMSType type in TypeIdsInInsertOrder) { d.Add(type, new List <ModelCode>()); } foreach (ModelCode mc in Enum.GetValues(typeof(ModelCode))) { DMSType type = ModelCodeHelper.GetTypeFromModelCode(mc); if (ModelCodeHelper.IsProperty(mc)) { (type == 0 ? abstractType : d[type]).Add(mc); } else if (type != 0) { typeToMC.Add(type, mc); } } foreach (ModelCode mc in abstractType) { foreach (KeyValuePair <DMSType, List <ModelCode> > type in d) { if (ModelCodeHelper.ModelCodeClassIsSubClassOf(typeToMC[type.Key], mc)) { type.Value.Add(mc); } } } return(d); }
public Dictionary <long, long> ResolveIds(Func <DMSType, int> idGenerator) { Dictionary <long, long> d = new Dictionary <long, long>(); // fix ids in insert operations - generate positive ids foreach (ResourceDescription rd in insertOps) { long oldGid = rd.Id; int oldId = ModelCodeHelper.GetEntityIdFromGID(oldGid); if (oldId >= 0) { Message = "Inserted GID " + oldGid + " has a positive entity ID."; return(null); } if (d.ContainsKey(oldGid)) { Message = "Inserted GID " + oldGid + " is a duplicate."; return(null); } DMSType type = (DMSType)ModelCodeHelper.GetTypeFromGID(rd.Id); int newId = idGenerator(type); if (newId < 0) { Message = "Inserted GID " + oldGid + " has an invalid DMSType."; return(null); } long newGid = ModelCodeHelper.SetEntityIdInGID(oldGid, newId); newGid = ModelCodeHelper.SetSystemIdInGID(newGid, 0); d[oldGid] = newGid; rd.Id = newGid; } // change reference ids in insert operations foreach (ResourceDescription rd in insertOps) { foreach (Property p in rd.Properties.Values) { if (p.Type == PropertyType.Reference) { long oldGid = ((ReferenceProperty)p).Value; int oldId = ModelCodeHelper.GetEntityIdFromGID(oldGid); if (oldId < 0) { if (!d.ContainsKey(oldGid)) { Message = "Referenced inserted GID " + oldGid + " not found."; return(null); } ((ReferenceProperty)p).Value = d[oldGid]; } } else if (p.Type == PropertyType.ReferenceVector) { bool changed = false; List <long> gids = ((ReferencesProperty)p).Value; for (int i = 0; i < gids.Count; ++i) { long oldGid = gids[i]; int oldId = ModelCodeHelper.GetEntityIdFromGID(oldGid); if (oldId < 0) { if (!d.ContainsKey(oldGid)) { Message = "Referenced inserted GID " + oldGid + " not found."; return(null); } gids[i] = d[oldGid]; changed = true; } } if (changed) { ((ReferencesProperty)p).Value = gids; } } } } // change ids and reference ids in update operations foreach (ResourceDescription rd in updateOps) { long oldGid = rd.Id; int oldId = ModelCodeHelper.GetEntityIdFromGID(rd.Id); if (oldId < 0) { if (oldId < 0) { if (!d.ContainsKey(oldGid)) { Message = "Referenced inserted GID " + oldGid + " not found."; return(null); } rd.Id = d[oldGid]; } } foreach (Property p in rd.Properties.Values) { if (p.Type == PropertyType.Reference) { long gidOldRef = ((ReferenceProperty)p).Value; int idOldRef = ModelCodeHelper.GetEntityIdFromGID(gidOldRef); if (idOldRef < 0) { if (!d.ContainsKey(gidOldRef)) { Message = "Referenced inserted GID " + gidOldRef + " not found."; return(null); } ((ReferenceProperty)p).Value = d[gidOldRef]; } } else if (p.Type == PropertyType.ReferenceVector) { bool changed = false; List <long> gids = ((ReferencesProperty)p).Value; for (int i = 0; i < gids.Count; ++i) { long gidOldRef = gids[i]; int idOldRef = ModelCodeHelper.GetEntityIdFromGID(gidOldRef); if (idOldRef < 0) { if (!d.ContainsKey(gidOldRef)) { Message = "Referenced inserted GID " + gidOldRef + " not found."; return(null); } gids[i] = d[gidOldRef]; changed = true; } } if (changed) { ((ReferencesProperty)p).Value = gids; } } } } // change ids in delete operations foreach (ResourceDescription rd in deleteOps) { long oldGid = rd.Id; int oldId = ModelCodeHelper.GetEntityIdFromGID(oldGid); if (oldId < 0) { if (!d.ContainsKey(oldGid)) { Message = "Referenced inserted GID " + oldGid + " not found."; return(null); } rd.Id = d[oldGid]; } } return(d); }