Exemple #1
0
        public async Task <GeneratorStage> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, GeneratorStageForeign genStageForeign, EntityWriteOption opt)
        {
            // check if entity already exists
            GeneratorStage existingGenStage = await _context.GeneratorStages.SingleOrDefaultAsync(r => r.WebUatId == genStageForeign.WebUatId);

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

            // find the GeneratingStation of the state via the region WebUatId
            int generatingStationWebUatId = genStageForeign.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 GeneratorStage with WebUat Id {genStageForeign.WebUatId} and name {genStageForeign.Name}");
                return(null);
            }

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

            // if entity is not present, then insert or check if we have to replace the entity completely
            if (existingGenStage == null || (opt == EntityWriteOption.Replace && existingGenStage != null))
            {
                GeneratorStage newGenStage = new GeneratorStage();
                newGenStage.Name = genStageForeign.Name;
                newGenStage.GeneratingStationId = genStation.GeneratingStationId;
                newGenStage.WebUatId            = genStageForeign.WebUatId;

                _context.GeneratorStages.Add(newGenStage);
                await _context.SaveChangesAsync();

                return(newGenStage);
            }

            // check if we have to modify the entity
            if (opt == EntityWriteOption.Modify && existingGenStage != null)
            {
                existingGenStage.Name = genStageForeign.Name;
                existingGenStage.GeneratingStationId = genStation.GeneratingStationId;
                await _context.SaveChangesAsync();

                return(existingGenStage);
            }
            return(null);
        }
Exemple #2
0
        public async Task ImportForeignGeneratingStations(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt)
        {
            GeneratingStationExtract        genStationExtract  = new GeneratingStationExtract();
            List <GeneratingStationForeign> genStationsForeign = genStationExtract.ExtractGeneratingStationsForeign(oracleConnStr);

            LoadGeneratingStation loadGenStation = new LoadGeneratingStation();

            foreach (GeneratingStationForeign genStationForeign in genStationsForeign)
            {
                GeneratingStation insertedGenStation = await loadGenStation.LoadSingleAsync(_context, _log, genStationForeign, opt);
            }
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public async Task <GeneratingStationOwner> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, GeneratingStationOwnerForeign genStationOwnerForeign, EntityWriteOption opt)
        {
            // check if entity already exists
            GeneratingStationOwner existingGenStationOwner = await _context.GeneratingStationOwners.SingleOrDefaultAsync(gso => gso.WebUatId == genStationOwnerForeign.WebUatId);

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

            // find the GeneratingStation via the GeneratingStation WebUatId
            int genStationWebUatId       = genStationOwnerForeign.GeneratingStationWebUatId;
            GeneratingStation genStation = await _context.GeneratingStations.SingleOrDefaultAsync(gs => gs.WebUatId == genStationWebUatId);

            // if GeneratingStation doesnot exist, skip the import. Ideally, there should not be such case
            if (genStation == null)
            {
                _log.LogCritical($"Unable to find GeneratingStation with webUatId {genStationWebUatId} while inserting GeneratingStationOwner with webUatId {genStationOwnerForeign.WebUatId}");
                return(null);
            }

            // find the Owner of the substation via the Owner WebUatId
            int   ownerWebUatId = genStationOwnerForeign.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 GeneratingStationOwner with webUatId {genStationOwnerForeign.WebUatId}");
                return(null);
            }

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

            // if entity is not present, then insert or check if we have to replace the entity completely
            if (existingGenStationOwner == null || (opt == EntityWriteOption.Replace && existingGenStationOwner != null))
            {
                GeneratingStationOwner genStationOwner = new GeneratingStationOwner();
                genStationOwner.OwnerId             = owner.OwnerId;
                genStationOwner.GeneratingStationId = genStation.GeneratingStationId;
                genStationOwner.WebUatId            = genStationOwnerForeign.WebUatId;

                _context.GeneratingStationOwners.Add(genStationOwner);
                await _context.SaveChangesAsync();

                return(genStationOwner);
            }

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

                return(existingGenStationOwner);
            }
            return(null);
        }
Exemple #6
0
        public async Task <GeneratingStation> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, GeneratingStationForeign genStationForeign, EntityWriteOption opt)
        {
            // check if entity already exists
            GeneratingStation existingGenStation = await _context.GeneratingStations.SingleOrDefaultAsync(ss => ss.WebUatId == genStationForeign.WebUatId);

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

            // find the GeneratorClassification of the substation via the GenClassification WebUatId
            int genClassificationWebUatId             = genStationForeign.GenClassificationWebUatId;
            GeneratorClassification genClassification = await _context.GeneratorClassifications.SingleOrDefaultAsync(gc => gc.WebUatId == genClassificationWebUatId);

            // if GeneratorClassification doesnot exist, skip the import. Ideally, there should not be such case
            if (genClassification == null)
            {
                _log.LogCritical($"Could not find GeneratorClassification with WebUatId {genClassificationWebUatId} in warehouse while creating Generating Station with WebUat Id {genStationForeign.WebUatId} and name {genStationForeign.Name}");
                return(null);
            }

            // find the Generation Type of the substation via the Voltage WebUatId
            int            genTypeWebUatId = genStationForeign.GenerationTypeWebUatId;
            GenerationType genType         = await _context.GenerationTypes.SingleOrDefaultAsync(gt => gt.WebUatId == genTypeWebUatId);

            // if GenerationType doesnot exist, skip the import. Ideally, there should not be such case
            if (genType == null)
            {
                _log.LogCritical($"Could not find GenerationType with WebUatId {genTypeWebUatId} in warehouse while creating Generating Station with WebUat Id {genStationForeign.WebUatId} and name {genStationForeign.Name}");
                return(null);
            }

            // find the State of the substation via the State WebUatId
            int   stateWebUatId = genStationForeign.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($"Could not find State with WebUatId {stateWebUatId} in warehouse while creating Generating Station with WebUat Id {genStationForeign.WebUatId} and name {genStationForeign.Name}");
                return(null);
            }

            // find the fuel of the substation via the State WebUatId
            int  fuelWebUatId = genStationForeign.FuelWebUatId;
            Fuel fuel         = await _context.Fuels.SingleOrDefaultAsync(f => f.WebUatId == fuelWebUatId);

            // if fuel doesnot exist, skip the import. Ideally, there should not be such case
            if (fuel == null)
            {
                _log.LogCritical($"Could not find Fuel with WebUatId {fuelWebUatId} in warehouse while creating Generating Station with WebUat Id {genStationForeign.WebUatId} and name {genStationForeign.Name}");
                // uncomment this after vendor complies to non null fuel types
                // return null;
            }

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

            // if entity is not present, then insert or check if we have to replace the entity completely
            if (existingGenStation == null || (opt == EntityWriteOption.Replace && existingGenStation != null))
            {
                GeneratingStation genStation = new GeneratingStation();
                genStation.Name                      = genStationForeign.Name;
                genStation.GenerationTypeId          = genType.GenerationTypeId;
                genStation.GeneratorClassificationId = genClassification.GeneratorClassificationId;
                genStation.StateId                   = state.StateId;
                if (fuel != null)
                {
                    genStation.FuelId = fuel.FuelId;
                }
                genStation.WebUatId = genStationForeign.WebUatId;

                _context.GeneratingStations.Add(genStation);
                await _context.SaveChangesAsync();

                return(genStation);
            }

            // check if we have to modify the entity
            if (opt == EntityWriteOption.Modify && existingGenStation != null)
            {
                existingGenStation.Name                      = genStationForeign.Name;
                existingGenStation.GenerationTypeId          = genType.GenerationTypeId;
                existingGenStation.GeneratorClassificationId = genClassification.GeneratorClassificationId;
                existingGenStation.StateId                   = state.StateId;
                if (fuel != null)
                {
                    existingGenStation.FuelId = fuel.FuelId;
                }
                await _context.SaveChangesAsync();

                return(existingGenStation);
            }
            return(null);
        }