Ejemplo n.º 1
0
        public async Task ImportForeignHvdcLines(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt)
        {
            HvdcLineExtract        hvdcLineExtract     = new HvdcLineExtract();
            List <HvdcLineForeign> hvdcLineForeignList = hvdcLineExtract.ExtractHvdcLineForeign(oracleConnStr);

            LoadHvdcLine loadHvdcLine = new LoadHvdcLine();

            foreach (HvdcLineForeign lineForeign in hvdcLineForeignList)
            {
                HvdcLine insertedLine = await loadHvdcLine.LoadSingleAsync(_context, _log, lineForeign, opt);
            }
        }
Ejemplo n.º 2
0
        public async Task <HvdcLineCkt> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, HvdcLineCktForeign hvdcLineCktForeign, EntityWriteOption opt)
        {
            // check if entity already exists
            HvdcLineCkt existingHvdcLineCkt = await _context.HvdcLineCkts.SingleOrDefaultAsync(ckt => ckt.WebUatId == hvdcLineCktForeign.WebUatId);

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

            // find the HvdcLine of the HvdcLineCkt via the State hvdcLineWebUatId
            int      hvdcLineWebUatId = hvdcLineCktForeign.HvdcLineWebUatId;
            HvdcLine hvdcLine         = await _context.HvdcLines.SingleOrDefaultAsync(hl => hl.WebUatId == hvdcLineWebUatId);

            // if HvdcLine doesnot exist, skip the import. Ideally, there should not be such case
            if (hvdcLine == null)
            {
                _log.LogCritical($"Unable to find HvdcLine with webUatId {hvdcLineWebUatId} while inserting HvdcLineCkt with webUatId {hvdcLineCktForeign.WebUatId} and name {hvdcLineCktForeign.Name}");
                return(null);
            }

            // find the FromBus of the HvdcLineCkt via the FromBusWebUatId
            int fromBusWebUatId = hvdcLineCktForeign.FromBusWebUatId;
            Bus fromBus         = await _context.Buses.SingleOrDefaultAsync(b => b.WebUatId == fromBusWebUatId);

            // if FromBus doesnot exist, skip the import. Ideally, there should not be such case
            if (fromBus == null)
            {
                _log.LogCritical($"Unable to find FromBus with webUatId {fromBusWebUatId} while inserting HvdcLineCkt with webUatId {hvdcLineCktForeign.WebUatId} and name {hvdcLineCktForeign.Name}");
                return(null);
            }

            // find the TomBus of the HvdcLineCkt via the ToBusWebUatId
            int toBusWebUatId = hvdcLineCktForeign.ToBusWebUatId;
            Bus toBus         = await _context.Buses.SingleOrDefaultAsync(b => b.WebUatId == toBusWebUatId);

            // if ToBus doesnot exist, skip the import. Ideally, there should not be such case
            if (toBus == null)
            {
                _log.LogCritical($"Unable to find ToBus with webUatId {toBusWebUatId} while inserting HvdcLineCkt with webUatId {hvdcLineCktForeign.WebUatId} and name {hvdcLineCktForeign.Name}");
                return(null);
            }

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

            // if entity is not present, then insert or check if we have to replace the entity completely
            if (existingHvdcLineCkt == null || (opt == EntityWriteOption.Replace && existingHvdcLineCkt != null))
            {
                HvdcLineCkt newHvdcLineCkt = new HvdcLineCkt();
                newHvdcLineCkt.Name                = hvdcLineCktForeign.Name;
                newHvdcLineCkt.CktNumber           = hvdcLineCktForeign.CktNumber.ToString();
                newHvdcLineCkt.HvdcLineId          = hvdcLine.HvdcLineId;
                newHvdcLineCkt.FromBusId           = fromBus.BusId;
                newHvdcLineCkt.ToBusId             = toBus.BusId;
                newHvdcLineCkt.NumConductorsPerCkt = hvdcLineCktForeign.NumConductorsPerCkt;
                newHvdcLineCkt.Length              = hvdcLineCktForeign.Length;
                newHvdcLineCkt.ThermalLimitMVA     = hvdcLineCktForeign.ThermalLimitMVA;
                newHvdcLineCkt.FtcDate             = hvdcLineCktForeign.FtcDate;
                newHvdcLineCkt.TrialOperationDate  = hvdcLineCktForeign.TrialOperationDate;
                newHvdcLineCkt.CommDate            = hvdcLineCktForeign.CommDate;
                newHvdcLineCkt.CodDate             = hvdcLineCktForeign.CodDate;
                newHvdcLineCkt.DeCommDate          = hvdcLineCktForeign.DeCommDate;

                newHvdcLineCkt.WebUatId = hvdcLineCktForeign.WebUatId;
                _context.HvdcLineCkts.Add(newHvdcLineCkt);
                await _context.SaveChangesAsync();

                return(newHvdcLineCkt);
            }

            // check if we have to modify the entity
            if (opt == EntityWriteOption.Modify && existingHvdcLineCkt != null)
            {
                existingHvdcLineCkt.Name                = hvdcLineCktForeign.Name;
                existingHvdcLineCkt.CktNumber           = hvdcLineCktForeign.CktNumber.ToString();
                existingHvdcLineCkt.HvdcLineId          = hvdcLine.HvdcLineId;
                existingHvdcLineCkt.FromBusId           = fromBus.BusId;
                existingHvdcLineCkt.ToBusId             = toBus.BusId;
                existingHvdcLineCkt.NumConductorsPerCkt = hvdcLineCktForeign.NumConductorsPerCkt;
                existingHvdcLineCkt.Length              = hvdcLineCktForeign.Length;
                existingHvdcLineCkt.ThermalLimitMVA     = hvdcLineCktForeign.ThermalLimitMVA;
                existingHvdcLineCkt.FtcDate             = hvdcLineCktForeign.FtcDate;
                existingHvdcLineCkt.TrialOperationDate  = hvdcLineCktForeign.TrialOperationDate;
                existingHvdcLineCkt.CommDate            = hvdcLineCktForeign.CommDate;
                existingHvdcLineCkt.CodDate             = hvdcLineCktForeign.CodDate;
                existingHvdcLineCkt.DeCommDate          = hvdcLineCktForeign.DeCommDate; await _context.SaveChangesAsync();

                return(existingHvdcLineCkt);
            }
            return(null);
        }
Ejemplo n.º 3
0
        public async Task <HvdcLine> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, HvdcLineForeign hvdcLineForeign, EntityWriteOption opt)
        {
            // check if entity already exists
            HvdcLine existingHvdcLine = await _context.HvdcLines.SingleOrDefaultAsync(lr => lr.WebUatId == hvdcLineForeign.WebUatId);

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

            // find the FromSubstation via the FromSSWebUatId
            int        fromSSWebUatId = hvdcLineForeign.FromSSWebUatId;
            Substation fromSS         = await _context.Substations.SingleOrDefaultAsync(ss => ss.WebUatId == fromSSWebUatId);

            // 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 {fromSSWebUatId} while inserting HvdcLine with webUatId {hvdcLineForeign.WebUatId} and name {hvdcLineForeign.Name}");
                return(null);
            }

            // find the ToSubstation via the ToSSWebUatId
            int        toSSWebUatId = hvdcLineForeign.ToSSWebUatId;
            Substation toSS         = await _context.Substations.SingleOrDefaultAsync(ss => ss.WebUatId == toSSWebUatId);

            // 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 {toSSWebUatId} while inserting HvdcLine with webUatId {hvdcLineForeign.WebUatId} and name {hvdcLineForeign.Name}");
                return(null);
            }

            // find the FromState via the State WebUatId
            int   fromStateWebUatId = hvdcLineForeign.FromStateWebUatId;
            State fromState         = await _context.States.SingleOrDefaultAsync(s => s.WebUatId == fromStateWebUatId);

            // if state doesnot exist, skip the import. Ideally, there should not be such case
            if (fromState == null)
            {
                _log.LogCritical($"Unable to find FromState with webUatId {fromStateWebUatId} while inserting HvdcLine with webUatId {hvdcLineForeign.WebUatId} and name {hvdcLineForeign.Name}");
                return(null);
            }

            // find the ToState via the State WebUatId
            int   toStateWebUatId = hvdcLineForeign.ToStateWebUatId;
            State toState         = await _context.States.SingleOrDefaultAsync(s => s.WebUatId == toStateWebUatId);

            // if toState doesnot exist, skip the import. Ideally, there should not be such case
            if (toState == null)
            {
                _log.LogCritical($"Unable to find ToState with webUatId {toStateWebUatId} while inserting HvdcLine with webUatId {hvdcLineForeign.WebUatId} and name {hvdcLineForeign.Name}");
                return(null);
            }

            int       voltLevelWebUatId = hvdcLineForeign.VoltLevelWebUatId;
            VoltLevel voltLevel         = await _context.VoltLevels.SingleOrDefaultAsync(v => v.WebUatId == voltLevelWebUatId);

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

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

            // if entity is not present, then insert or check if we have to replace the entity completely
            if (existingHvdcLine == null || (opt == EntityWriteOption.Replace && existingHvdcLine != null))
            {
                HvdcLine newHvdcLine = new HvdcLine();
                newHvdcLine.Name             = hvdcLineForeign.Name;
                newHvdcLine.FromStateId      = fromState.StateId;
                newHvdcLine.ToStateId        = toState.StateId;
                newHvdcLine.FromSubstationId = fromSS.SubstationId;
                newHvdcLine.ToSubstationId   = toSS.SubstationId;
                newHvdcLine.VoltLevelId      = voltLevel.VoltLevelId;
                newHvdcLine.WebUatId         = hvdcLineForeign.WebUatId;
                _context.HvdcLines.Add(newHvdcLine);
                await _context.SaveChangesAsync();

                return(newHvdcLine);
            }

            // check if we have to modify the entity
            if (opt == EntityWriteOption.Modify && existingHvdcLine != null)
            {
                existingHvdcLine.Name             = hvdcLineForeign.Name;
                existingHvdcLine.FromStateId      = fromState.StateId;
                existingHvdcLine.ToStateId        = toState.StateId;
                existingHvdcLine.FromSubstationId = fromSS.SubstationId;
                existingHvdcLine.ToSubstationId   = toSS.SubstationId;
                existingHvdcLine.VoltLevelId      = voltLevel.VoltLevelId;
                await _context.SaveChangesAsync();

                return(existingHvdcLine);
            }
            return(null);
        }