示例#1
0
        /// <summary>
        /// Gets a list of health events for the license based subscription.
        /// </summary>
        /// <param name="customerId">Identifier of the customer.</param>
        /// <returns>A list of health events.</returns>
        private async Task <List <IHealthEvent> > GetOfficeSubscriptionHealthAsync(string customerId)
        {
            AuthenticationResult  token;
            ServiceCommunications comm;

            customerId.AssertNotEmpty(nameof(customerId));

            try
            {
                token = await Provider.AccessToken.GetAccessTokenAsync(
                    $"{Provider.Configuration.ActiveDirectoryEndpoint}/{customerId}",
                    Provider.Configuration.OfficeManagementEndpoint,
                    new ApplicationCredential
                {
                    ApplicationId     = Provider.Configuration.ApplicationId,
                    ApplicationSecret = Provider.Configuration.ApplicationSecret,
                    UseCache          = true
                }).ConfigureAwait(false);

                comm = new ServiceCommunications(Provider, token);
                return(await comm.GetCurrentStatusAsync(customerId).ConfigureAwait(false));
            }
            finally
            {
                comm  = null;
                token = null;
            }
        }
        /// <summary>
        /// Get the specified messages using the Office 365 Service Communication API.
        /// </summary>
        /// <param name="tenantId">The tenant identifier.</param>
        /// <param name="messageIds">The message ids.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">tenantId</exception>
        public JsonResult GetMessages(string tenantId, string messageIds)
        {
            if (string.IsNullOrEmpty(tenantId))
            {
                throw new ArgumentNullException("tenantId");
            }

            List <Message>        messages;
            ServiceCommunications service;

            string[] ids;

            try
            {
                messages = new List <Message>();
                service  = new ServiceCommunications(TokenContext.UserAssertionToken);
                ids      = messageIds.Split(',');

                foreach (string id in ids)
                {
                    if (!string.IsNullOrEmpty(id))
                    {
                        messages.Add(service.GetMessage(tenantId, id));
                    }
                }

                return(Json(new { Result = "OK", Records = messages, TotalRecordCount = messages.Count }));
            }
            finally
            {
                messages = null;
                service  = null;
            }
        }
        private async Task <List <IHealthEvent> > GetOfficeSubscriptionHealthAsync(string customerId)
        {
            ServiceCommunications comm;

            if (string.IsNullOrEmpty(customerId))
            {
                throw new ArgumentNullException(nameof(customerId));
            }

            try
            {
                comm = new ServiceCommunications(TokenContext.UserAssertionToken);
                return(await comm.GetCurrentStatusAsync(customerId));
            }
            finally
            {
                comm = null;
            }
        }
        /// <summary>
        /// Get Office 365status details for specified tenant using the Office 365 Service Communication API.
        /// </summary>
        /// <param name="tenantId">The tenant identifier.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">tenantId</exception>
        public JsonResult OfficeStatus(string tenantId)
        {
            List <StatusDetails>  records;
            ServiceCommunications service;

            if (string.IsNullOrEmpty(tenantId))
            {
                throw new ArgumentNullException("tenantId");
            }

            try
            {
                service = new ServiceCommunications(TokenContext.UserAssertionToken);
                records = service.GetCurrentStatus(tenantId);

                return(Json(new { Result = "OK", Records = records, TotalRecordCount = records.Count }));
            }
            finally
            {
                service = null;
            }
        }
示例#5
0
        /// <summary>
        /// Gets a list of health events for the license based subscription.
        /// </summary>
        /// <param name="customerId">Identifier of the customer.</param>
        /// <returns>A list of health events.</returns>
        private async Task <List <IHealthEvent> > GetOfficeSubscriptionHealthAsync(string customerId)
        {
            AuthenticationToken   token;
            ServiceCommunications comm;

            customerId.AssertNotEmpty(nameof(customerId));

            try
            {
                token = await this.Service.TokenManagement.GetAppOnlyTokenAsync(
                    $"{this.Service.Configuration.ActiveDirectoryEndpoint}/{customerId}",
                    this.Service.Configuration.OfficeManagementEndpoint);

                comm = new ServiceCommunications(this.Service, token);
                return(await comm.GetCurrentStatusAsync(customerId));
            }
            finally
            {
                comm  = null;
                token = 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="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;
            }
        }