protected void CloneSegmentAttributesWithoutId(KopieAchsenSegment targetItem, IImportedSegment importedSegment)
 {
     targetItem.AchsenId  = importedSegment.AchsenId;
     targetItem.Name      = importedSegment.Name;
     targetItem.Sequence  = importedSegment.Sequence;
     targetItem.Operation = importedSegment.Operation;
     targetItem.Shape     = importedSegment.Shape;
 }
Example #2
0
        private AchsenSegment findSegment(Achse achse, KopieAchsenSegment kopieSegment)
        {
            var list = achse.AchsenSegmente.Where(o => o.BsId == kopieSegment.Id);

            if (list.Count() == 0)
            {
                list = achsenCache.SelectMany(a => a.Value.AchsenSegmente).Where(s => s.BsId == kopieSegment.Id);
                if (!list.Any())
                {
                    return(null);
                }
            }

            return(list.First());
        }
        ///// utils
        protected void ReceivedItem(IImportedItem item)
        {
            if (item.Operation == AxisImportOperation.INSERT) // insert?
            {
                IKopie kopie = null;
                Num    num   = null;
                switch (Pass)
                {
                case AxisImportPass.Achsen:
                    kopie = new KopieAchse();
                    CloneAxisAttributesWithoutId(kopie as KopieAchse, item as IImportedAchse);
                    num = statistics.NumAxis;
                    break;

                case AxisImportPass.Segmente:
                    kopie = new KopieAchsenSegment();
                    CloneSegmentAttributesWithoutId(kopie as KopieAchsenSegment, item as IImportedSegment);
                    num = statistics.NumSegment;
                    break;

                case AxisImportPass.Sektoren:
                    kopie = new KopieSektor();
                    CloneSektorAttributesWithoutId(kopie as KopieSektor, item as IImportedSektor);
                    num = statistics.NumSector;
                    break;

                default:
                    return;
                }
                kopie.Id = item.Id;

                kopie.ImpNr = ImpNr;
                CurrentSession.Persist(kopie);

                num.Inserts++;
            }
            else  // update or delete
            {
                IKopie kopie = null;
                Num    num   = null;

                switch (Pass)
                {
                case AxisImportPass.Achsen:
                    kopie = CurrentSession.Get <KopieAchse>(item.Id);
                    if (kopie == null)
                    {
                        throw new AxisImportException("Axis " + item.Id + " does not exist in database");
                    }
                    CloneAxisAttributesWithoutId(kopie as KopieAchse, item as IImportedAchse);
                    num = statistics.NumAxis;
                    break;

                case AxisImportPass.Segmente:
                    kopie = CurrentSession.Get <KopieAchsenSegment>(item.Id);
                    if (kopie == null)
                    {
                        throw new AxisImportException("Segment " + item.Id + " does not exist in database");
                    }
                    CloneSegmentAttributesWithoutId(kopie as KopieAchsenSegment, item as IImportedSegment);
                    num = statistics.NumSegment;
                    break;

                case AxisImportPass.Sektoren:
                    kopie = CurrentSession.Get <KopieSektor>(item.Id);
                    if (kopie == null)
                    {
                        throw new AxisImportException("Sektor " + item.Id + " does not exist in database");
                    }
                    CloneSektorAttributesWithoutId(kopie as KopieSektor, item as IImportedSektor);
                    num = statistics.NumSector;
                    break;

                default:
                    return;
                }

                kopie.ImpNr = ImpNr;

                if (item.Operation == AxisImportOperation.UPDATE)
                {
                    num.Updates++;
                }
                else
                {
                    num.Deletes++;
                }
            }
            HavePersistedRecord();
        }
Example #4
0
        private void ReadAchsKopieData()
        {
            // HQL doesnt support left joins for foreign keys that aren't mapped
            // therefore we need three queries

            {
                var list = session.QueryOver <KopieAchse>().Where(ka => ka.Owner == owner).List();

                foreach (object obj in list)
                {
                    KopieAchse achse = (KopieAchse)obj;

                    if (!kopieAchsenToSegmentDict.ContainsKey(achse))
                    {
                        kopieAchsenToSegmentDict.Add(achse, new HashSet <KopieAchsenSegment>()
                        {
                        });
                    }
                    else
                    {
                    }
                }
            }

            {
                var kopieAchseTypeName                     = typeof(KopieAchse).Name;
                var kopieAchsenSegmentTypeName             = typeof(KopieAchsenSegment).Name;
                var kopieAchseIdPropertyName               = ExpressionHelper.GetPropertyName <KopieAchse, Guid>(ka => ka.Id);
                var kopieAchsenSegmentAchsenIdPropertyName = ExpressionHelper.GetPropertyName <KopieAchsenSegment, Guid>(kas => kas.AchsenId);
                var kopieAchseOwnerPropertyName            = ExpressionHelper.GetPropertyName <KopieAchse, string>(ka => ka.Owner);

                var qry = session.CreateQuery(string.Format("from {0} achse, {1} segment where achse.{2} = segment.{3} and achse.{4} = :owner",
                                                            new string[] { kopieAchseTypeName, kopieAchsenSegmentTypeName, kopieAchseIdPropertyName, kopieAchsenSegmentAchsenIdPropertyName, kopieAchseOwnerPropertyName }));
                qry.SetString("owner", owner);
                qry.SetReadOnly(true);
                var list = qry.List();

                foreach (object arr in list)
                {
                    KopieAchse         achse         = (KopieAchse)((object[])arr)[0];
                    KopieAchsenSegment achsenSegment = (KopieAchsenSegment)((object[])arr)[1];

                    if (!kopieAchsenToSegmentDict.ContainsKey(achse))
                    {
                        kopieAchsenToSegmentDict.Add(achse, new HashSet <KopieAchsenSegment>()
                        {
                            achsenSegment
                        });
                    }
                    else
                    {
                        kopieAchsenToSegmentDict[achse].Add(achsenSegment);
                    }

                    if (!kopieSegmentToSektorDict.ContainsKey(achsenSegment))
                    {
                        kopieSegmentToSektorDict.Add(achsenSegment, new HashSet <KopieSektor>()
                        {
                        });
                    }
                }
            }


            {
                var kopieAchseTypeName                     = typeof(KopieAchse).Name;
                var kopieAchsenSegmentTypeName             = typeof(KopieAchsenSegment).Name;
                var kopieSektorTypeName                    = typeof(KopieSektor).Name;
                var kopieAchseIdPropertyName               = ExpressionHelper.GetPropertyName <KopieAchse, Guid>(ka => ka.Id);
                var kopieAchsenSegmentAchsenIdPropertyName = ExpressionHelper.GetPropertyName <KopieAchsenSegment, Guid>(kas => kas.AchsenId);
                var kopieAchsenSegmentIdPropertyName       = ExpressionHelper.GetPropertyName <KopieAchsenSegment, Guid>(kas => kas.Id);
                var kopieAchsenSektorSegmentIdPropertyName = ExpressionHelper.GetPropertyName <KopieSektor, Guid>(ks => ks.SegmentId);
                var kopieAchseOwnerPropertyName            = ExpressionHelper.GetPropertyName <KopieAchse, string>(ka => ka.Owner);

                var qry = session.CreateQuery(string.Format("from {0} achse, {1} segment, {2} sektor where achse.{3} = segment.{4} and segment.{5} = sektor.{6} and achse.{7} = :owner",
                                                            new string[] { kopieAchseTypeName, kopieAchsenSegmentTypeName, kopieSektorTypeName,
                                                                           kopieAchseIdPropertyName, kopieAchsenSegmentAchsenIdPropertyName, kopieAchsenSegmentIdPropertyName,
                                                                           kopieAchsenSektorSegmentIdPropertyName, kopieAchseOwnerPropertyName }));
                qry.SetString("owner", owner);
                qry.SetReadOnly(true);
                var list = qry.List();

                foreach (object arr in list)
                {
                    KopieAchse         achse         = (KopieAchse)((object[])arr)[0];
                    KopieAchsenSegment achsenSegment = (KopieAchsenSegment)((object[])arr)[1];
                    KopieSektor        sektor        = (KopieSektor)((object[])arr)[2];

                    if (!kopieAchsenToSegmentDict.ContainsKey(achse))
                    {
                        kopieAchsenToSegmentDict.Add(achse, new HashSet <KopieAchsenSegment>()
                        {
                            achsenSegment
                        });
                    }
                    else
                    {
                        kopieAchsenToSegmentDict[achse].Add(achsenSegment);
                    }


                    if (!kopieSegmentToSektorDict.ContainsKey(achsenSegment))
                    {
                        kopieSegmentToSektorDict.Add(achsenSegment, new HashSet <KopieSektor>()
                        {
                            sektor
                        });
                    }
                    else
                    {
                        kopieSegmentToSektorDict[achsenSegment].Add(sektor);
                    }
                }
            }
        }
Example #5
0
        private AchsenSegment UpdateSegment(Achse achse, KopieAchse kopieAchse, KopieAchsenSegment kopieSegment, int operation)
        {
            if (kopieSegment.ImpNr <= lastImpNr)
            {
                return(null);
            }

            maxImpNr = Math.Max(maxImpNr, kopieSegment.ImpNr);

            switch (operation)
            {
            case AxisImportOperation.DELETE:
            {
                AchsenSegment segment =
                    findSegment(achse, kopieSegment);

                if (segment == null)
                {
                    return(null);
                }

                if (ReferenceUpdater != null)
                {
                    ReferenceUpdater.BeforeDeleteSegment(segment);
                }

                foreach (KopieSektor kopieSektor in kopieSegmentToSektorDict[kopieSegment])
                {
                    UpdateSektor(segment, kopieSektor, kopieSektor.Operation);
                }

                achse.AchsenSegmente.Remove(segment);
                session.Delete(segment);

                statistics.NumSegment.Deletes++;
                return(null);
            }

            case AxisImportOperation.UPDATE:
            {
                AchsenSegment segment =
                    findSegment(achse, kopieSegment);

                if (segment == null)
                {
                    return(UpdateSegment(achse, kopieAchse, kopieSegment, AxisImportOperation.INSERT));
                }

                if (ReferenceUpdater != null)
                {
                    ReferenceUpdater.BeforeUpdateSegment(segment, kopieAchse, kopieSegment);
                }

                segment         = gisKopieMappingEngine.Translate <KopieAchsenSegment, AchsenSegment>(kopieSegment, segment);
                segment.Shape4d = kopieSegment.Shape;

                if (segment.Mandant != mandant)
                {
                    throw new Exception("segment.Mandant != mandant");
                }

                foreach (KopieSektor kopieSektor in kopieSegmentToSektorDict[kopieSegment])
                {
                    UpdateSektor(segment, kopieSektor, kopieSektor.Operation);
                }

                statistics.NumSegment.Updates++;
                return(segment);
            }

            case AxisImportOperation.INSERT:
            {
                if (findSegment(achse, kopieSegment) != null)
                {
                    throw new Exception("Cannot insert: KopieSegment " + kopieSegment.Id + " already exists in AchsenSegment table!");
                }

                AchsenSegment segment = gisKopieMappingEngine.Translate <KopieAchsenSegment, AchsenSegment>(kopieSegment);
                segment.BsId = kopieSegment.Id;

                segment.Shape4d = kopieSegment.Shape;

                segment.Mandant          = mandant;
                segment.ErfassungsPeriod = erfassungsPeriod;

                segment.Achse = achse;
                achse.AchsenSegmente.Add(segment);

                foreach (KopieSektor kopieSektor in kopieSegmentToSektorDict[kopieSegment])
                {
                    UpdateSektor(segment, kopieSektor, kopieSektor.Operation);
                }

                if (ReferenceUpdater != null)
                {
                    ReferenceUpdater.AfterCreateSegment(segment);
                }

                statistics.NumSegment.Inserts++;
                return(segment);
            }
            }
            return(null);
        }
Example #6
0
        public void BeforeUpdateSegment(AchsenSegment targetSegment, KopieAchse kopieAchse, KopieAchsenSegment kopieSegment)
        {
            DateTime oldVersionValidFrom = oldAxisValidFromDict[targetSegment.Achse.BsId];
            DateTime newVersionValidFrom = kopieAchse.VersionValidFrom;


            if (targetSegment.AchsenReferenzen.Count > 0)
            {
                foreach (AchsenReferenz achsRef in new List <AchsenReferenz>(targetSegment.AchsenReferenzen))
                {
                    ILineString oldRefGeometry     = (ILineString)achsRef.Shape;
                    ILineString newSegmentGeometry = GeometryUtils.ConvertMLineStringTo2D(gf, (MLineString)kopieSegment.Shape);

                    GeometryTransformer gt = new GeometryTransformer(oldRefGeometry, newSegmentGeometry);

                    GeometryTransformerResult result = gt.Transform();

                    switch (result.ResultState)
                    {
                    case GeometryTransformerResultState.Success:
                    {
                        achsRef.Shape = result.NewRefGeometry;
                        Register(achsRef);
                        statistics.UpdatedReferences++;
                        break;
                    }

                    case GeometryTransformerResultState.FailedWouldBeOutside:
                    {
                        RegisterConflict(achsRef, CreateConflict(AchsenUpdateConflict.CONFLICTTYPE_PARTIAL_REFERENCE_OUTSIDE, targetSegment.Id, oldRefGeometry));
                        RemoveReference(achsRef);
                        statistics.DeletedReferences++;
                        break;
                    }

                    case GeometryTransformerResultState.FailedWouldBeTooShort:
                    {
                        RegisterConflict(achsRef, CreateConflict(AchsenUpdateConflict.CONFLICTTYPE_PARTIAL_REFERENCE_TOOSHORT, targetSegment.Id, oldRefGeometry));
                        RemoveReference(achsRef);
                        statistics.DeletedReferences++;
                        break;
                    }
                    }
                }
            }
        }