Exemplo n.º 1
0
 protected void CloneSektorAttributesWithoutId(KopieSektor targetItem, IImportedSektor importedSektor)
 {
     targetItem.Km           = importedSektor.Km;
     targetItem.Name         = importedSektor.SectorName;
     targetItem.SectorLength = importedSektor.SectorLength;
     targetItem.Sequence     = importedSektor.Sequence;
     targetItem.MarkerGeom   = importedSektor.MarkerGeom;
     targetItem.SegmentId    = importedSektor.SegmentId;
     targetItem.Operation    = importedSektor.Operation;
 }
Exemplo n.º 2
0
        private Sektor findSektor(AchsenSegment achsenSegment, KopieSektor kopieSektor)
        {
            var list = achsenSegment.Sektoren.Where(o => o.BsId == kopieSektor.Id);

            if (list.Count() == 0)
            {
                list = achsenCache.SelectMany(a => a.Value.AchsenSegmente).SelectMany(s => s.Sektoren).Where(se => se.BsId == kopieSektor.Id);
                if (!list.Any())
                {
                    return(null);
                }
            }
            return(list.First());
        }
Exemplo n.º 3
0
        ///// 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();
        }
Exemplo n.º 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);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private Sektor UpdateSektor(AchsenSegment achsenSegment, KopieSektor kopieSektor, int operation)
        {
            if (kopieSektor.ImpNr <= lastImpNr)
            {
                return(null);
            }

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

            switch (operation)
            {
            case AxisImportOperation.DELETE:
            {
                Sektor sektor =
                    findSektor(achsenSegment, kopieSektor);

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

                achsenSegment.Sektoren.Remove(sektor);
                session.Delete(sektor);

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

            case AxisImportOperation.UPDATE:
            {
                Sektor sektor =
                    findSektor(achsenSegment, kopieSektor);

                if (sektor == null)
                {
                    return(UpdateSektor(achsenSegment, kopieSektor, AxisImportOperation.INSERT));
                }
                sektor = gisKopieMappingEngine.Translate <KopieSektor, Sektor>(kopieSektor, sektor);

                statistics.NumSector.Updates++;
                return(sektor);
            }

            case AxisImportOperation.INSERT:
            {
                if (findSektor(achsenSegment, kopieSektor) != null)
                {
                    throw new Exception("Cannot insert: KopieSektor " + kopieSektor.Id + " already exists in Sektor Table!");
                }

                Sektor sektor = gisKopieMappingEngine.Translate <KopieSektor, Sektor>(kopieSektor);
                sektor.BsId          = kopieSektor.Id;
                sektor.AchsenSegment = achsenSegment;
                achsenSegment.Sektoren.Add(sektor);

                statistics.NumSector.Inserts++;
                return(sektor);
            }
            }
            return(null);
        }