Beispiel #1
0
        public bool Evaluate(IRuleExecutionContext context)
        {
            /* STUDENT: Complete the Evaluate method to:
             * Retrieve the current temperature
             * Compare it to the temperature stored in the Policy
             * Return the result of that comparison
             */
            var             minimumTemperature = MinimumTemperature.Yield(context);
            var             city            = City.Yield(context);
            var             country         = Country.Yield(context);
            CommerceContext commerceContext = context.Fact <CommerceContext>((string)null);

            string openWeatherAPIKey  = commerceContext.GetPolicy <WeatherServiceClientPolicy>().OpenWeatherAPIKey;
            var    currentTemperature = GetCurrentTemperature(city, country, openWeatherAPIKey);

            if (currentTemperature > minimumTemperature)
            {
                return(true);
            }
            else
            {
                return(false);
            }

            // STUDENT: Replace this line. It is only provided so the stub
            // project will build cleanly
        }
Beispiel #2
0
        public bool Evaluate(IRuleExecutionContext context)
        {
            /* STUDENT: Complete the Evaluate method to:
             * Retrieve the current temperature
             * Compare it to the temperature stored in the Policy
             * Return the result of that comparison
             */
            var minimumTemperature = MinimumTemperature.Yield(context);
            var city    = City.Yield(context);
            var country = Country.Yield(context);


            // Fetch applicationid from the policy created.
            CommerceContext commerceContext      = context.Fact <CommerceContext>((string)null);
            var             weatherServicePolicy = commerceContext.GetPolicy <WeatherServiceClientPolicy>();

            var currentTemperature = GetCurrentTemperature(city, country, weatherServicePolicy.ApplicationId);

            if (currentTemperature > minimumTemperature)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        static void Main()
        {
            CurrentTemperature = BrainPad.TemperatureSensor.ReadTemperatureInFahrenheit();
            MinimumTemperature = CurrentTemperature;
            MaximumTemperature = CurrentTemperature;

            while (true)
            {
                CurrentTemperature = BrainPad.TemperatureSensor.ReadTemperatureInFahrenheit();
                if (CurrentTemperature > MaximumTemperature)
                {
                    MaximumTemperature = CurrentTemperature;
                }
                if (CurrentTemperature < MinimumTemperature)
                {
                    MinimumTemperature = CurrentTemperature;
                }

                BrainPad.Display.Clear();

                BrainPad.Display.DrawSmallText(39, 0, "Current");
                BrainPad.Display.DrawText(37, 12, (CurrentTemperature.ToString("F1")));

                BrainPad.Display.DrawSmallText(2, 34, "Minimum");
                BrainPad.Display.DrawText(0, 46, (MinimumTemperature.ToString("F1")));

                BrainPad.Display.DrawSmallText(72, 34, "Maximum");
                BrainPad.Display.DrawText(70, 46, (MaximumTemperature.ToString("F1")));

                if ((MaximumTemperature - MinimumTemperature) > 0)
                {
                    TemperaturePosition = (CurrentTemperature - MinimumTemperature) / (MaximumTemperature - MinimumTemperature) * 127;
                    BrainPad.Display.DrawLine(0, 63, (int)TemperaturePosition, 63);
                    BrainPad.Display.DrawPoint(0, 62);
                    BrainPad.Display.DrawPoint(127, 62);

                    BrainPad.LightBulb.TurnColor(TemperaturePosition / 32, 0, (127 - TemperaturePosition) / 16);
                }

                BrainPad.Display.RefreshScreen();
                BrainPad.Wait.Milliseconds(250);
            }
        }