Exemple #1
0
        public async Task ImportForeignAcTransLineCktCondTypes(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt)
        {
            AcTransLineCircuitCondTypeExtract    acTransLineCktCondExtract      = new AcTransLineCircuitCondTypeExtract();
            List <AcTransLineCktCondTypeForeign> acTransLineCktCondTypesForeign = acTransLineCktCondExtract.ExtractAcTransLineCktCondTypeForeign(oracleConnStr);

            LoadAcTransLineCktCondType loadAcTransLineCktCond = new LoadAcTransLineCktCondType();

            foreach (AcTransLineCktCondTypeForeign acTransLineCktCondTypeForeign in acTransLineCktCondTypesForeign)
            {
                AcTransLineCkt insertedAcTransLineCkt = await loadAcTransLineCktCond.LoadSingleAsync(_context, _log, acTransLineCktCondTypeForeign, opt);
            }
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public async Task <AcTransLineCktOwner> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, AcTransmissionLineCircuitOwnerForeign acCktOwnerForeign, EntityWriteOption opt)
        {
            // check if entity already exists
            AcTransLineCktOwner existingAcCktOwner = await _context.AcTransLineCktOwners.SingleOrDefaultAsync(aco => aco.WebUatId == acCktOwnerForeign.WebUatId);

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

            // find the AcTranLineCkt via the AcTranLineCkt WebUatId
            int            acCktWebUatId = acCktOwnerForeign.AcTranLineCktWebUatId;
            AcTransLineCkt acTransCkt    = await _context.AcTransLineCkts.SingleOrDefaultAsync(ss => ss.WebUatId == acCktWebUatId);

            // if AcTransLineCkt doesnot exist, skip the import. Ideally, there should not be such case
            if (acTransCkt == null)
            {
                _log.LogCritical($"Could not find AcTransLineCkt with WebUatId {acCktWebUatId} in warehouse while creating AcTransLineCktOwner with WebUat Id {acCktOwnerForeign.WebUatId}");
                return(null);
            }

            // find the Owner of the AcTransLineCkt via the Owner WebUatId
            int   ownerWebUatId = acCktOwnerForeign.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($"Could not find Owner with WebUatId {ownerWebUatId} in warehouse while creating AcTransLineCktOwner with WebUat Id {acCktOwnerForeign.WebUatId}");
                return(null);
            }

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

            // if entity is not present, then insert or check if we have to replace the entity completely
            if (existingAcCktOwner == null || (opt == EntityWriteOption.Replace && existingAcCktOwner != null))
            {
                AcTransLineCktOwner acCktOwner = new AcTransLineCktOwner();
                acCktOwner.OwnerId          = owner.OwnerId;
                acCktOwner.AcTransLineCktId = acTransCkt.AcTransLineCktId;
                acCktOwner.WebUatId         = acCktOwnerForeign.WebUatId;

                _context.AcTransLineCktOwners.Add(acCktOwner);
                await _context.SaveChangesAsync();

                return(acCktOwner);
            }


            // check if we have to modify the entity
            if (opt == EntityWriteOption.Modify && existingAcCktOwner != null)
            {
                existingAcCktOwner.OwnerId          = owner.OwnerId;
                existingAcCktOwner.AcTransLineCktId = acTransCkt.AcTransLineCktId;
                await _context.SaveChangesAsync();

                return(existingAcCktOwner);
            }
            return(null);
        }
Exemple #5
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);
        }
Exemple #6
0
        public async Task <Fsc> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, FscForeign fscForeign, EntityWriteOption opt)
        {
            // check if entity already exists
            Fsc existingFsc = await _context.Fscs.SingleOrDefaultAsync(lr => lr.WebUatId == fscForeign.WebUatId);

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

            // find the Substation via the SubstationWebUatId
            int        substationWebUatId = fscForeign.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 Fsc with webUatId {fscForeign.WebUatId} and name {fscForeign.Name}");
                return(null);
            }

            // find the State via the State WebUatId
            int   stateWebUatId = fscForeign.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 Fsc with webUatId {fscForeign.WebUatId} and name {fscForeign.Name}");
                return(null);
            }

            int            cktWebUatId = fscForeign.AcTransLineCktWebUatId;
            AcTransLineCkt ckt         = await _context.AcTransLineCkts.SingleOrDefaultAsync(v => v.WebUatId == cktWebUatId);

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

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

            // if entity is not present, then insert or check if we have to replace the entity completely
            if (existingFsc == null || (opt == EntityWriteOption.Replace && existingFsc != null))
            {
                Fsc newFsc = new Fsc();
                newFsc.Name                = fscForeign.Name;
                newFsc.AcTransLineCktId    = ckt.AcTransLineCktId;
                newFsc.SubstationId        = substation.SubstationId;
                newFsc.StateId             = state.StateId;
                newFsc.PercComp            = fscForeign.PercComp;
                newFsc.LineReactance       = fscForeign.LineReactance;
                newFsc.CapacitiveReactance = fscForeign.CapacitiveReactance;
                newFsc.RatedMvarPhase      = fscForeign.RatedMvarPhase;
                newFsc.RatedCurrentAmps    = fscForeign.RatedCurrentAmps;
                newFsc.CommDate            = fscForeign.CommDate;
                newFsc.CodDate             = fscForeign.CodDate;
                newFsc.DeCommDate          = fscForeign.DeCommDate;
                newFsc.WebUatId            = fscForeign.WebUatId;
                _context.Fscs.Add(newFsc);
                await _context.SaveChangesAsync();

                return(newFsc);
            }

            // check if we have to modify the entity
            if (opt == EntityWriteOption.Modify && existingFsc != null)
            {
                existingFsc.Name                = fscForeign.Name;
                existingFsc.AcTransLineCktId    = ckt.AcTransLineCktId;
                existingFsc.SubstationId        = substation.SubstationId;
                existingFsc.StateId             = state.StateId;
                existingFsc.PercComp            = fscForeign.PercComp;
                existingFsc.LineReactance       = fscForeign.LineReactance;
                existingFsc.CapacitiveReactance = fscForeign.CapacitiveReactance;
                existingFsc.RatedMvarPhase      = fscForeign.RatedMvarPhase;
                existingFsc.RatedCurrentAmps    = fscForeign.RatedCurrentAmps;
                existingFsc.CommDate            = fscForeign.CommDate;
                existingFsc.CodDate             = fscForeign.CodDate;
                existingFsc.DeCommDate          = fscForeign.DeCommDate;
                await _context.SaveChangesAsync();

                return(existingFsc);
            }
            return(null);
        }