Example #1
0
        public static async Task <HeroCard> GenerateLocationCard()
        {
            var address         = "Corso del Lavoro e della Scienza 3 - 38122 Trento";
            var resourceManager = new LocationResourceManager();
            var mapsAPI         = WebConfigurationManager.AppSettings["BingMapsMasterKey"];
            var carBuilder      = new LocationCardBuilder(mapsAPI, resourceManager);
            var bingService     = new BingGeoSpatialService(mapsAPI);
            var locationSet     = await bingService.GetLocationsByQueryAsync(address);

            var addressUrl = "https://www.google.it/maps/place/" + address;
            var card       = carBuilder.CreateHeroCards(locationSet.Locations).ToList().First();

            card.Title = "Info";

            string text = String.Empty;

            text += $@"Telefono: +39 0461270311" + "\n\n";
            text += $@"Email: [email protected]" + "\n\n";
            text += $@"Indirizzo: {address}";

            card.Text    = text;
            card.Buttons = new[] { new CardAction(ActionTypes.OpenUrl, @"Mappa", value: addressUrl),
                                   new CardAction(ActionTypes.OpenUrl, @"Contatti", value: "http://www.muse.it/it/contatti/Pagine/default.aspx"),
                                   new CardAction(ActionTypes.OpenUrl, @"Orari e Tariffe", value: "http://www.muse.it/it/visita/orari-tariffe/Pagine/Home.aspx") };
            return(card);
        }
        public async Task Should_Post_To_User_Passed_Prompt_When_Start_Called()
        {
            // Arrange
            string prompt  = "Where do you want to ship your widget?";
            var    dialog  = new LocationDialog(string.Empty, "facebook", prompt, LocationOptions.None);
            var    context = this.GetSetupMockObject();

            context
            .Setup(c => c.MakeMessage())
            .Returns(() => new Activity());

            context
            .Setup(c => c.PostAsync(It.IsAny <IMessageActivity>(), It.IsAny <CancellationToken>()))
            .Returns(() => Task.CompletedTask);

            context
            .Setup(c => c.Call(It.IsAny <IDialog <LocationDialogResponse> >(), It.IsAny <ResumeAfter <LocationDialogResponse> >()))
            .Callback <IDialog <LocationDialogResponse>, ResumeAfter <LocationDialogResponse> >(async(d, c) => await d.StartAsync(context.Object));

            // Act
            await dialog.StartAsync(context.Object);

            // Assert
            var locationResourceManager = new LocationResourceManager();

            context.Verify(c => c.Call(It.IsAny <FacebookNativeLocationRetrieverDialog>(), It.IsAny <ResumeAfter <LocationDialogResponse> >()), Times.Never);
            context.Verify(c => c.PostAsync(It.Is <IMessageActivity>(a => a.Text == prompt + locationResourceManager.TitleSuffix), It.IsAny <CancellationToken>()), Times.Once);
        }
Example #3
0
 public FacebookNativeLocationRetrieverDialog(
     string prompt,
     IGeoSpatialService geoSpatialService,
     LocationOptions options,
     LocationRequiredFields requiredFields,
     LocationResourceManager resourceManager)
     : base(geoSpatialService, options, requiredFields, resourceManager)
 {
     SetField.NotNull(out this.prompt, nameof(prompt), prompt);
 }
 internal LocationRetrieverDialogBase(
     IGeoSpatialService geoSpatialService,
     LocationOptions options,
     LocationRequiredFields requiredFields,
     LocationResourceManager resourceManager) : base(resourceManager)
 {
     SetField.NotNull(out this.geoSpatialService, nameof(geoSpatialService), geoSpatialService);
     this.options        = options;
     this.requiredFields = requiredFields;
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocationDialog"/> class.
 /// </summary>
 /// <param name="geoSpatialService">The Geo-Special Service</param>
 /// <param name="apiKey">The geo spatial service API key.</param>
 /// <param name="prompt">The prompt posted to the user when dialog starts.</param>
 /// <param name="supportsKeyboard">Indicates whether channel supports keyboard buttons or not.</param>
 /// <param name="resourceManager">The resource manager.</param>
 internal RichLocationRetrieverDialog(
     IGeoSpatialService geoSpatialService,
     string apiKey,
     string prompt,
     bool supportsKeyboard,
     LocationResourceManager resourceManager) : base(resourceManager)
 {
     SetField.NotNull(out this.geoSpatialService, nameof(geoSpatialService), geoSpatialService);
     SetField.NotNull(out this.apiKey, nameof(apiKey), apiKey);
     this.prompt           = prompt;
     this.supportsKeyboard = supportsKeyboard;
 }
Example #6
0
 internal EditFavoriteLocationDialog(
     ILocationDialogFactory locationDialogFactory,
     IFavoritesManager favoritesManager,
     string favoriteName,
     Location favoriteLocation,
     LocationResourceManager resourceManager)
     : base(resourceManager)
 {
     SetField.NotNull(out this.locationDialogFactory, nameof(locationDialogFactory), locationDialogFactory);
     SetField.NotNull(out this.favoritesManager, nameof(favoritesManager), favoritesManager);
     SetField.NotNull(out this.favoriteName, nameof(favoriteName), favoriteName);
     SetField.NotNull(out this.favoriteLocation, nameof(favoriteLocation), favoriteLocation);
 }
        public async Task If_Help_Command_Post_Help_Message()
        {
            // Arrange
            var dialog = new LocationDialog(string.Empty, "facebook", string.Empty, LocationOptions.UseNativeControl);

            var context = this.GetSetupMockObject();

            // Act
            await dialog.MessageReceivedAsync(context.Object, TestHelper.CreateAwaitableMessage("help"));

            // Assert
            var locationResourceManager = new LocationResourceManager();

            context.Verify(c => c.PostAsync(It.Is <IMessageActivity>(a => a.Text == locationResourceManager.HelpMessage), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task If_Reset_Command_Call_StartAsync()
        {
            // Arrange
            string prompt = "Where do you want to ship your widget?";
            var    dialog = new LocationDialog(string.Empty, "facebook", prompt, LocationOptions.None);

            var context = this.GetSetupMockObject();

            // Act
            await dialog.MessageReceivedAsync(context.Object, TestHelper.CreateAwaitableMessage("reset"));

            // Assert
            var locationResourceManager = new LocationResourceManager();

            context.Verify(c => c.PostAsync(It.Is <IMessageActivity>(a => a.Text == locationResourceManager.ResetPrompt), It.IsAny <CancellationToken>()), Times.Once);
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocationDialog"/> class.
 /// </summary>
 /// <param name="geoSpatialService">The Geo-Special Service.</param>
 /// <param name="cardBuilder">The card builder service.</param>
 /// <param name="prompt">The prompt posted to the user when dialog starts.</param>
 /// <param name="supportsKeyboard">Indicates whether channel supports keyboard buttons or not.</param>
 /// <param name="options">The location options used to customize the experience.</param>
 /// <param name="requiredFields">The location required fields.</param>
 /// <param name="resourceManager">The resource manager.</param>
 internal RichLocationRetrieverDialog(
     string prompt,
     bool supportsKeyboard,
     ILocationCardBuilder cardBuilder,
     IGeoSpatialService geoSpatialService,
     LocationOptions options,
     LocationRequiredFields requiredFields,
     LocationResourceManager resourceManager,
     bool skipPrompt = false)
     : base(geoSpatialService, options, requiredFields, resourceManager)
 {
     SetField.NotNull(out this.cardBuilder, nameof(cardBuilder), cardBuilder);
     SetField.NotNull(out this.prompt, nameof(prompt), prompt);
     this.supportsKeyboard = supportsKeyboard;
     this.skipPrompt       = skipPrompt;
 }
Example #10
0
 public FavoriteLocationRetrieverDialog(
     bool supportsKeyboard,
     IFavoritesManager favoritesManager,
     ILocationDialogFactory locationDialogFactory,
     ILocationCardBuilder cardBuilder,
     IGeoSpatialService geoSpatialService,
     LocationOptions options,
     LocationRequiredFields requiredFields,
     LocationResourceManager resourceManager)
     : base(geoSpatialService, options, requiredFields, resourceManager)
 {
     SetField.NotNull(out this.favoritesManager, nameof(favoritesManager), favoritesManager);
     SetField.NotNull(out this.locationDialogFactory, nameof(locationDialogFactory), locationDialogFactory);
     SetField.NotNull(out this.cardBuilder, nameof(cardBuilder), cardBuilder);
     this.supportsKeyboard = supportsKeyboard;
 }
 internal LocationDialogFactory(
     string apiKey,
     string channelId,
     string prompt,
     IGeoSpatialService geoSpatialService,
     LocationOptions options,
     LocationRequiredFields requiredFields,
     LocationResourceManager resourceManager)
 {
     SetField.NotNull(out this.apiKey, nameof(apiKey), apiKey);
     SetField.NotNull(out this.channelId, nameof(channelId), channelId);
     SetField.NotNull(out this.prompt, nameof(prompt), prompt);
     this.geoSpatialService = geoSpatialService;
     this.options           = options;
     this.requiredFields    = requiredFields;
     this.resourceManager   = resourceManager ?? new LocationResourceManager();
 }
Example #12
0
        internal static IDialog <LocationDialogResponse> CreateLocationRetrieverDialog(
            string apiKey,
            string channelId,
            string prompt,
            bool useNativeControl,
            LocationResourceManager resourceManager)
        {
            bool isFacebookChannel = StringComparer.OrdinalIgnoreCase.Equals(channelId, "facebook");

            if (useNativeControl && isFacebookChannel)
            {
                return(new FacebookNativeLocationRetrieverDialog(prompt, resourceManager));
            }

            return(new RichLocationRetrieverDialog(
                       geoSpatialService: new BingGeoSpatialService(),
                       apiKey: apiKey,
                       prompt: prompt,
                       supportsKeyboard: isFacebookChannel,
                       resourceManager: resourceManager));
        }
Example #13
0
        internal LocationDialogFactory(
            string apiKey,
            string channelId,
            string prompt,
            IGeoSpatialService geoSpatialService,
            LocationOptions options,
            LocationRequiredFields requiredFields,
            LocationResourceManager resourceManager)
        {
            SetField.NotNull(out this.apiKey, nameof(apiKey), apiKey);
            SetField.NotNull(out this.channelId, nameof(channelId), channelId);
            SetField.NotNull(out this.prompt, nameof(prompt), prompt);
            this.geoSpatialService = geoSpatialService;
            this.options           = options;
            this.requiredFields    = requiredFields;
            this.resourceManager   = resourceManager ?? new LocationResourceManager();

            if (!string.IsNullOrEmpty(this.apiKey) && this.apiKey.Length > 60)
            {
                useAzureMaps = false;
            }
        }
Example #14
0
 public LocationRequiredFieldsDialog(Bing.Location location, LocationRequiredFields requiredFields, LocationResourceManager resourceManager)
     : base(resourceManager)
 {
     SetField.NotNull(out this.location, nameof(location), location);
     this.requiredFields   = requiredFields;
     this.location.Address = this.location.Address ?? new Bing.Address();
 }
Example #15
0
 internal AddFavoriteLocationDialog(IFavoritesManager favoritesManager, Location location, LocationResourceManager resourceManager) : base(resourceManager)
 {
     SetField.NotNull(out this.favoritesManager, nameof(favoritesManager), favoritesManager);
     SetField.NotNull(out this.location, nameof(location), location);
 }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocationDialogBase{T}" /> class.
 /// </summary>
 /// <param name="resourceManager">The resource manager.</param>
 internal LocationDialogBase(LocationResourceManager resourceManager)
 {
     this.resourceManager = resourceManager ?? new LocationResourceManager();
 }
 public FacebookNativeLocationRetrieverDialog(string prompt, LocationResourceManager resourceManager)
     : base(resourceManager)
 {
     SetField.NotNull(out this.prompt, nameof(prompt), prompt);
     this.prompt = prompt;
 }