internal static string GetFormattedAddress(this Bing.Location location, string separator)
        {
            if (location?.Address == null)
            {
                return(null);
            }

            return(string.Join(separator, new[]
            {
                location.Address.AddressLine,
                location.Address.Locality,
                location.Address.AdminDistrict,
                location.Address.PostalCode,
                location.Address.CountryRegion
            }.Where(x => !string.IsNullOrEmpty(x))));
        }
        public LocationDialog(
            string apiKey,
            string prompt,
            bool skipPrompt         = false,
            bool useAzureMaps       = true,
            LocationOptions options = LocationOptions.None,
            LocationRequiredFields requiredFields   = LocationRequiredFields.None,
            LocationResourceManager resourceManager = null) : base(MainDialogId)
        {
            resourceManager = resourceManager ?? new LocationResourceManager();
            var favoritesManager = new FavoritesManager();

            IGeoSpatialService geoSpatialService;

            if (useAzureMaps)
            {
                geoSpatialService = new AzureMapsSpatialService(apiKey);
            }
            else
            {
                geoSpatialService = new BingGeoSpatialService(apiKey);
            }

            Dialogs.Add(Inputs.Choice, new ChoicePrompt(Culture.English));
            Dialogs.Add(Inputs.Text, new TextPrompt());
            Dialogs.Add(Inputs.Confirm, new ConfirmPrompt(Culture.English));

            Dialogs.Add(MainDialogId, new WaterfallStep[]
            {
                async(dc, args, next) =>
                {
                    if (options.HasFlag(LocationOptions.SkipFavorites) ||
                        !favoritesManager.GetFavorites(dc.Context).Result.Any())
                    {
                        var isFacebookChannel = StringComparer.OrdinalIgnoreCase.Equals(
                            dc.Context.Activity.ChannelId, "facebook");

                        if (options.HasFlag(LocationOptions.UseNativeControl) && isFacebookChannel)
                        {
                            await dc.Begin(DialogIds.LocationRetrieverFacebookDialog);
                        }
                        else
                        {
                            await dc.Begin(DialogIds.LocationRetrieverRichDialog);
                        }
                    }
                    else
                    {
                        await dc.Begin(DialogIds.HeroStartCardDialog);
                    }
                },
                async(dc, args, next) =>
                {
                    Bing.Location selectedLocation = (Bing.Location)args[Outputs.SelectedLocation];
                    dc.ActiveDialog.State[Outputs.SelectedLocation] = selectedLocation;

                    if (options.HasFlag(LocationOptions.SkipFinalConfirmation))
                    {
                        await next();
                    }
                    else
                    {
                        await dc.Prompt(Inputs.Confirm,
                                        string.Format(resourceManager.ConfirmationAsk,
                                                      selectedLocation.GetFormattedAddress(resourceManager.AddressSeparator)),
                                        new PromptOptions()
                        {
                            RetryPromptString = resourceManager.ConfirmationInvalidResponse
                        });
                    }
                },
                async(dc, args, next) =>
                {
                    if (args is ConfirmResult result && !result.Confirmation)
                    {
                        await dc.Context.SendActivity(resourceManager.ResetPrompt);
                        await dc.Replace(MainDialogId);
                    }