示例#1
0
        private WindGenerator GetWindGeneratorFromDataBase(string city)
        {
            #region Generate base objects
            WeatherBase weatherBase = null;
            WindGeneratorBase windGeneratorBase = Task<WindGeneratorBase>.Factory.StartNew(()=>  Repositories.windGeneratorRepository.GetOneWindGenerator(city)).Result;

            WindMillBase windMillBase = Task<WindMillBase>.Factory.StartNew(() => Repositories.windMillRepository.GetOneWindMill(windGeneratorBase.WindMill)).Result;
            AggregateBase aggregateBase = Task<AggregateBase>.Factory.StartNew(() => Repositories.aggregateRepository.GetOneAggregate(windGeneratorBase.Aggregate)).Result;
            weatherBase = Task<WeatherBase>.Factory.StartNew(() => Repositories.weatherRepository.GetLastWeather(windGeneratorBase.Weather)).Result;
            #endregion

            #region Logics for aggregate state and cost
            if ((windGeneratorBase.Power = windGeneratorBase.CalculatePower()) < windMillBase.MinPower)
            {
                windGeneratorBase.AggregateONCnt++;
                aggregateBase.State = true;           
            }
            else
            {
                aggregateBase.State = false;
            }

            windGeneratorBase.TotalAggregateCost = windGeneratorBase.CalculateTotalAggregateCost(120);
            #endregion

            #region Write in database
            Repositories.windGeneratorRepository.AddOrReplaceWindGenerator(windGeneratorBase);
            Repositories.aggregateRepository.AddOrReplaceAggregate(aggregateBase);
            #endregion

            #region Generate wcf objects
            Aggregate aggregate = new Aggregate(int.Parse(aggregateBase.RowKey), aggregateBase.CostPerHour, aggregateBase.Power, aggregateBase.State);
            WindMill windMill = new WindMill(windMillBase.Coefficient, windMillBase.MinPower, windMillBase.TurbineDiameter, windMillBase.MaxSpeed, windMillBase.MaxSpeedTime,windMillBase.WorkingTime);

            if (weatherBase == null)
                weatherBase = Task<WeatherBase>.Factory.StartNew(() => Repositories.weatherRepository.GetOneWeather(windGeneratorBase.Weather)).Result;

            Weather weather = new Weather(weatherBase.City, weatherBase.Description, weatherBase.MaxTemp, weatherBase.MinTemp, weatherBase.Pressure, weatherBase.WindSpeed);

            return new WindGenerator(weather, windMill, windGeneratorBase.WindMillCnt, aggregate,windGeneratorBase.AggregateONCnt,windGeneratorBase.Power);
            #endregion
        }
示例#2
0
 public void WindGeneratorBaseConstructor_BadParameters2(string weather, string windMill, int windMillCnt, string aggregate)
 {
     WindGeneratorBase windGenerator = new WindGeneratorBase(weather, windMill, windMillCnt, aggregate);
 }