コード例 #1
0
 public void ApplyShipOrders(TimeSpan t, bool isFinalChange, IWind currentWind)
 {
     foreach (var ship in _shipsByIndex.Values)
     {
         ship.ApplyCurrentShipOrder(t, isFinalChange, currentWind);
     }
 }
コード例 #2
0
        public string Get(string id, string temp, string wind)
        {
            new ApplicationAction("Starting Weather Api Calls", "user", "WeatherTest for " + id).Save();

            new ApplicationAction("Using AutoFac", "user", "DI using a Framework").Save();

            //Dependency Injection with framework Autofac
            var builder = new ContainerBuilder();

            builder.RegisterType <ProcessApi>().As <IProcessApi>();
            builder.RegisterType <Config>().As <IConfig>();
            IContainer Container = builder.Build();


            TempType UserSelectTemp = (TempType)Enum.Parse(typeof(TempType), temp.ToUpper());
            WindType UserSelectWind = (WindType)Enum.Parse(typeof(WindType), wind.ToUpper());


            //List of Apis to call all based on the Strategy pattern
            var WeatherApis = new List <IWeatherStrategy>();

            // add new API which would have been created - TODO make this a dynaimc process so this file does not need to be edited
            WeatherApis.Add(new WeatherDataCollectorBbc());
            WeatherApis.Add(new WeatherDataCollectorAccu());

            new ApplicationAction("Added Apis", "user", "Two Apis").Save();

            //List to hold API call data
            var LocationDataSets = new List <string>();

            using (var scope = Container.BeginLifetimeScope())
            {
                foreach (IWeatherStrategy api in WeatherApis)
                {
                    // call each of the APIs and store the result
                    LocationDataSets.Add(api.gatherData(id, scope.Resolve <IProcessApi>(), scope.Resolve <IConfig>()));
                }
            }

            new ApplicationAction("Creating objects", "user", "Using factory pattern").Save();

            ITemperatureFactory tempFactory  = new TemperatureFactory();
            ITemperature        selectedTemp = tempFactory.CreateTemperature(UserSelectTemp);

            IWindFactory windFactory  = new WindFactory();
            IWind        selectedWind = windFactory.CreateWind(UserSelectWind);

            new ApplicationAction("Calcuating results", "user", "Aggregated result data").Save();

            //call the aggregator to work out the results
            var calculatedLocationWeather = new Aggregator(selectedTemp, selectedWind).AggregateData(LocationDataSets);

            calculatedLocationWeather.Location = id;

            new ApplicationAction("Completed prcoessing", "user", "TReturn data to client").Save();
            //return to client final result
            return(JsonConvert.SerializeObject(calculatedLocationWeather));
        }
コード例 #3
0
ファイル: Weather.cs プロジェクト: ErtyHackward/utopia
 public Weather(IClock clock, ServerComponent server)
 {
     Wind                    = new Wind(false);
     MoistureOffset          = 0.0f;
     TemperatureOffset       = 0.0f;
     _clock                  = clock;
     _server                 = server;
     _server.MessageWeather += ServerConnection_MessageWeather;
 }
コード例 #4
0
        public void ApplyCurrentShipOrder(TimeSpan timeStep, bool isFinalChange, IWind currentWind)
        {
            if (!HasValidShipOrder)
            {
                throw new InvalidOperationException("The order is not complete enough to send to this ship.");
            }

            if (_movementOrderStack == null)
            {
                _movementOrderStack = CreateMovementOrderStack(CurrentShipOrder);
            }

            var timeLeftToTravel = timeStep;

            while (_movementOrderStack.Any())
            {
                var movementOrder = _movementOrderStack.Pop();

                // If we don't manage to finish the movement order this time step we subtract the spent time and put it back on the stack.
                if (timeStep < movementOrder.TimeSpan)
                {
                    movementOrder.TimeSpan -= timeStep;
                    _movementOrderStack.Push(movementOrder);
                }

                var timeSpentForThisMovementOrder = new TimeSpan(Math.Min(timeLeftToTravel.Ticks, movementOrder.TimeSpan.Ticks));

                var distanceToTravelForThisMovementOrder = timeSpentForThisMovementOrder.TotalSeconds * CurrentSpeed * SpeedMultiplierFromWind(currentWind);

                if (movementOrder is ForwardMovementOrder)
                {
                    ApplyMovementOrder((ForwardMovementOrder)movementOrder, distanceToTravelForThisMovementOrder);
                }
                else if (movementOrder is YawMovementOrder)
                {
                    ApplyMovementOrder((YawMovementOrder)movementOrder, distanceToTravelForThisMovementOrder);
                }

                timeLeftToTravel -= timeSpentForThisMovementOrder;
                if (timeLeftToTravel.Ticks == 0)
                {
                    break;
                }
            }

            ApplyWindDrift(currentWind, timeStep);

            if (isFinalChange)
            {
                _movementOrderStack = null;

                if (CurrentShipOrder.ShipSailLevelIncrement.HasValue && CurrentShipOrder.ShipSailLevelIncrement != SailLevelChange.StayAtCurrentSailSpeed)
                {
                    ChangeSailLevel(CurrentShipOrder.ShipSailLevelIncrement.Value);
                }
            }
        }
コード例 #5
0
        public double SpeedMultiplierFromWind(IWind wind)
        {
            var angleDiff = 180 - Math.Abs(180 - (AngleInDegrees - wind.Angle));

            Console.WriteLine(angleDiff);
            if (angleDiff < 30)
            {
                return(wind.Velocity * 0.08);
            }
            if (angleDiff < 150)
            {
                return(wind.Velocity * 0.1);
            }

            return(wind.Velocity * 0.03);
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WeatherReport"/> class.
 /// </summary>
 /// <param name="time">The value of time.</param>
 /// <param name="temperature">The value of temperature.</param>
 /// <param name="pressure">The value of atmospheric pressure.</param>
 /// <param name="humidity">The value of humidity.</param>
 /// <param name="wind">The value of wind.</param>
 /// <param name="cloudiness">The value of cloudiness.</param>
 /// <param name="precipitation">The value of precipitation.</param>
 public WeatherReport(
     DateTime time,
     ITemperature temperature,
     IPressure pressure,
     IHumidity humidity,
     IWind wind,
     ICloudiness cloudiness,
     IPrecipitation precipitation)
 {
     this.Time          = time;
     this.Temperature   = temperature;
     this.Pressure      = pressure;
     this.Humidity      = humidity;
     this.Wind          = wind;
     this.Cloudiness    = cloudiness;
     this.Precipitation = precipitation;
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: AdamantAlan/Patterns
 public adapterWindToWeather(IWind wind) => _wind = wind;
コード例 #8
0
        private void ApplyWindDrift(IWind wind, TimeSpan timeStep)
        {
            var direction = Vector2D.DirectionFromAngle(wind.Angle);

            Position += direction * wind.Velocity * timeStep.TotalSeconds * DriftMultiplier;
        }
コード例 #9
0
 public Aggregator(ITemperature temp, IWind wind)
 {
     tempHandler = temp;
     windHandler = wind;
 }
コード例 #10
0
ファイル: Poppy.cs プロジェクト: KairatJC/ioc
 public Poppy(IWind wind)
 {
     _wind = wind;
 }
コード例 #11
0
ファイル: Poppy.cs プロジェクト: KairatJC/ioc
 public Poppy()
 {
     _wind = WindFactory.GetWindObj();
 }