Beispiel #1
0
        /// <summary>
        /// Given the <paramref name="layer"/> type, returns a human-friendly name.
        /// </summary>
        public static string GetFriendlyName(RadarLayerType layer)
        {
            switch (layer)
            {
            case RadarLayerType.BaseReflectivity:
                return("Base Radar");

            case RadarLayerType.StormRelativeMotion:
                return("Storm Relative Motion");

            case RadarLayerType.OneHourPrecipitation:
                return("Rain (one-hour precipitation)");

            case RadarLayerType.Topography:
                return("Topography");

            case RadarLayerType.CountyBoundaries:
                return("County Boundaries");

            case RadarLayerType.Rivers:
                return("Rivers");

            case RadarLayerType.Highways:
                return("Highways");

            case RadarLayerType.Cities:
                return("Cities");

            default:
                return("Unknown layer");
            }
        }
Beispiel #2
0
 /// <summary>
 /// Removes the specified <paramref name="layer"/> from the stack. Returns an empty string, but if not present, returns an error message.
 /// </summary>
 public string RemoveLayer(RadarLayerType layer)
 {
     if (!this.RadarLayers.Contains(layer))
     {
         return($"The '{layer.ToString()}' layer has already been removed from rendering.");
     }
     else
     {
         this.RadarLayers.Remove(layer);
         return(string.Empty);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Adds the specified <paramref name="layer"/> to the end of the stack. Returns an empty string, but if already present, returns an error message.
 /// </summary>
 public string AddLayer(RadarLayerType layer)
 {
     if (this.RadarLayers.Contains(layer))
     {
         return($"The '{layer.ToString()}' layer has already been added for rendering.");
     }
     else
     {
         this.RadarLayers.Add(layer);
         return(string.Empty);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Move the specified <paramref name="layer"/> down the stack. Returns an empty string, but if not present, returns an error message.
        /// </summary>
        public string DemoteLayer(RadarLayerType layer)
        {
            if (!this.RadarLayers.Contains(layer))
            {
                return($"The '{layer.ToString()}' layer is not listed for rendering.");
            }
            else
            {
                int idx = this.RadarLayers.IndexOf(layer);
                if (idx != this.RadarLayers.Count - 1)
                {
                    this.RadarLayers.Remove(layer);
                    this.RadarLayers.Insert(idx + 1, layer);
                }

                return(string.Empty);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Move the specified <paramref name="layer"/> up the stack. Returns an empty string, but if not present, returns an error message.
        /// </summary>
        public string PromoteLayer(RadarLayerType layer)
        {
            if (!this.RadarLayers.Contains(layer))
            {
                return($"The '{layer.ToString()}' layer is not listed for rendering.");
            }
            else
            {
                // We really could use a linked-list, but the amount of data here is so minimal that the optimization isn't worth it.
                int idx = this.RadarLayers.IndexOf(layer);
                if (idx != 0)
                {
                    this.RadarLayers.Remove(layer);
                    this.RadarLayers.Insert(idx - 1, layer);
                }

                return(string.Empty);
            }
        }
        protected override async Task <ConversationResponse <WeatherSettings> > ContinueConversationAsync(IStore blobStore, ActivityRequest request, WeatherSettings priorConversation)
        {
            if (request.SanitizedText.Contains("quit"))
            {
                priorConversation = null; // Reset the game state
            }

            string input = request.SanitizedText.ToLower();

            List <string>             responseText = new List <string>();
            List <AttachmentResponse> attachments  = new List <AttachmentResponse>();

            if (input.Contains("weather"))
            {
                input = input.Replace("weather", string.Empty).Trim();
                if (!string.IsNullOrWhiteSpace(input))
                {
                    // The rest of the input is the location, so update our geo-coordinate
                    try
                    {
                        GeoCoordinate coordinate = await this.locationFinder.GetLocationAsync(input).ConfigureAwait(false);

                        Station closestStation    = StationLocator.FindClosestStation(coordinate);
                        string  distanceToStation = $", {(int)(closestStation.Location.GetDistanceTo(coordinate) / 10.0) / 100.0} km away.";
                        if (closestStation.Callsign != priorConversation.Station)
                        {
                            responseText.Add($"Using {closestStation.Callsign} near {closestStation.City}{distanceToStation}");
                            priorConversation.Station = closestStation.Callsign;
                        }
                        else
                        {
                            responseText.Add($"{closestStation.Callsign}, the currently-selected station, is still the closest NOAA station{distanceToStation}");
                        }
                    }
                    catch (Exception ex)
                    {
                        responseText.Add(ex.Message + ": " + ex.StackTrace);
                    }
                }

                // Actually get the weather.
                AttachmentResponse radarImage =
                    await LayerRetriever.GetRadarImageAsync(priorConversation, blobStore, "weather-images", TimeSpan.FromDays(3 * 30)).ConfigureAwait(false);

                attachments.Add(radarImage);
            }
            else if (input.Contains("layers") || input.Contains("layer"))
            {
                input = input.Replace("layers", string.Empty).Replace("layer", string.Empty).Trim();
                if (input.Contains("add"))
                {
                    input = input.Replace("add", string.Empty).Trim();
                    RadarLayerType layer = RadarLayerTypeNames.GetLayer(input);
                    if (layer == RadarLayerType.Unknown)
                    {
                        responseText.Add($"Unknown layer '{input}'");
                        OutputValidLayers(responseText);
                    }
                    else
                    {
                        string response = priorConversation.LayerStack.AddLayer(layer);
                        if (!string.IsNullOrEmpty(response))
                        {
                            responseText.Add(response);
                        }

                        OutputCurrentLayers(priorConversation, responseText);
                    }
                }
                else if (input.Contains("remove"))
                {
                    input = input.Replace("remove", string.Empty).Trim();
                    RadarLayerType layer = RadarLayerTypeNames.GetLayer(input);
                    if (layer == RadarLayerType.Unknown)
                    {
                        responseText.Add($"Unknown layer '{input}'");
                        OutputValidLayers(responseText);
                    }
                    else
                    {
                        string response = priorConversation.LayerStack.RemoveLayer(layer);
                        if (!string.IsNullOrEmpty(response))
                        {
                            responseText.Add(response);
                        }
                        OutputCurrentLayers(priorConversation, responseText);
                    }
                }
                else if (input.Contains("promote"))
                {
                    input = input.Replace("promote", string.Empty).Trim();
                    RadarLayerType layer = RadarLayerTypeNames.GetLayer(input);
                    if (layer == RadarLayerType.Unknown)
                    {
                        responseText.Add($"Unknown layer '{input}'");
                        OutputValidLayers(responseText);
                    }
                    else
                    {
                        string response = priorConversation.LayerStack.PromoteLayer(layer);
                        if (!string.IsNullOrEmpty(response))
                        {
                            responseText.Add(response);
                        }
                        OutputCurrentLayers(priorConversation, responseText);
                    }
                }
                else if (input.Contains("demote"))
                {
                    input = input.Replace("demote", string.Empty).Trim();
                    RadarLayerType layer = RadarLayerTypeNames.GetLayer(input);
                    if (layer == RadarLayerType.Unknown)
                    {
                        responseText.Add($"Unknown layer '{input}'");
                        OutputValidLayers(responseText);
                    }
                    else
                    {
                        string response = priorConversation.LayerStack.DemoteLayer(layer);
                        if (!string.IsNullOrEmpty(response))
                        {
                            responseText.Add(response);
                        }
                        OutputCurrentLayers(priorConversation, responseText);
                    }
                }
                else
                {
                    responseText.Add("Valid layer commands are 'add', 'remove', 'promote', or 'demote'");
                    OutputValidLayers(responseText);
                    OutputCurrentLayers(priorConversation, responseText);
                }
            }
            else
            {
                responseText.Add("Unknown command!");
                responseText.Add(this.GetHelpText());
            }

            return(new ConversationResponse <WeatherSettings>(priorConversation, new ActivityResponse(string.Join("\r\n\r\n", responseText), attachments)));
        }