コード例 #1
0
        protected override async Task OnEventActivityAsync(ITurnContext <IEventActivity> turnContext, CancellationToken cancellationToken)
        {
            var ev    = turnContext.Activity.AsEventActivity();
            var value = ev.Value?.ToString();

            switch (ev.Name)
            {
            case Events.TimezoneEvent:
            {
                var state = await _stateAccessor.GetAsync(turnContext, () => new EmailSkillState());

                state.UserInfo.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(value);

                break;
            }

            case Events.LocationEvent:
            {
                var state = await _stateAccessor.GetAsync(turnContext, () => new EmailSkillState());

                var azureMapsClient = new AzureMapsClient(_settings);
                state.UserInfo.TimeZone = await azureMapsClient.GetTimeZoneInfoByCoordinates(value);

                break;
            }

            default:
            {
                await _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken);

                break;
            }
            }
        }
コード例 #2
0
        private async Task PopulateStateFromActivity(ITurnContext context)
        {
            var activity       = context.Activity;
            var semanticAction = activity.SemanticAction;

            if (semanticAction != null && semanticAction.Entities.ContainsKey(StateProperties.TimeZone))
            {
                var timezone    = semanticAction.Entities[StateProperties.TimeZone];
                var timezoneObj = timezone.Properties[StateProperties.TimeZone].ToObject <TimeZoneInfo>();
                var state       = await _stateAccessor.GetAsync(context, () => new EmailSkillState());

                state.UserInfo.TimeZone = timezoneObj;
            }

            if (semanticAction != null && semanticAction.Entities.ContainsKey(StateProperties.Location))
            {
                var location       = semanticAction.Entities[StateProperties.Location];
                var locationString = location.Properties[StateProperties.Location].ToString();
                var state          = await _stateAccessor.GetAsync(context, () => new EmailSkillState());

                var azureMapsClient = new AzureMapsClient(_settings);
                var timezone        = await azureMapsClient.GetTimeZoneInfoByCoordinates(locationString);

                state.UserInfo.TimeZone = timezone;
            }
        }
コード例 #3
0
        private void GeocodeCsvAddressesFrom(string path, string key)
        {
            var amWebClient = new CookieWebClient();
            var amBasePath  = new ApplicationBasePath(
                protocolPrefix: "https://",
                site: "atlas.microsoft.com",
                applicationPath: "/");

            var amClient = new AzureMapsClient(
                webClient: amWebClient,
                basePath: amBasePath,
                subscriptionKey: key);

            int geocoded       = 0;
            int alreadyGeocode = 0;
            var addresses      = LoadCsvAddresses.LoadFrom(path);

            foreach (var address in addresses)
            {
                if (address.Latitude == null ||
                    address.Longitude == null ||
                    address.Latitude == 0 ||
                    address.Longitude == 0)
                {
                    var coordinates = new AzureMapsmGeocodeAddress(view, amClient)
                                      .Geocode(address);

                    address.Latitude  = coordinates.Latitude;
                    address.Longitude = coordinates.Longitude;

                    geocoded++;
                }
                else
                {
                    alreadyGeocode++;
                }
            }

            view.AppendResultText($"\nTotal Addresses: {(geocoded + alreadyGeocode)}");
            view.AppendResultText($"\nGeocoded: {geocoded}");
            view.AppendResultText($"\nAlready Geocoded (Skipped): {alreadyGeocode}");

            var newPath = view.GetFileNameToSaveAs(path, "csv");

            if (string.IsNullOrWhiteSpace(newPath))
            {
                // Cancelled
                view.AppendResultText($"\nGeocoding not saved.");

                return;
            }

            LoadCsvAddresses.SaveTo(addresses, newPath);

            view.AppendResultText($"\nGeocoding saved to {newPath}");
        }
コード例 #4
0
        // Runs when a new event activity comes in.
        protected override async Task OnEventActivityAsync(DialogContext innerDc, CancellationToken cancellationToken = default)
        {
            var ev    = innerDc.Context.Activity.AsEventActivity();
            var value = ev.Value?.ToString();

            switch (ev.Name)
            {
            case TokenEvents.TokenResponseEventName:
            {
                // Forward the token response activity to the dialog waiting on the stack.
                await innerDc.ContinueDialogAsync();

                break;
            }

            case Events.TimezoneEvent:
            {
                var state = await _stateAccessor.GetAsync(innerDc.Context, () => new EmailSkillState());

                state.UserInfo.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(value);

                break;
            }

            case Events.LocationEvent:
            {
                var state = await _stateAccessor.GetAsync(innerDc.Context, () => new EmailSkillState());

                var azureMapsClient = new AzureMapsClient(_settings);
                state.UserInfo.TimeZone = await azureMapsClient.GetTimeZoneInfoByCoordinates(value);

                break;
            }

            default:
            {
                await innerDc.Context.SendActivityAsync(new Activity(type : ActivityTypes.Trace, text : $"Unknown Event '{ev.Name ?? "undefined"}' was received but not processed."));

                break;
            }
            }
        }
コード例 #5
0
        private async Task PopulateStateFromSemanticAction(ITurnContext context)
        {
            var activity       = context.Activity;
            var semanticAction = activity.SemanticAction;

            if (semanticAction != null && semanticAction.Entities.ContainsKey("timezone"))
            {
                var timezone    = semanticAction.Entities["timezone"];
                var timezoneObj = timezone.Properties["timezone"].ToObject <TimeZoneInfo>();

                var state = await _stateAccessor.GetAsync(context, () => new CalendarSkillState());

                // we have a timezone
                state.UserInfo.Timezone = timezoneObj;
            }

            if (semanticAction != null && semanticAction.Entities.ContainsKey("location"))
            {
                var location       = semanticAction.Entities["location"];
                var locationString = location.Properties["location"].ToString();
                var state          = await _stateAccessor.GetAsync(context, () => new CalendarSkillState());

                var coords = locationString.Split(',');
                if (coords.Length == 2)
                {
                    if (double.TryParse(coords[0], out var lat) && double.TryParse(coords[1], out var lng))
                    {
                        state.UserInfo.Latitude  = lat;
                        state.UserInfo.Longitude = lng;
                    }
                }

                var azureMapsClient = new AzureMapsClient(_settings);
                var timezone        = await azureMapsClient.GetTimeZoneInfoByCoordinates(locationString);

                state.UserInfo.Timezone = timezone;
            }
        }
コード例 #6
0
 public AzureMapsmGeocodeAddress(IClientView view, AzureMapsClient client)
 {
     this.view   = view;
     this.client = client;
 }