/// <summary>
        /// Initializes a new instance of the <see cref="GraphClient"/> class.
        /// </summary>
        /// <param name="provider">Provides access to core application services.</param>
        /// <param name="client">Provides the ability to interact with the Microsoft Graph.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="provider"/> is null.
        /// or
        /// <paramref name="client"/> is null.
        /// </exception>
        public GraphClient(IBotProvider provider, IGraphServiceClient client)
        {
            provider.AssertNotNull(nameof(provider));
            client.AssertNotNull(nameof(client));

            this.provider = provider;
            this.client   = client;
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AuthenticationProvider"/> class.
        /// </summary>
        /// <param name="provider">Provides access to core services.</param>
        /// <param name="customerId">Identifier for customer whose resources are being accessed.</param>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="customerId"/> is empty or null.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="provider"/> is null.
        /// </exception>
        public AuthenticationProvider(IBotProvider provider, string customerId)
        {
            provider.AssertNotNull(nameof(provider));
            customerId.AssertNotEmpty(nameof(customerId));

            this.customerId = customerId;
            this.provider   = provider;
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AuthDialog"/> class.
        /// </summary>
        /// <param name="provider">Provides access to core application services.</param>
        /// <param name="message">Message received by the bot from the end user.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="provider"/> is null.
        /// or
        /// <paramref name="message"/> is null.
        /// </exception>
        public AuthDialog(IBotProvider provider, IMessageActivity message)
        {
            provider.AssertNotNull(nameof(provider));
            message.AssertNotNull(nameof(message));

            this.provider         = provider;
            conversationReference = message.ToConversationReference();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphClient"/> class.
        /// </summary>
        /// <param name="provider">Provides access to core application services.</param>
        /// <param name="customerId">Identifier for customer whose resources are being accessed.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="customerId"/> is empty or null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="provider"/> is null.
        /// </exception>
        public GraphClient(IBotProvider provider, string customerId)
        {
            provider.AssertNotNull(nameof(provider));
            customerId.AssertNotEmpty(nameof(customerId));

            this.customerId = customerId;
            this.provider   = provider;
            client          = new GraphServiceClient(new AuthenticationProvider(this.provider, customerId));
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QuestionDialog"/> class.
        /// </summary>
        /// <param name="provider">Provides access to core services.</param>
        public QuestionDialog(IBotProvider provider)
        {
            provider.AssertNotNull(nameof(provider));

            QnAService = new QnAMakerService(new QnAMakerAttribute(
                                                 provider.Configuration.QnASubscriptionKey.ToUnsecureString(),
                                                 provider.Configuration.QnAKnowledgebaseId,
                                                 "default message",
                                                 0.6));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DistributedTokenCache"/> class.
        /// </summary>
        /// <param name="provider">Provides access to the core explorer providers.</param>
        /// <param name="resource">The resource being accessed.</param>
        /// <param name="key">The unique identifier for the cache entry.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="resource"/> is empty or null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="provider"/> is null.
        /// </exception>
        public DistributedTokenCache(IBotProvider provider, string resource, string key = null)
        {
            provider.AssertNotNull(nameof(provider));
            resource.AssertNotEmpty(nameof(resource));

            this.provider = provider;
            keyValue      = key;
            this.resource = resource;

            AfterAccess  = AfterAccessNotification;
            BeforeAccess = BeforeAccessNotification;
        }
        /// <summary>
        /// Gets the customer principal from the private bot data associated with the user.
        /// </summary>
        /// <param name="context">The context for the bot.</param>
        /// <param name="provider">Provides access to core application services.</param>
        /// <returns>An instance of <see cref="CustomerPrincipal"/> that represents the authenticated user.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="context"/> is null.
        /// or
        /// <paramref name="provider"/> is null.
        /// </exception>
        public static async Task <CustomerPrincipal> GetCustomerPrincipalAsync(this IBotContext context, IBotProvider provider)
        {
            CustomerPrincipal    principal = null;
            AuthenticationResult authResult;

            context.AssertNotNull(nameof(context));
            provider.AssertNotNull(nameof(provider));

            try
            {
                if (context.PrivateConversationData.TryGetValue(BotConstants.CustomerPrincipalKey, out principal))
                {
                    if (principal.ExpiresOn < DateTime.UtcNow)
                    {
                        authResult = await provider.AccessToken.AcquireTokenSilentAsync(
                            $"{provider.Configuration.ActiveDirectoryEndpoint}/{principal.CustomerId}",
                            provider.Configuration.GraphEndpoint,
                            provider.Configuration.ApplicationId,
                            new UserIdentifier(principal.ObjectId, UserIdentifierType.UniqueId)).ConfigureAwait(false);

                        principal.AccessToken = authResult.AccessToken;
                        principal.ExpiresOn   = authResult.ExpiresOn;

                        context.StoreCustomerPrincipal(principal);
                    }

                    return(principal);
                }

                return(null);
            }
            finally
            {
                authResult = null;
            }
        }
        /// <summary>
        /// Performs the operation represented by this intent.
        /// </summary>
        /// <param name="context">The context of the conversational process.</param>
        /// <param name="message">The message from the authenticated user.</param>
        /// <param name="result">The result from Language Understanding cognitive service.</param>
        /// <param name="provider">Provides access to core services;.</param>
        /// <returns>An instance of <see cref="Task"/> that represents the asynchronous operation.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="context"/> is null.
        /// or
        /// <paramref name="message"/> is null.
        /// or
        /// <paramref name="result"/> is null.
        /// or
        /// <paramref name="provider"/> is null.
        /// </exception>
        public async Task ExecuteAsync(IDialogContext context, IAwaitable <IMessageActivity> message, LuisResult result, IBotProvider provider)
        {
            IMessageActivity messageActivity;

            context.AssertNotNull(nameof(context));
            message.AssertNotNull(nameof(message));
            result.AssertNotNull(nameof(result));
            provider.AssertNotNull(nameof(provider));

            try
            {
                messageActivity = await message;

                await context.Forward(
                    new QuestionDialog(provider),
                    ResumeAfterQnA,
                    messageActivity,
                    CancellationToken.None).ConfigureAwait(false);
            }
            finally
            {
                messageActivity = null;
            }
        }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseApiController"/> class.
 /// </summary>
 /// <param name="provider">Provides access to core application services.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 protected BaseApiController(IBotProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     Provider = provider;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ActionDialog"/> class.
 /// </summary>
 /// <param name="provider">Provides access to core application services.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public ActionDialog(IBotProvider provider) :
     base(new LuisService(new LuisModelAttribute(provider.Configuration.LuisAppId, provider.Configuration.LuisApiKey.ToUnsecureString())))
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }
        /// <summary>
        /// Performs the operation represented by this intent.
        /// </summary>
        /// <param name="context">The context of the conversational process.</param>
        /// <param name="message">The message from the authenticated user.</param>
        /// <param name="result">The result from Language Understanding cognitive service.</param>
        /// <param name="provider">Provides access to core services;.</param>
        /// <returns>An instance of <see cref="Task"/> that represents the asynchronous operation.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="context"/> is null.
        /// or
        /// <paramref name="message"/> is null.
        /// or
        /// <paramref name="result"/> is null.
        /// or
        /// <paramref name="provider"/> is null.
        /// </exception>
        public async Task ExecuteAsync(IDialogContext context, IAwaitable <IMessageActivity> message, LuisResult result, IBotProvider provider)
        {
            CustomerPrincipal           principal;
            DateTime                    startTime;
            Dictionary <string, double> eventMetrics;
            Dictionary <string, string> eventProperties;
            IMessageActivity            response;
            List <OfficeHealthEvent>    healthEvents;
            ServiceCommunications       serviceComm;
            string authority;
            string customerId;

            context.AssertNotNull(nameof(context));
            message.AssertNotNull(nameof(message));
            result.AssertNotNull(nameof(result));
            provider.AssertNotNull(nameof(provider));

            try
            {
                startTime = DateTime.Now;

                principal = await context.GetCustomerPrincipalAsync(provider).ConfigureAwait(false);

                if (principal.CustomerId.Equals(provider.Configuration.PartnerCenterAccountId, StringComparison.CurrentCultureIgnoreCase))
                {
                    principal.AssertValidCustomerContext(Resources.SelectCustomerFirst);

                    authority  = $"{provider.Configuration.ActiveDirectoryEndpoint}/{principal.Operation.CustomerId}";
                    customerId = principal.Operation.CustomerId;
                }
                else
                {
                    authority  = $"{provider.Configuration.ActiveDirectoryEndpoint}/{principal.CustomerId}";
                    customerId = principal.CustomerId;
                }

                serviceComm = new ServiceCommunications(
                    new Uri(provider.Configuration.OfficeManagementEndpoint),
                    new ServiceCredentials(
                        provider.Configuration.ApplicationId,
                        provider.Configuration.ApplicationSecret.ToUnsecureString(),
                        provider.Configuration.OfficeManagementEndpoint,
                        principal.Operation.CustomerId));

                healthEvents = await serviceComm.GetHealthEventsAsync(principal.Operation.CustomerId).ConfigureAwait(false);

                response = context.MakeMessage();
                response.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                response.Attachments      = healthEvents.Select(e => e.ToAttachment()).ToList();

                await context.PostAsync(response).ConfigureAwait(false);

                // Track the event measurements for analysis.
                eventMetrics = new Dictionary <string, double>
                {
                    { "ElapsedMilliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds },
                    { "NumberOfSubscriptions", response.Attachments.Count }
                };

                // Capture the request for the customer summary for analysis.
                eventProperties = new Dictionary <string, string>
                {
                    { "ChannelId", context.Activity.ChannelId },
                    { "CustomerId", principal.CustomerId },
                    { "LocalTimeStamp", context.Activity.LocalTimestamp.ToString() },
                    { "UserId", principal.ObjectId }
                };

                provider.Telemetry.TrackEvent("OfficeIssues/Execute", eventProperties, eventMetrics);
            }
            catch (Exception ex)
            {
                response      = context.MakeMessage();
                response.Text = Resources.ErrorMessage;

                provider.Telemetry.TrackException(ex);

                await context.PostAsync(response).ConfigureAwait(false);
            }
            finally
            {
                eventMetrics    = null;
                eventProperties = null;
                principal       = null;
                response        = null;
                serviceComm     = null;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyVaultProvider"/> class.
 /// </summary>
 /// <param name="provider">Provides access to core bot providers.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public KeyVaultProvider(IBotProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }
示例#13
0
        /// <summary>
        /// Performs the operation represented by this intent.
        /// </summary>
        /// <param name="context">The context of the conversational process.</param>
        /// <param name="message">The message from the authenticated user.</param>
        /// <param name="result">The result from Language Understanding cognitive service.</param>
        /// <param name="provider">Provides access to core services.</param>
        /// <returns>An instance of <see cref="Task"/> that represents the asynchronous operation.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="context"/> is null.
        /// or
        /// <paramref name="message"/> is null.
        /// or
        /// <paramref name="result"/> is null.
        /// or
        /// <paramref name="provider"/> is null.
        /// </exception>
        public async Task ExecuteAsync(IDialogContext context, IAwaitable <IMessageActivity> message, LuisResult result, IBotProvider provider)
        {
            CustomerPrincipal           principal;
            DateTime                    startTime;
            Dictionary <string, double> eventMeasurements;
            Dictionary <string, string> eventProperties;
            IMessageActivity            response;
            List <Customer>             customers;

            context.AssertNotNull(nameof(context));
            message.AssertNotNull(nameof(message));
            result.AssertNotNull(nameof(result));
            provider.AssertNotNull(nameof(provider));

            try
            {
                startTime = DateTime.Now;

                principal = await context.GetCustomerPrincipalAsync(provider).ConfigureAwait(false);

                customers = await provider.PartnerOperations.GetCustomersAsync(principal).ConfigureAwait(false);

                response = context.MakeMessage();
                response.AttachmentLayout = AttachmentLayoutTypes.Carousel;

                response.Attachments = customers.Select(c => (new ThumbnailCard
                {
                    Buttons = new List <CardAction>
                    {
                        new CardAction
                        {
                            Title = Resources.SelectCaptial,
                            Type = ActionTypes.PostBack,
                            Value = $"select customer {c.Id}"
                        }
                    },
                    Subtitle = c.CompanyProfile.Domain,
                    Title = c.CompanyProfile.CompanyName
                }).ToAttachment()).ToList();

                await context.PostAsync(response).ConfigureAwait(false);

                // Capture the request for the customer summary for analysis.
                eventProperties = new Dictionary <string, string>
                {
                    { "ChannelId", context.Activity.ChannelId },
                    { "CustomerId", principal.CustomerId },
                    { "LocalTimeStamp", context.Activity.LocalTimestamp.ToString() },
                    { "Locale", response.Locale },
                    { "UserId", principal.ObjectId }
                };

                // Track the event measurements for analysis.
                eventMeasurements = new Dictionary <string, double>
                {
                    { "ElapsedMilliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds },
                    { "NumberOfCustomers", response.Attachments.Count }
                };

                provider.Telemetry.TrackEvent("ListCustomers/Execute", eventProperties, eventMeasurements);
            }
            finally
            {
                customers         = null;
                eventMeasurements = null;
                eventProperties   = null;
            }
        }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocalizationProvider"/> class.
 /// </summary>
 /// <param name="provider">Provides access to core application services.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public LocalizationProvider(IBotProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }
示例#15
0
        /// <summary>
        /// Performs the operation represented by this intent.
        /// </summary>
        /// <param name="context">The context of the conversational process.</param>
        /// <param name="message">The message from the authenticated user.</param>
        /// <param name="result">The result from Language Understanding cognitive service.</param>
        /// <param name="provider">Provides access to core services.</param>
        /// <returns>An instance of <see cref="Task"/> that represents the asynchronous operation.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="context"/> is null.
        /// or
        /// <paramref name="message"/> is null.
        /// or
        /// <paramref name="result"/> is null.
        /// or
        /// <paramref name="provider"/> is null.
        /// </exception>
        public async Task ExecuteAsync(IDialogContext context, IAwaitable <IMessageActivity> message, LuisResult result, IBotProvider provider)
        {
            CustomerPrincipal           principal;
            Customer                    customer;
            DateTime                    startTime;
            Dictionary <string, double> eventMeasurements;
            Dictionary <string, string> eventProperties;
            EntityRecommendation        indentifierEntity;
            IMessageActivity            response;
            string customerId = string.Empty;

            context.AssertNotNull(nameof(context));
            message.AssertNotNull(nameof(message));
            result.AssertNotNull(nameof(result));
            provider.AssertNotNull(nameof(provider));

            try
            {
                startTime = DateTime.Now;
                response  = context.MakeMessage();

                principal = await context.GetCustomerPrincipalAsync(provider).ConfigureAwait(false);

                if (result.TryFindEntity("identifier", out indentifierEntity))
                {
                    customerId = indentifierEntity.Entity.Replace(" ", string.Empty);
                    principal.Operation.CustomerId     = customerId;
                    principal.Operation.SubscriptionId = string.Empty;
                    context.StoreCustomerPrincipal(principal);
                }

                if (string.IsNullOrEmpty(customerId))
                {
                    response.Text = Resources.UnableToLocateCustomer;
                }
                else
                {
                    customer = await provider.PartnerOperations.GetCustomerAsync(principal, customerId).ConfigureAwait(false);

                    response.Text = $"{Resources.CustomerContext} {customer.CompanyProfile.CompanyName}";
                }

                await context.PostAsync(response).ConfigureAwait(false);

                // Capture the request for the customer summary for analysis.
                eventProperties = new Dictionary <string, string>
                {
                    { "ChannelId", context.Activity.ChannelId },
                    { "CustomerId", customerId },
                    { "PrincipalCustomerId", principal.CustomerId },
                    { "LocalTimeStamp", context.Activity.LocalTimestamp.ToString() },
                    { "UserId", principal.ObjectId }
                };

                // Track the event measurements for analysis.
                eventMeasurements = new Dictionary <string, double>
                {
                    { "ElapsedMilliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds }
                };

                provider.Telemetry.TrackEvent("SelectCustomer/ExecuteAsync", eventProperties, eventMeasurements);
            }
            finally
            {
                customer          = null;
                indentifierEntity = null;
                eventMeasurements = null;
                eventProperties   = null;
                message           = null;
            }
        }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RedisCacheProvider"/> class.
 /// </summary>
 /// <param name="provider">Provides access to the core bot providers.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public RedisCacheProvider(IBotProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="IntentService"/> class.
 /// </summary>
 /// <param name="provider">Provides access to core services.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public IntentService(IBotProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="AccessTokenProvider"/> class.
 /// </summary>
 /// <param name="provider">Provides access to core explorer providers.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public AccessTokenProvider(IBotProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PartnerOperations"/> class.
 /// </summary>
 /// <param name="provider">Provides access to core services.</param>
 /// <exception cref="ArgumentException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public PartnerOperations(IBotProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }
        /// <summary>
        /// Performs the operation represented by this intent.
        /// </summary>
        /// <param name="context">The context of the conversational process.</param>
        /// <param name="message">The message from the authenticated user.</param>
        /// <param name="result">The result from Language Understanding cognitive service.</param>
        /// <param name="provider">Provides access to core services;.</param>
        /// <returns>An instance of <see cref="Task"/> that represents the asynchronous operation.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="context"/> is null.
        /// or
        /// <paramref name="message"/> is null.
        /// or
        /// <paramref name="result"/> is null.
        /// or
        /// <paramref name="provider"/> is null.
        /// </exception>
        public async Task ExecuteAsync(IDialogContext context, IAwaitable <IMessageActivity> message, LuisResult result, IBotProvider provider)
        {
            Customer                    customer = null;
            CustomerPrincipal           principal;
            DateTime                    startTime;
            Dictionary <string, double> eventMetrics;
            Dictionary <string, string> eventProperties;
            IMessageActivity            response;
            List <Subscription>         subscriptions;

            context.AssertNotNull(nameof(context));
            message.AssertNotNull(nameof(message));
            result.AssertNotNull(nameof(result));
            provider.AssertNotNull(nameof(principal));

            try
            {
                startTime = DateTime.Now;

                principal = await context.GetCustomerPrincipalAsync(provider).ConfigureAwait(false);

                if (principal.CustomerId.Equals(provider.Configuration.PartnerCenterAccountId))
                {
                    customer = await provider.PartnerOperations.GetCustomerAsync(principal).ConfigureAwait(false);

                    response      = context.MakeMessage();
                    response.Text = string.Format(Resources.SubscriptionRequestMessage, customer.CompanyProfile.CompanyName);
                    await context.PostAsync(response).ConfigureAwait(false);
                }

                subscriptions = await provider.PartnerOperations.GetSubscriptionsAsync(principal).ConfigureAwait(false);

                response = context.MakeMessage();
                response.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                response.Attachments      = subscriptions.Select(s => s.ToAttachment()).ToList();

                await context.PostAsync(response).ConfigureAwait(false);

                // Track the event measurements for analysis.
                eventMetrics = new Dictionary <string, double>
                {
                    { "ElapsedMilliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds },
                    { "NumberOfSubscriptions", response.Attachments.Count }
                };

                // Capture the request for the customer summary for analysis.
                eventProperties = new Dictionary <string, string>
                {
                    { "ChannelId", context.Activity.ChannelId },
                    { "CustomerId", principal.CustomerId },
                    { "LocalTimeStamp", context.Activity.LocalTimestamp.ToString() },
                    { "UserId", principal.ObjectId }
                };

                provider.Telemetry.TrackEvent("ListCustomers/Execute", eventProperties, eventMetrics);
            }
            finally
            {
                customer        = null;
                eventMetrics    = null;
                eventProperties = null;
                principal       = null;
                response        = null;
                subscriptions   = null;
            }
        }
示例#21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationProvider" /> class.
 /// </summary>
 /// <param name="provider">Provides access to core services.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public ConfigurationProvider(IBotProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }