private void CreateAndInsertDeltaOperation(string mrid, ResourceDescription rd)
        {
            long        negGid  = 0;
            DeltaOpType deltaOp = DeltaOpType.Insert;
            DMSType     type    = (DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rd.Id);

            if (ModelCodeHelper.ExtractEntityIdFromGlobalId(rd.Id) < 0 && !NegativeGidToMrid.ContainsKey(rd.Id))
            {
                negGid = rd.Id;
                NegativeGidToMrid.Add(rd.Id, mrid);
            }

            if (MridToPositiveGidFromServer.ContainsKey(mrid))
            {
                rd.Id   = MridToPositiveGidFromServer[mrid];
                deltaOp = DeltaOpType.Update;
            }

            delta.AddDeltaOperation(deltaOp, rd, true);

            if (!MridsFromConcreteModel.Contains(mrid))
            {
                MridsFromConcreteModel.Add(mrid);
            }

            report.Report.Append("Operation: ").Append(deltaOp).Append(" ").Append(type)
            .Append(" mrid: ").Append(mrid)
            .Append(" ID: ").Append(string.Format("0x{0:X16}", negGid))
            .Append(" after correction is GID: ").AppendLine($"0x{rd.Id:X16}");
        }
        private void CorrectNegativeReferences()
        {
            foreach (ResourceDescription rd in delta.InsertOperations)
            {
                foreach (Property prop in rd.Properties)
                {
                    if (prop.Type == PropertyType.Reference)
                    {
                        long targetGid = prop.AsLong();

                        if (ModelCodeHelper.ExtractEntityIdFromGlobalId(targetGid) < 0)
                        {
                            if (NegativeGidToMrid.ContainsKey(targetGid))
                            {
                                string mrid = NegativeGidToMrid[targetGid];
                                if (MridToPositiveGidFromServer.ContainsKey(mrid))
                                {
                                    long positiveGid = MridToPositiveGidFromServer[mrid];
                                    prop.SetValue(positiveGid);
                                }
                            }
                        }
                    }
                }
            }

            foreach (ResourceDescription rd in delta.UpdateOperations)
            {
                foreach (Property prop in rd.Properties)
                {
                    if (prop.Type == PropertyType.Reference)
                    {
                        long targetGid = prop.AsLong();

                        if (ModelCodeHelper.ExtractEntityIdFromGlobalId(targetGid) < 0)
                        {
                            if (NegativeGidToMrid.ContainsKey(targetGid))
                            {
                                string mrid = NegativeGidToMrid[targetGid];
                                if (MridToPositiveGidFromServer.ContainsKey(mrid))
                                {
                                    long positiveGid = MridToPositiveGidFromServer[mrid];
                                    prop.SetValue(positiveGid);
                                }
                            }
                        }
                    }
                }
            }
        }