public async Task <State> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, StateForeign stateForeign, EntityWriteOption opt) { // check if entity already exists State existingState = await _context.States.SingleOrDefaultAsync(r => r.WebUatId == stateForeign.WebUatId); // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingState != null) { return(existingState); } // find the region of the state via the region WebUatId int regionWebUatId = stateForeign.RegionWebUatId; Region stateRegion = await _context.Regions.SingleOrDefaultAsync(r => r.WebUatId == regionWebUatId); // if region doesnot exist, skip the import. Ideally, there should not be such case if (stateRegion == null) { _log.LogCritical($"Unable to find region with webUatId {regionWebUatId} while inserting state with webUatId {stateForeign.WebUatId} and name {stateForeign.FullName}"); return(null); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingState != null) { _context.States.Remove(existingState); } // if region is not present, then insert or check if we have to replace the entity completely if (existingState == null || (opt == EntityWriteOption.Replace && existingState != null)) { State newState = new State(); newState.FullName = stateForeign.FullName; newState.ShortName = stateForeign.ShortName; newState.RegionId = stateRegion.RegionId; newState.WebUatId = stateForeign.WebUatId; _context.States.Add(newState); await _context.SaveChangesAsync(); return(newState); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingState != null) { existingState.FullName = stateForeign.FullName; existingState.ShortName = stateForeign.ShortName; existingState.RegionId = stateRegion.RegionId; await _context.SaveChangesAsync(); return(existingState); } return(null); }
public async Task ImportForeignCompensatorTypes(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { CompensatorTypeExtract compensatorTypeExtract = new CompensatorTypeExtract(); List <CompensatorType> compensatorTypes = compensatorTypeExtract.ExtractCompensatorTypes(oracleConnStr); LoadCompensatorType loadCompensatorType = new LoadCompensatorType(); foreach (CompensatorType compensatorType in compensatorTypes) { CompensatorType insertedCompensatorType = await loadCompensatorType.LoadSingleAsync(_context, _log, compensatorType, opt); } }
public async Task <CompensatorOwner> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, CompensatorOwnerForeign compensatorOwnerForeign, EntityWriteOption opt) { // check if entity already exists CompensatorOwner existingCompensatorOwner = await _context.CompensatorOwners.SingleOrDefaultAsync(cO => cO.WebUatId == compensatorOwnerForeign.WebUatId); // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingCompensatorOwner != null) { return(existingCompensatorOwner); } // find the Compensator via the Compensator WebUatId int compensatorWebUatId = compensatorOwnerForeign.CompensatorWebUatId; Compensator compensator = await _context.Compensators.SingleOrDefaultAsync(c => c.WebUatId == compensatorWebUatId); // if Compensator doesnot exist, skip the import. Ideally, there should not be such case if (compensator == null) { _log.LogCritical($"Unable to find Compensator with webUatId {compensatorWebUatId} while inserting CompensatorOwner with webUatId {compensatorOwnerForeign.WebUatId}"); return(null); } // find the Owner of the Compensator via the Owner WebUatId int ownerWebUatId = compensatorOwnerForeign.OwnerWebUatId; Owner owner = await _context.Owners.SingleOrDefaultAsync(o => o.WebUatId == ownerWebUatId); // if owner doesnot exist, skip the import. Ideally, there should not be such case if (owner == null) { _log.LogCritical($"Unable to find Owner with webUatId {ownerWebUatId} while inserting CompensatorOwner with webUatId {compensatorOwnerForeign.WebUatId}"); return(null); } try { // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingCompensatorOwner != null) { _context.CompensatorOwners.Remove(existingCompensatorOwner); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingCompensatorOwner == null || (opt == EntityWriteOption.Replace && existingCompensatorOwner != null)) { CompensatorOwner newCompensatorOwner = new CompensatorOwner(); newCompensatorOwner.OwnerId = owner.OwnerId; newCompensatorOwner.CompensatorId = compensator.CompensatorId; newCompensatorOwner.WebUatId = compensatorOwnerForeign.WebUatId; _context.CompensatorOwners.Add(newCompensatorOwner); await _context.SaveChangesAsync(); return(newCompensatorOwner); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingCompensatorOwner != null) { existingCompensatorOwner.OwnerId = owner.OwnerId; existingCompensatorOwner.CompensatorId = compensator.CompensatorId; await _context.SaveChangesAsync(); return(existingCompensatorOwner); } } catch (DbUpdateException e) { _log.LogCritical($"Error occured while inserting CompensatorOwner with webUatId {compensatorOwnerForeign.WebUatId}, owner id {owner.OwnerId} and compensatorId {compensator.CompensatorId}"); _log.LogCritical($"EntityWriteOption = {opt.ToString()}"); _log.LogCritical($"{e.Message}"); return(null); } return(null); }
public async Task <AcTransLineCkt> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, AcTransLineCktCondTypeForeign acLineCondTypeForeign, EntityWriteOption opt) { // get the conductor type of the entity ConductorType condType = await _context.ConductorTypes.SingleOrDefaultAsync(ct => ct.WebUatId == acLineCondTypeForeign.CondTypeWebUatId); // if conductor type doesnot exist, skip the import. Ideally, there should not be such case if (condType == null) { _log.LogCritical($"Unable to find ConductorType with webUatId {acLineCondTypeForeign.CondTypeWebUatId} while inserting AcTransLineCktCondType with webUatId {acLineCondTypeForeign.WebUatId}"); return(null); } // get the ac transmission line ckt of the entity AcTransLineCkt existingAcTransLineCkt = await _context.AcTransLineCkts.SingleOrDefaultAsync(acCkt => acCkt.WebUatId == acLineCondTypeForeign.AcTransLineCktWebUatId); // if ac transmission line ckt doesnot exist, skip the import. Ideally, there should not be such case if (existingAcTransLineCkt == null) { _log.LogCritical($"Unable to find AcTransLineCkt with webUatId {acLineCondTypeForeign.AcTransLineCktWebUatId} while inserting AcTransLineCktCondType with webUatId {acLineCondTypeForeign.WebUatId}"); return(null); } // check if we should not modify existing conductor type if (existingAcTransLineCkt.ConductorTypeId.HasValue && opt == EntityWriteOption.DontReplace) { return(existingAcTransLineCkt); } // if conductor type is not present, then insert or replace conductor type if (!existingAcTransLineCkt.ConductorTypeId.HasValue || opt == EntityWriteOption.Replace || opt == EntityWriteOption.Modify) { existingAcTransLineCkt.ConductorTypeId = condType.ConductorTypeId; await _context.SaveChangesAsync(); return(existingAcTransLineCkt); } return(null); }
public async Task ImportForeignBusReactorOwners(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { BusReactorOwnerExtract brOwnerExtract = new BusReactorOwnerExtract(); List <BusReactorOwnerForeign> brOwnersForeign = brOwnerExtract.ExtractBusReactorOwnersForeign(oracleConnStr); LoadBusReactorOwner loadBrOwner = new LoadBusReactorOwner(); foreach (BusReactorOwnerForeign brOwnerForeign in brOwnersForeign) { BusReactorOwner insertedBrOwner = await loadBrOwner.LoadSingleAsync(_context, _log, brOwnerForeign, opt); } }
public async Task ImportForeignHvdcLineCktOwners(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { HvdcLineCktOwnerExtract hvdcLineCktOwnerExtract = new HvdcLineCktOwnerExtract(); List <HvdcLineCktOwnerForeign> hvdcLineCktOwnerForeignList = hvdcLineCktOwnerExtract.ExtractHvdcLineCktOwnersForeign(oracleConnStr); LoadHvdcLineCktOwner loadHvdcLineCktOwner = new LoadHvdcLineCktOwner(); foreach (HvdcLineCktOwnerForeign cktOwnerForeign in hvdcLineCktOwnerForeignList) { HvdcLineCktOwner insertedCktOwner = await loadHvdcLineCktOwner.LoadSingleAsync(_context, _log, cktOwnerForeign, opt); } }
public async Task ImportForeignLineReactorOwners(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { LineReactorOwnerExtract lrOwnerExtract = new LineReactorOwnerExtract(); List <LineReactorOwnerForeign> lrOwnersForeign = lrOwnerExtract.ExtractLineReactorOwnersForeign(oracleConnStr); LoadLineReactorOwner loadLrOwner = new LoadLineReactorOwner(); foreach (LineReactorOwnerForeign lrOwnerForeign in lrOwnersForeign) { LineReactorOwner insertedLrOwner = await loadLrOwner.LoadSingleAsync(_context, _log, lrOwnerForeign, opt); } }
public async Task <Fuel> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, Fuel fuel, EntityWriteOption opt) { // check if entity already exists Fuel existingFuel = await _context.Fuels.SingleOrDefaultAsync(r => r.WebUatId == fuel.WebUatId); // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingFuel != null) { _context.Fuels.Remove(existingFuel); } // check if entity is not present or check if we have to replace the entity completely if (existingFuel == null || (opt == EntityWriteOption.Replace && existingFuel != null)) { _context.Fuels.Add(fuel); await _context.SaveChangesAsync(); return(fuel); } // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingFuel != null) { return(existingFuel); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingFuel != null) { existingFuel.Name = fuel.Name; await _context.SaveChangesAsync(); return(existingFuel); } return(null); }
public async Task <Compensator> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, CompensatorForeign compensatorForeign, EntityWriteOption opt) { // check if entity already exists Compensator existingCompensator = await _context.Compensators.SingleOrDefaultAsync(lr => lr.WebUatId == compensatorForeign.WebUatId); // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingCompensator != null) { return(existingCompensator); } // find the CompensatorType via the CompensatorTypeWebUatId int compTypeWebUatId = compensatorForeign.CompensatorTypeWebUatId; CompensatorType compType = await _context.CompensatorTypes.SingleOrDefaultAsync(ct => ct.WebUatId == compTypeWebUatId); // if CompensatorType doesnot exist, skip the import. Ideally, there should not be such case if (compType == null) { _log.LogCritical($"Unable to find CompensatorType with webUatId {compTypeWebUatId} while inserting Compensator with webUatId {compensatorForeign.WebUatId} and name {compensatorForeign.Name}"); return(null); } // find the Substation via the SubstationWebUatId int substationWebUatId = compensatorForeign.SubstationWebUatId; Substation substation = await _context.Substations.SingleOrDefaultAsync(ss => ss.WebUatId == substationWebUatId); // if Substation doesnot exist, skip the import. Ideally, there should not be such case if (substation == null) { _log.LogCritical($"Unable to find Substation with webUatId {substationWebUatId} while inserting Compensator with webUatId {compensatorForeign.WebUatId} and name {compensatorForeign.Name}"); return(null); } // find the State via the State WebUatId int stateWebUatId = compensatorForeign.StateWebUatId; State state = await _context.States.SingleOrDefaultAsync(s => s.WebUatId == stateWebUatId); // if state doesnot exist, skip the import. Ideally, there should not be such case if (state == null) { _log.LogCritical($"Unable to find state with webUatId {stateWebUatId} while inserting Compensator with webUatId {compensatorForeign.WebUatId} and name {compensatorForeign.Name}"); return(null); } // find the attachElement Id of the Compensator int attachElementId = -1; int attachElementType = compensatorForeign.AttachElementType; int attachElementWebUatId = compensatorForeign.AttachElementWebUatId; if (attachElementType == 1) { // attach element is a bus attachElementId = (await _context.Buses.SingleOrDefaultAsync(b => b.WebUatId == attachElementWebUatId)).BusId; } else if (attachElementType == 2) { // attach element is an AC Transmission line attachElementId = (await _context.AcTransLineCkts.SingleOrDefaultAsync(b => b.WebUatId == attachElementWebUatId)).AcTransLineCktId; } else { // encountered an unknown attach element type, ideally this should not happen _log.LogCritical($"Encountered an unknown attach element type {attachElementType} while inserting Compensator with webUatId {compensatorForeign.WebUatId} and name {compensatorForeign.Name}"); return(null); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingCompensator != null) { _context.Compensators.Remove(existingCompensator); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingCompensator == null || (opt == EntityWriteOption.Replace && existingCompensator != null)) { Compensator newCompensator = new Compensator(); newCompensator.Name = compensatorForeign.Name; newCompensator.CompensatorTypeId = compType.CompensatorTypeId; newCompensator.SubstationId = substation.SubstationId; newCompensator.StateId = state.StateId; newCompensator.AttachElementType = compensatorForeign.AttachElementType; newCompensator.AttachElementId = attachElementId; newCompensator.CompensatorNumber = compensatorForeign.CompensatorNumber.ToString(); newCompensator.PercVariableComp = compensatorForeign.PercVariableComp; newCompensator.PercFixedComp = compensatorForeign.PercFixedComp; newCompensator.LineReactanceOhms = compensatorForeign.LineReactanceOhms; newCompensator.CommDate = compensatorForeign.CommDate; newCompensator.CodDate = compensatorForeign.CodDate; newCompensator.DeCommDate = compensatorForeign.DeCommDate; newCompensator.WebUatId = compensatorForeign.WebUatId; _context.Compensators.Add(newCompensator); await _context.SaveChangesAsync(); return(newCompensator); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingCompensator != null) { existingCompensator.Name = compensatorForeign.Name; existingCompensator.CompensatorTypeId = compType.CompensatorTypeId; existingCompensator.SubstationId = substation.SubstationId; existingCompensator.StateId = state.StateId; existingCompensator.AttachElementType = compensatorForeign.AttachElementType; existingCompensator.AttachElementId = attachElementId; existingCompensator.CompensatorNumber = compensatorForeign.CompensatorNumber.ToString(); existingCompensator.PercVariableComp = compensatorForeign.PercVariableComp; existingCompensator.PercFixedComp = compensatorForeign.PercFixedComp; existingCompensator.LineReactanceOhms = compensatorForeign.LineReactanceOhms; existingCompensator.CommDate = compensatorForeign.CommDate; existingCompensator.CodDate = compensatorForeign.CodDate; existingCompensator.DeCommDate = compensatorForeign.DeCommDate; await _context.SaveChangesAsync(); return(existingCompensator); } return(null); }
public async Task ImportForeignBayTypes(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { BayTypeExtract bayTypeExtract = new BayTypeExtract(); List <BayType> bayTypes = bayTypeExtract.ExtractBays(oracleConnStr); LoadBayType loadBayType = new LoadBayType(); foreach (BayType bayType in bayTypes) { BayType insertedBayType = await loadBayType.LoadSingleAsync(_context, _log, bayType, opt); } }
public async Task <Region> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, Region region, EntityWriteOption opt) { // check if entity already exists Region existingRegion = await _context.Regions.SingleOrDefaultAsync(r => r.WebUatId == region.WebUatId); // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingRegion != null) { _context.Regions.Remove(existingRegion); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingRegion == null || (opt == EntityWriteOption.Replace && existingRegion != null)) { _context.Regions.Add(region); await _context.SaveChangesAsync(); return(region); } // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingRegion != null) { return(existingRegion); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingRegion != null) { existingRegion.FullName = region.FullName; existingRegion.ShortName = region.ShortName; await _context.SaveChangesAsync(); return(existingRegion); } return(null); }
public async Task ImportForeignHvdcPoles(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { HvdcPoleExtract hvdcPoleExtract = new HvdcPoleExtract(); List <HvdcPoleForeign> hvdcPoleForeignList = hvdcPoleExtract.ExtractHvdcPoleForeign(oracleConnStr); LoadHvdcPole loadHvdcPole = new LoadHvdcPole(); foreach (HvdcPoleForeign lineForeign in hvdcPoleForeignList) { HvdcPole insertedPole = await loadHvdcPole.LoadSingleAsync(_context, _log, lineForeign, opt); } }
public async Task <Owner> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, Owner owner, EntityWriteOption opt) { // check if entity already exists Owner existingOwner = await _context.Owners.SingleOrDefaultAsync(o => o.WebUatId == owner.WebUatId); // if region is not present, then insert if (existingOwner == null) { _context.Owners.Add(owner); await _context.SaveChangesAsync(); return(owner); } // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingOwner != null) { return(existingOwner); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingOwner != null) { _context.Owners.Remove(existingOwner); _context.Owners.Add(owner); await _context.SaveChangesAsync(); return(owner); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingOwner != null) { existingOwner.Name = owner.Name; await _context.SaveChangesAsync(); return(existingOwner); } return(null); }
public async Task <Transformer> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, TransformerForeign trForeign, EntityWriteOption opt) { // check if entity already exists Transformer existingTr = await _context.Transformers.SingleOrDefaultAsync(tr => tr.WebUatId == trForeign.WebUatId); // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingTr != null) { return(existingTr); } // check if substation type is valid string ssTypeSubstation = "SubStation"; string ssTypeGenStation = "Generating Station"; if (!(trForeign.StationType == ssTypeSubstation || trForeign.StationType == ssTypeGenStation)) { _log.LogCritical($"substation type is not {ssTypeSubstation} or {ssTypeGenStation} while inserting Transformer with webUatId {trForeign.WebUatId} and name {trForeign.Name}"); return(null); } MajorSubstation hvSubstation = null; int hvSubstationWebUatId = -1; if (trForeign.StationType == ssTypeSubstation) { // The transformer is in Substation hvSubstationWebUatId = trForeign.HVStationWebUatId; hvSubstation = await _context.MajorSubstations.SingleOrDefaultAsync(hvss => hvss.WebUatId == hvSubstationWebUatId); if (hvSubstation == null) { _log.LogCritical($"Unable to find MajorSubstation with webUatId {hvSubstationWebUatId} while inserting Transformer with webUatId {trForeign.WebUatId} and name {trForeign.Name}"); return(null); } } GeneratingStation hvGenStation = null; int hvGenstationWebUatId = -1; if (trForeign.StationType == ssTypeGenStation) { // The transformer is in GeneratingStation hvGenstationWebUatId = trForeign.HVStationWebUatId; hvGenStation = await _context.GeneratingStations.SingleOrDefaultAsync(hvgt => hvgt.WebUatId == hvGenstationWebUatId); if (hvGenStation == null) { _log.LogCritical($"Unable to find GeneratingStation with webUatId {hvGenstationWebUatId} while inserting Transformer with webUatId {trForeign.WebUatId} and name {trForeign.Name}"); return(null); } } // find the HV Voltage of the Transformer via the Voltage WebUatId int hvVoltWebUatId = trForeign.HighVoltLevelWebUatId; VoltLevel hvVolt = await _context.VoltLevels.SingleOrDefaultAsync(vl => vl.WebUatId == hvVoltWebUatId); // if voltage level doesnot exist, skip the import. Ideally, there should not be such case if (hvVolt == null) { _log.LogCritical($"Unable to find HV VoltLevel with webUatId {hvVoltWebUatId} while inserting Transformer with webUatId {trForeign.WebUatId} and name {trForeign.Name}"); return(null); } // find the LV Voltage of the Transformer via the Voltage WebUatId int lvVoltWebUatId = trForeign.LowVoltLevelWebUatId; VoltLevel lvVolt = await _context.VoltLevels.SingleOrDefaultAsync(vl => vl.WebUatId == lvVoltWebUatId); // if voltage level doesnot exist, skip the import. Ideally, there should not be such case if (lvVolt == null) { _log.LogCritical($"Unable to find LV VoltLevel with webUatId {lvVoltWebUatId} while inserting Transformer with webUatId {trForeign.WebUatId} and name {trForeign.Name}"); // uncomment this after vendor complies for non null LV voltage types // return null; } // find the State of the substation via the State WebUatId int stateWebUatId = trForeign.StateWebUatId; State state = await _context.States.SingleOrDefaultAsync(s => s.WebUatId == stateWebUatId); // if state doesnot exist, skip the import. Ideally, there should not be such case if (state == null) { _log.LogCritical($"Unable to find State with webUatId {stateWebUatId} while inserting Transformer with webUatId {trForeign.WebUatId} and name {trForeign.Name}"); return(null); } // find the TransformerType of the Transformer via the TransformerTypeWebUatId int trTypeWebUatId = trForeign.TransTypeWebUatId; TransformerType trType = await _context.TransformerTypes.SingleOrDefaultAsync(trt => trt.WebUatId == trTypeWebUatId); // if TransformerType doesnot exist, skip the import. Ideally, there should not be such case if (trType == null) { _log.LogCritical($"Unable to find TransformerType with webUatId {trTypeWebUatId} while inserting Transformer with webUatId {trForeign.WebUatId} and name {trForeign.Name}"); return(null); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingTr != null) { _context.Transformers.Remove(existingTr); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingTr == null || (opt == EntityWriteOption.Replace && existingTr != null)) { Transformer newTr = new Transformer(); newTr.Name = trForeign.Name; newTr.StationType = trForeign.StationType; newTr.HighVoltLevelId = hvVolt.VoltLevelId; if (lvVolt != null) { newTr.LowVoltLevelId = lvVolt.VoltLevelId; } newTr.TransformerNumber = trForeign.TransformerNumber; newTr.TransformerTypeId = trType.TransformerTypeId; newTr.StateId = state.StateId; newTr.MVACapacity = trForeign.MVACapacity; newTr.CodDate = trForeign.CodDate; newTr.CommDate = trForeign.CommDate; newTr.DecommDate = trForeign.DecommDate; newTr.WebUatId = trForeign.WebUatId; if (trForeign.StationType == ssTypeSubstation) { newTr.HvSubstationId = hvSubstation.MajorSubstationId; } else if (trForeign.StationType == ssTypeGenStation) { newTr.HvGeneratingStationId = hvGenStation.GeneratingStationId; } _context.Transformers.Add(newTr); await _context.SaveChangesAsync(); return(newTr); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingTr != null) { existingTr.Name = trForeign.Name; existingTr.StationType = trForeign.StationType; existingTr.HighVoltLevelId = hvVolt.VoltLevelId; if (lvVolt != null) { existingTr.LowVoltLevelId = lvVolt.VoltLevelId; } existingTr.TransformerNumber = trForeign.TransformerNumber; existingTr.TransformerTypeId = trType.TransformerTypeId; existingTr.StateId = state.StateId; existingTr.MVACapacity = trForeign.MVACapacity; existingTr.CodDate = trForeign.CodDate; existingTr.CommDate = trForeign.CommDate; existingTr.DecommDate = trForeign.DecommDate; if (trForeign.StationType == ssTypeSubstation) { existingTr.HvSubstationId = hvSubstation.MajorSubstationId; } else if (trForeign.StationType == ssTypeGenStation) { existingTr.HvGeneratingStationId = hvGenStation.GeneratingStationId; } await _context.SaveChangesAsync(); return(existingTr); } return(null); }
public async Task <BusReactorOwner> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, BusReactorOwnerForeign brOwnerForeign, EntityWriteOption opt) { // check if entity already exists BusReactorOwner existingBrOwner = await _context.BusReactorOwners.SingleOrDefaultAsync(brO => brO.WebUatId == brOwnerForeign.WebUatId); // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingBrOwner != null) { return(existingBrOwner); } // find the BusReactor via the BusReactorWebUatId int brWebUatId = brOwnerForeign.BusReactorWebUatId; BusReactor busReactor = await _context.BusReactors.SingleOrDefaultAsync(br => br.WebUatId == brWebUatId); // if BusReactor doesnot exist, skip the import. Ideally, there should not be such case if (busReactor == null) { _log.LogCritical($"Unable to find BusReactor with webUatId {brWebUatId} while inserting BusReactorOwner with webUatId {brOwnerForeign.WebUatId}"); return(null); } // find the Owner of the substation via the Owner WebUatId int ownerWebUatId = brOwnerForeign.OwnerWebUatId; Owner owner = await _context.Owners.SingleOrDefaultAsync(o => o.WebUatId == ownerWebUatId); // if owner doesnot exist, skip the import. Ideally, there should not be such case if (owner == null) { _log.LogCritical($"Unable to find Owner with webUatId {ownerWebUatId} while inserting BusReactorOwner with webUatId {brOwnerForeign.WebUatId}"); return(null); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingBrOwner != null) { _context.BusReactorOwners.Remove(existingBrOwner); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingBrOwner == null || (opt == EntityWriteOption.Replace && existingBrOwner != null)) { BusReactorOwner newBrOwner = new BusReactorOwner(); newBrOwner.OwnerId = owner.OwnerId; newBrOwner.BusReactorId = busReactor.BusReactorId; newBrOwner.WebUatId = brOwnerForeign.WebUatId; _context.BusReactorOwners.Add(newBrOwner); await _context.SaveChangesAsync(); return(newBrOwner); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingBrOwner != null) { existingBrOwner.OwnerId = owner.OwnerId; existingBrOwner.BusReactorId = busReactor.BusReactorId; await _context.SaveChangesAsync(); return(existingBrOwner); } return(null); }
public async Task ImportForeignGenClassifications(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { GeneratorClassificationExtract genClassificationExtract = new GeneratorClassificationExtract(); List <GeneratorClassification> genClassifications = genClassificationExtract.ExtractGeneratorClassifications(oracleConnStr); LoadGeneratorClassification loadGenClassification = new LoadGeneratorClassification(); foreach (GeneratorClassification genClassification in genClassifications) { GeneratorClassification insertedGenClassification = await loadGenClassification.LoadSingleAsync(_context, _log, genClassification, opt); } }
public async Task ImportForeignTransformerTypes(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { TransformerTypeExtract transTypeExtract = new TransformerTypeExtract(); List <TransformerType> transTypes = transTypeExtract.ExtractTransformerTypes(oracleConnStr); LoadTransformerType loadTrType = new LoadTransformerType(); foreach (TransformerType trType in transTypes) { TransformerType insertedTrType = await loadTrType.LoadSingleAsync(_context, _log, trType, opt); } }
public async Task <LineReactor> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, LineReactorForeign lrForeign, EntityWriteOption opt) { // check if entity already exists LineReactor existingLr = await _context.LineReactors.SingleOrDefaultAsync(lr => lr.WebUatId == lrForeign.WebUatId); // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingLr != null) { return(existingLr); } // find the Substation of the LineReactor via the Substation WebUatId int ssWebUatId = lrForeign.SubstationWebUatId; Substation substation = await _context.Substations.SingleOrDefaultAsync(ss => ss.WebUatId == ssWebUatId); // if Substation doesnot exist, skip the import. Ideally, there should not be such case if (substation == null) { _log.LogCritical($"Unable to find Substation with webUatId {ssWebUatId} while inserting LineReactor with webUatId {lrForeign.WebUatId} and name {lrForeign.Name}"); return(null); } // find the AcTransLineCkt of the LineReactor via the AcTransLineCkt WebUatId int lineCktWebUatId = lrForeign.AcTransLineCktWebUatId; AcTransLineCkt acCkt = await _context.AcTransLineCkts.SingleOrDefaultAsync(ckt => ckt.WebUatId == lineCktWebUatId); // if AcTransLineCkt doesnot exist, skip the import. Ideally, there should not be such case if (acCkt == null) { _log.LogCritical($"Unable to find AcTransLineCkt with webUatId {lineCktWebUatId} while inserting LineReactor with webUatId {lrForeign.WebUatId} and name {lrForeign.Name}"); return(null); } // find the State of the LineReactor via the State WebUatId int stateWebUatId = lrForeign.StateWebUatId; State state = await _context.States.SingleOrDefaultAsync(s => s.WebUatId == stateWebUatId); // if state doesnot exist, skip the import. Ideally, there should not be such case if (state == null) { _log.LogCritical($"Unable to find State with webUatId {stateWebUatId} while inserting LineReactor with webUatId {lrForeign.WebUatId} and name {lrForeign.Name}"); return(null); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingLr != null) { _context.LineReactors.Remove(existingLr); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingLr == null || (opt == EntityWriteOption.Replace && existingLr != null)) { LineReactor newLr = new LineReactor(); newLr.Name = lrForeign.Name; newLr.MvarCapacity = lrForeign.MvarCapacity; newLr.CommDate = lrForeign.CommDate; newLr.CodDate = lrForeign.CodDate; newLr.DecommDate = lrForeign.DecommDate; newLr.AcTransLineCktId = acCkt.AcTransLineCktId; newLr.SubstationId = substation.SubstationId; newLr.StateId = substation.StateId; newLr.IsConvertible = lrForeign.IsConvertible == 0 ? false : true; newLr.IsSwitchable = lrForeign.IsSwitchable == 0 ? false : true; newLr.WebUatId = lrForeign.WebUatId; _context.LineReactors.Add(newLr); await _context.SaveChangesAsync(); return(newLr); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingLr != null) { existingLr.Name = lrForeign.Name; existingLr.MvarCapacity = lrForeign.MvarCapacity; existingLr.CommDate = lrForeign.CommDate; existingLr.CodDate = lrForeign.CodDate; existingLr.DecommDate = lrForeign.DecommDate; existingLr.AcTransLineCktId = acCkt.AcTransLineCktId; existingLr.SubstationId = substation.SubstationId; existingLr.StateId = substation.StateId; existingLr.IsConvertible = lrForeign.IsConvertible == 0 ? false : true; existingLr.IsSwitchable = lrForeign.IsSwitchable == 0 ? false : true; await _context.SaveChangesAsync(); return(existingLr); } return(null); }
public async Task <SubstationOwner> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, SubstationOwnerForeign ssOwnerForeign, EntityWriteOption opt) { // check if entity already exists SubstationOwner existingSSOwner = await _context.SubstationOwners.SingleOrDefaultAsync(ssO => ssO.WebUatId == ssOwnerForeign.WebUatId); // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingSSOwner != null) { return(existingSSOwner); } // find the Substation via the Substation WebUatId int ssWebUatId = ssOwnerForeign.SubstationWebUatId; Substation substation = await _context.Substations.SingleOrDefaultAsync(ss => ss.WebUatId == ssWebUatId); // if Substation doesnot exist, skip the import. Ideally, there should not be such case if (substation == null) { _log.LogCritical($"Unable to find Substation with webUatId {ssWebUatId} while inserting SubstationOwner with webUatId {ssOwnerForeign.WebUatId}"); return(null); } // find the Owner of the substation via the Owner WebUatId int ownerWebUatId = ssOwnerForeign.OwnerWebUatId; Owner owner = await _context.Owners.SingleOrDefaultAsync(o => o.WebUatId == ownerWebUatId); // if owner doesnot exist, skip the import. Ideally, there should not be such case if (owner == null) { _log.LogCritical($"Unable to find Owner with webUatId {ownerWebUatId} while inserting SubstationOwner with webUatId {ssOwnerForeign.WebUatId}"); return(null); } try { // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingSSOwner != null) { _context.SubstationOwners.Remove(existingSSOwner); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingSSOwner == null || (opt == EntityWriteOption.Replace && existingSSOwner != null)) { SubstationOwner newSSOwner = new SubstationOwner(); newSSOwner.OwnerId = owner.OwnerId; newSSOwner.SubstationId = substation.SubstationId; newSSOwner.WebUatId = ssOwnerForeign.WebUatId; _context.SubstationOwners.Add(newSSOwner); await _context.SaveChangesAsync(); return(newSSOwner); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingSSOwner != null) { existingSSOwner.OwnerId = owner.OwnerId; existingSSOwner.SubstationId = substation.SubstationId; await _context.SaveChangesAsync(); return(existingSSOwner); } } catch (DbUpdateException e) { _log.LogCritical($"Error occured while inserting SubstationOwner with webUatId {ssOwnerForeign.WebUatId}, owner id {owner.OwnerId} and ssId {substation.SubstationId}"); _log.LogCritical($"EntityWriteOption = {opt.ToString()}"); _log.LogCritical($"{e.Message}"); return(null); } return(null); }
public async Task <GeneratorUnit> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, GeneratorUnitForeign genUnitForeign, EntityWriteOption opt) { // check if entity already exists GeneratorUnit existingGenUnit = await _context.GeneratorUnits.SingleOrDefaultAsync(r => r.WebUatId == genUnitForeign.WebUatId); // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingGenUnit != null) { return(existingGenUnit); } // find the GeneratingStation of the unit via the GeneratingStationWebUatId int generatingStationWebUatId = genUnitForeign.GeneratingStationWebUatId; GeneratingStation genStation = await _context.GeneratingStations.SingleOrDefaultAsync(r => r.WebUatId == generatingStationWebUatId); // if genStation doesnot exist, skip the import. Ideally, there should not be such case if (genStation == null) { _log.LogCritical($"Could not find GeneratingStation with WebUatId {generatingStationWebUatId} in warehouse while creating GeneratorUnit with WebUat Id {genUnitForeign.WebUatId} and name {genUnitForeign.Name}"); return(null); } // find the GeneratorStage of the unit via the GeneratingStationWebUatId int generatorStageWebUatId = genUnitForeign.GeneratorStageWebUatId; GeneratorStage genStage = await _context.GeneratorStages.SingleOrDefaultAsync(r => r.WebUatId == generatorStageWebUatId); // if genStage doesnot exist, skip the import. Ideally, there should not be such case if (genStage == null) { _log.LogCritical($"Could not find GeneratorStage with WebUatId {generatorStageWebUatId} in warehouse while creating GeneratorUnit with WebUat Id {genUnitForeign.WebUatId} and name {genUnitForeign.Name}"); return(null); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingGenUnit != null) { _context.GeneratorUnits.Remove(existingGenUnit); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingGenUnit == null || (opt == EntityWriteOption.Replace && existingGenUnit != null)) { GeneratorUnit newGenUnit = new GeneratorUnit(); newGenUnit.Name = genUnitForeign.Name; newGenUnit.GeneratingStationId = genStation.GeneratingStationId; newGenUnit.GeneratorStageId = genStage.GeneratorStageId; newGenUnit.UnitNumber = genUnitForeign.UnitNumber.ToString(); newGenUnit.GenVoltageKV = genUnitForeign.GenVoltageKV; newGenUnit.GenHighVoltageKV = genUnitForeign.GenHighVoltageKV; newGenUnit.MvaCapacity = genUnitForeign.MvaCapacity; newGenUnit.InstalledCapacity = genUnitForeign.InstalledCapacity; newGenUnit.CodDateTime = genUnitForeign.CodDateTime; newGenUnit.CommDateTime = genUnitForeign.CommDateTime; newGenUnit.DeCommDateTime = genUnitForeign.DeCommDateTime; newGenUnit.WebUatId = genUnitForeign.WebUatId; _context.GeneratorUnits.Add(newGenUnit); await _context.SaveChangesAsync(); return(newGenUnit); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingGenUnit != null) { existingGenUnit.Name = genUnitForeign.Name; existingGenUnit.GeneratingStationId = genStation.GeneratingStationId; existingGenUnit.GeneratorStageId = genStage.GeneratorStageId; existingGenUnit.UnitNumber = genUnitForeign.UnitNumber.ToString(); existingGenUnit.GenVoltageKV = genUnitForeign.GenVoltageKV; existingGenUnit.GenHighVoltageKV = genUnitForeign.GenHighVoltageKV; existingGenUnit.MvaCapacity = genUnitForeign.MvaCapacity; existingGenUnit.InstalledCapacity = genUnitForeign.InstalledCapacity; existingGenUnit.CodDateTime = genUnitForeign.CodDateTime; existingGenUnit.CommDateTime = genUnitForeign.CommDateTime; existingGenUnit.DeCommDateTime = genUnitForeign.DeCommDateTime; await _context.SaveChangesAsync(); return(existingGenUnit); } return(null); }
public async Task <TransformerType> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, TransformerType transType, EntityWriteOption opt) { // check if entity already exists TransformerType existingTrType = await _context.TransformerTypes.SingleOrDefaultAsync(trT => trT.WebUatId == transType.WebUatId); // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingTrType != null) { _context.TransformerTypes.Remove(existingTrType); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingTrType == null || (opt == EntityWriteOption.Replace && existingTrType != null)) { _context.TransformerTypes.Add(transType); await _context.SaveChangesAsync(); return(transType); } // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingTrType != null) { return(existingTrType); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingTrType != null) { existingTrType.Name = transType.Name; await _context.SaveChangesAsync(); return(existingTrType); } return(null); }
public async Task ImportForeignTransformers(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { TransformerExtract trExtract = new TransformerExtract(); List <TransformerForeign> trForeignList = trExtract.ExtractTransformersForeign(oracleConnStr); LoadTransformer loadTr = new LoadTransformer(); foreach (TransformerForeign trForeign in trForeignList) { Transformer insertedTr = await loadTr.LoadSingleAsync(_context, _log, trForeign, opt); } }
public async Task ImportForeignGeneratorUnits(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { GeneratorUnitExtract genUnitExtract = new GeneratorUnitExtract(); List <GeneratorUnitForeign> genUnitsForeign = genUnitExtract.ExtractGeneratorUnitsForeign(oracleConnStr); LoadGeneratorUnit loadGenUnit = new LoadGeneratorUnit(); foreach (GeneratorUnitForeign genUnitForeign in genUnitsForeign) { GeneratorUnit insertedGenUnit = await loadGenUnit.LoadSingleAsync(_context, _log, genUnitForeign, opt); } }
public async Task ImportForeignGenerationTypes(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { GenerationTypeExtract genTypeExtract = new GenerationTypeExtract(); List <GenerationType> genTypes = genTypeExtract.ExtractGenTypes(oracleConnStr); LoadGenerationType loadGenType = new LoadGenerationType(); foreach (GenerationType genType in genTypes) { GenerationType insertedGenType = await loadGenType.LoadSingleAsync(_context, _log, genType, opt); } }
public async Task <Voltage> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, VoltageForeign volForeign, EntityWriteOption opt) { // check if entity already exists Voltage existingSSVoltage = await _context.Voltage.SingleOrDefaultAsync(ss => ss.WebUatId == volForeign.WebUatId); //Entity name which is Voltage here should be decide // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingSS != null) { return(existingSSVoltage); } //Find the associated SubStation by SubstationId int assSubStationId = volForeign.AssSubstationWebUatId; Substation assSubstation = await _context.Substation.SingleOrDefaultAsync(ass => ass.WebUatId == assSubStationId); // if Associated Substation doesnot exist, skip the import. Ideally, there should not be such case if (assSubstation == null) { _log.LogCritical($"Unable to find AssociatedSubstation with webUatId {assSubStationId} while inserting Substation with webUatId {volForeign.WebUatId} "); return(null); } // if entity is not present, then insert if (existingSSVoltage == null) { Voltage newVoltage = new Voltage(); newVoltage.VoltageId = volForeign.WebUatId; newVoltage.SubstationId = volForeign.AssSubstationWebUatId; newVoltage.Date = volForeign.Date; newVoltage.Time = volForeign.Time; newVoltage.VoltageValue = volForeign.Voltage; newVoltage.Substation = assSubstation; _context.Voltage.Add(newVoltage); await _context.SaveChangesAsync(); return(newVoltage); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingSSVoltage != null) { _context.Voltage.Remove(existingSSVoltage); Voltage newVoltage = new Voltage(); newVoltage.VoltageId = volForeign.WebUatId; newVoltage.SubstationId = volForeign.AssSubstationWebUatId; newVoltage.Date = volForeign.Date; newVoltage.Time = volForeign.Time; newVoltage.VoltageValue = volForeign.Voltage; newVoltage.Substation = assSubstation; _context.Voltage.Add(newVoltage); await _context.SaveChangesAsync(); return(newVoltage); } // check if we have to modify the entity completely if (opt == EntityWriteOption.Modify && existingSSVoltage != null) { existingSSVoltage.VoltageId = volForeign.WebUatId; existingSSVoltage.SubstationId = volForeign.AssSubstationWebUatId; existingSSVoltage.Date = volForeign.Date; existingSSVoltage.Time = volForeign.Time; existingSSVoltage.VoltageValue = volForeign.Voltage; existingSSVoltage.Substation = assSubstation; await _context.SaveChangesAsync(); return(existingSS); } return(null); }
public async Task <GeneratorClassification> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, GeneratorClassification genClassification, EntityWriteOption opt) { // check if entity already exists GeneratorClassification existingGenClassification = await _context.GeneratorClassifications.SingleOrDefaultAsync(gc => gc.WebUatId == genClassification.WebUatId); // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingGenClassification != null) { _context.GeneratorClassifications.Remove(existingGenClassification); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingGenClassification == null || (opt == EntityWriteOption.Replace && existingGenClassification != null)) { _context.GeneratorClassifications.Add(genClassification); await _context.SaveChangesAsync(); return(genClassification); } // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingGenClassification != null) { return(existingGenClassification); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingGenClassification != null) { existingGenClassification.Name = genClassification.Name; await _context.SaveChangesAsync(); return(existingGenClassification); } return(null); }
public async Task <FilterBank> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, FilterBankForeign fbForeign, EntityWriteOption opt) { // check if entity already exists FilterBank existingFb = await _context.FilterBanks.SingleOrDefaultAsync(lr => lr.WebUatId == fbForeign.WebUatId); // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingFb != null) { return(existingFb); } // find the region int regionWebUatId = fbForeign.RegionWebUatId; Region region = await _context.Regions.SingleOrDefaultAsync(r => r.WebUatId == regionWebUatId); // if region doesnot exist, skip the import. Ideally, there should not be such case if (region == null) { _log.LogCritical($"Unable to find region with webUatId {regionWebUatId} while inserting FilterBank with webUatId {fbForeign.WebUatId} and name {fbForeign.Name}"); return(null); } // find the State of the LineReactor via the State WebUatId int stateWebUatId = fbForeign.StateWebUatId; State state = await _context.States.SingleOrDefaultAsync(s => s.WebUatId == stateWebUatId); // if state doesnot exist, skip the import. Ideally, there should not be such case if (state == null) { _log.LogCritical($"Unable to find State with webUatId {stateWebUatId} while inserting FilterBank with webUatId {fbForeign.WebUatId} and name {fbForeign.Name}"); return(null); } // find the Substation of the LineReactor via the Substation WebUatId int ssWebUatId = fbForeign.SubstationWebUatId; Substation substation = await _context.Substations.SingleOrDefaultAsync(ss => ss.WebUatId == ssWebUatId); // if Substation doesnot exist, skip the import. Ideally, there should not be such case if (substation == null) { _log.LogCritical($"Unable to find Substation with webUatId {ssWebUatId} while inserting FilterBank with webUatId {fbForeign.WebUatId} and name {fbForeign.Name}"); return(null); } int voltLevelWebUatId = fbForeign.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 FilterBank with webUatId {fbForeign.WebUatId} and name {fbForeign.Name}"); return(null); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingFb != null) { _context.FilterBanks.Remove(existingFb); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingFb == null || (opt == EntityWriteOption.Replace && existingFb != null)) { FilterBank newFb = new FilterBank(); newFb.Name = fbForeign.Name; newFb.RegionId = region.RegionId; newFb.StateId = state.StateId; newFb.SubstationId = substation.SubstationId; newFb.VoltLevelId = voltLevel.VoltLevelId; newFb.IsSwitchable = fbForeign.IsSwitchable == 0 ? false : true; newFb.FilterBankNumber = fbForeign.FilterBankNumber.ToString(); newFb.WebUatId = fbForeign.WebUatId; _context.FilterBanks.Add(newFb); await _context.SaveChangesAsync(); return(newFb); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingFb != null) { existingFb.Name = fbForeign.Name; existingFb.RegionId = region.RegionId; existingFb.StateId = state.StateId; existingFb.SubstationId = substation.SubstationId; existingFb.VoltLevelId = voltLevel.VoltLevelId; existingFb.IsSwitchable = fbForeign.IsSwitchable == 0 ? false : true; existingFb.FilterBankNumber = fbForeign.FilterBankNumber.ToString(); await _context.SaveChangesAsync(); return(existingFb); } return(null); }
public async Task ImportForeignVoltageLevels(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { VoltLevelExtract voltLevelExtract = new VoltLevelExtract(); List <VoltLevel> voltLevels = voltLevelExtract.ExtractVoltageLevels(oracleConnStr); LoadVoltageLevel loadVoltageLevel = new LoadVoltageLevel(); foreach (VoltLevel voltLevel in voltLevels) { VoltLevel insertedVolt = await loadVoltageLevel.LoadSingleAsync(_context, _log, voltLevel, opt); } }
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); }
public async Task ImportForeignOwners(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { OwnerExtract ownerExtract = new OwnerExtract(); List <Owner> owners = ownerExtract.ExtractOwners(oracleConnStr); LoadOwner loadOwner = new LoadOwner(); foreach (Owner owner in owners) { Owner insertedOwner = await loadOwner.LoadSingleAsync(_context, _log, owner, opt); } }