Beispiel #1
0
        public async Task ImportForeignAcTransLines(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt)
        {
            AcTransLineExtract acTransLineExtract = new AcTransLineExtract();
            List <AcTransmissionLineForeign> acTransLinesForeign = acTransLineExtract.ExtractAcTransLineForeign(oracleConnStr);

            LoadAcTransmissionLine loadAcTransLine = new LoadAcTransmissionLine();

            foreach (AcTransmissionLineForeign acTransLineForeign in acTransLinesForeign)
            {
                AcTransmissionLine insertedAcTransLine = await loadAcTransLine.LoadSingleAsync(_context, _log, acTransLineForeign, opt);
            }
        }
Beispiel #2
0
        public async Task <AcTransmissionLine> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, AcTransmissionLineForeign acTrForeign, EntityWriteOption opt)
        {
            // check if entity already exists
            AcTransmissionLine existingAcTrLine = await _context.AcTransmissionLines.SingleOrDefaultAsync(acTr => acTr.WebUatId == acTrForeign.WebUatId);

            // check if we should not modify existing entity
            if (opt == EntityWriteOption.DontReplace && existingAcTrLine != null)
            {
                return(existingAcTrLine);
            }

            // find the from Substation via FromSubstattion WebUatId
            int        fromSSebUatId = acTrForeign.FromSSWebUatId;
            Substation fromSS        = await _context.Substations.SingleOrDefaultAsync(ss => ss.WebUatId == fromSSebUatId);

            // if FromSubstation doesnot exist, skip the import. Ideally, there should not be such case
            if (fromSS == null)
            {
                _log.LogCritical($"Unable to find FromSubstation with webUatId {fromSSebUatId} while inserting AcTransmissionLine with webUatId {acTrForeign.WebUatId} and name {acTrForeign.Name}");
                return(null);
            }

            // find the To Substation via ToSubstattion WebUatId
            int        toSSebUatId = acTrForeign.ToSSWebUatId;
            Substation toSS        = await _context.Substations.SingleOrDefaultAsync(ss => ss.WebUatId == toSSebUatId);

            // if ToSubstation doesnot exist, skip the import. Ideally, there should not be such case
            if (toSS == null)
            {
                _log.LogCritical($"Unable to find ToSubstation with webUatId {toSSebUatId} while inserting AcTransmissionLine with webUatId {acTrForeign.WebUatId} and name {acTrForeign.Name}");
                return(null);
            }

            // find the Voltage of the substation via the Voltage WebUatId
            int       voltWebUatId = acTrForeign.VoltLevelWebUatId;
            VoltLevel voltLevel    = await _context.VoltLevels.SingleOrDefaultAsync(vl => vl.WebUatId == voltWebUatId);

            // if voltage level doesnot exist, skip the import. Ideally, there should not be such case
            if (voltLevel == null)
            {
                _log.LogCritical($"Unable to find VoltLevel with webUatId {voltWebUatId} while inserting AcTransmissionLine with webUatId {acTrForeign.WebUatId} and name {acTrForeign.Name}");
                return(null);
            }

            // check if we have to replace the entity completely
            if (opt == EntityWriteOption.Replace && existingAcTrLine != null)
            {
                _context.AcTransmissionLines.Remove(existingAcTrLine);
            }

            // if entity is not present, then insert or check if we have to replace the entity completely
            if (existingAcTrLine == null || (opt == EntityWriteOption.Replace && existingAcTrLine != null))
            {
                AcTransmissionLine newAcTrLine = new AcTransmissionLine();
                newAcTrLine.Name             = acTrForeign.Name;
                newAcTrLine.VoltLevelId      = voltLevel.VoltLevelId;
                newAcTrLine.FromSubstationId = fromSS.SubstationId;
                newAcTrLine.ToSubstationId   = toSS.SubstationId;
                newAcTrLine.WebUatId         = acTrForeign.WebUatId;

                _context.AcTransmissionLines.Add(newAcTrLine);
                await _context.SaveChangesAsync();

                return(newAcTrLine);
            }

            // check if we have to modify the entity
            if (opt == EntityWriteOption.Modify && existingAcTrLine != null)
            {
                existingAcTrLine.Name             = acTrForeign.Name;
                existingAcTrLine.VoltLevelId      = voltLevel.VoltLevelId;
                existingAcTrLine.FromSubstationId = fromSS.SubstationId;
                existingAcTrLine.ToSubstationId   = toSS.SubstationId;
                await _context.SaveChangesAsync();

                return(existingAcTrLine);
            }
            return(null);
        }
Beispiel #3
0
        public async Task <AcTransLineCkt> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, AcTransmissionLineCircuitForeign acTrLineCktForeign, EntityWriteOption opt)
        {
            // check if entity already exists
            AcTransLineCkt existingAcTrLineCkt = await _context.AcTransLineCkts.SingleOrDefaultAsync(acCkt => acCkt.WebUatId == acTrLineCktForeign.WebUatId);

            // check if we should not modify existing entity
            if (opt == EntityWriteOption.DontReplace && existingAcTrLineCkt != null)
            {
                return(existingAcTrLineCkt);
            }

            // find the from AcTransmissionLine via FromSubstattion WebUatId
            int acTransLineWebUatId     = acTrLineCktForeign.AcTransLineWebUatId;
            AcTransmissionLine acTrLine = await _context.AcTransmissionLines.SingleOrDefaultAsync(atl => atl.WebUatId == acTransLineWebUatId);

            // if AcTransmissionLine doesnot exist, skip the import. Ideally, there should not be such case
            if (acTrLine == null)
            {
                _log.LogCritical($"Unable to find AcTransmissionLine with webUatId {acTransLineWebUatId} while inserting AcTransLineCkt with webUatId {acTrLineCktForeign.WebUatId} and name {acTrLineCktForeign.Name}");
                return(null);
            }

            // check if we have to replace the entity completely
            if (opt == EntityWriteOption.Replace && existingAcTrLineCkt != null)
            {
                _context.AcTransLineCkts.Remove(existingAcTrLineCkt);
            }

            // if entity is not present, then insert or check if we have to replace the entity completely
            if (existingAcTrLineCkt == null || (opt == EntityWriteOption.Replace && existingAcTrLineCkt != null))
            {
                AcTransLineCkt newAcTrLineCkt = new AcTransLineCkt();
                newAcTrLineCkt.Name = acTrLineCktForeign.Name;
                newAcTrLineCkt.AcTransmissionLineId = acTrLine.AcTransmissionLineId;
                newAcTrLineCkt.CktNumber            = acTrLineCktForeign.CktNumber.ToString();
                newAcTrLineCkt.CODDate            = acTrLineCktForeign.CODDate;
                newAcTrLineCkt.CommDate           = acTrLineCktForeign.CommDate;
                newAcTrLineCkt.DeCommDate         = acTrLineCktForeign.DeCommDate;
                newAcTrLineCkt.FtcDate            = acTrLineCktForeign.FtcDate;
                newAcTrLineCkt.Length             = acTrLineCktForeign.Length;
                newAcTrLineCkt.SIL                = acTrLineCktForeign.SIL;
                newAcTrLineCkt.ThermalLimitMVA    = acTrLineCktForeign.ThermalLimitMVA;
                newAcTrLineCkt.TrialOperationDate = acTrLineCktForeign.TrialOperationDate;
                newAcTrLineCkt.WebUatId           = acTrLineCktForeign.WebUatId;

                _context.AcTransLineCkts.Add(newAcTrLineCkt);
                await _context.SaveChangesAsync();

                return(newAcTrLineCkt);
            }

            // check if we have to modify the entity
            if (opt == EntityWriteOption.Modify && existingAcTrLineCkt != null)
            {
                existingAcTrLineCkt.Name = acTrLineCktForeign.Name;
                existingAcTrLineCkt.AcTransmissionLineId = acTrLine.AcTransmissionLineId;
                existingAcTrLineCkt.CktNumber            = acTrLineCktForeign.CktNumber.ToString();
                existingAcTrLineCkt.CODDate            = acTrLineCktForeign.CODDate;
                existingAcTrLineCkt.CommDate           = acTrLineCktForeign.CommDate;
                existingAcTrLineCkt.DeCommDate         = acTrLineCktForeign.DeCommDate;
                existingAcTrLineCkt.FtcDate            = acTrLineCktForeign.FtcDate;
                existingAcTrLineCkt.Length             = acTrLineCktForeign.Length;
                existingAcTrLineCkt.SIL                = acTrLineCktForeign.SIL;
                existingAcTrLineCkt.ThermalLimitMVA    = acTrLineCktForeign.ThermalLimitMVA;
                existingAcTrLineCkt.TrialOperationDate = acTrLineCktForeign.TrialOperationDate;
                await _context.SaveChangesAsync();

                return(existingAcTrLineCkt);
            }
            return(null);
        }