示例#1
0
        public async Task <CommunicationDetails> AddMessageToCommunication(string submitedSubscription, string supportTicketId, string subject, string body)
        {
            if (string.IsNullOrWhiteSpace(submitedSubscription))
            {
                throw new ArgumentException($"'{nameof(submitedSubscription)}' cannot be null or whitespace.", nameof(submitedSubscription));
            }
            if (string.IsNullOrWhiteSpace(supportTicketId))
            {
                throw new ArgumentException($"'{nameof(supportTicketId)}' cannot be null or whitespace.", nameof(supportTicketId));
            }
            if (string.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentException($"'{nameof(subject)}' cannot be null or whitespace.", nameof(subject));
            }
            if (string.IsNullOrWhiteSpace(body))
            {
                throw new ArgumentException($"'{nameof(body)}' cannot be null or whitespace.", nameof(body));
            }

            try
            {
                var apiToken = await base.ApiIdentity.GetAccessTokenForUserAsync(Scope);

                var cr       = new Microsoft.Rest.TokenCredentials(apiToken);
                var msClient = new MicrosoftSupportClient(cr, HttpClientBase, true);
                msClient.SubscriptionId = submitedSubscription;
                var email = await ApiIdentity.GetCurrentUserEmail();

                string name = null;
                name = StringHelper.RandomStringDate(20);
                var crNew = await msClient.Communications.CreateAsync(supportTicketId, name, new CommunicationDetails
                {
                    Body    = body,
                    Sender  = email,
                    Subject = subject,
                });

                return(crNew);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#2
0
        public async Task <RefundSupportTicket> CreateSupportTicket(ServiceIssue serviceIssue, string subId, List <string> trackingIds)
        {
            RefundSupportTicket result = new();

            try
            {
#if DEBUG
                _logger.LogInformation($"{nameof(CreateSupportTicket)} started.");
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
#endif
                var apiToken = await base.ApiIdentity.GetAccessTokenForUserAsync(Scope);

                var cr       = new Microsoft.Rest.TokenCredentials(apiToken);
                var msClient = new MicrosoftSupportClient(cr, HttpClientBase, true);

                //test
                msClient.SubscriptionId = _testSubId; // can be only on sub
                var defTicket = await msClient.SupportTickets.GetAsync(_testSupportTicketId);

                var subIds = serviceIssue.ImpactedSubscriptions.GetSubcriptionIdsFromTextExt();
                if (subIds.IsNullOrEmptyCollection())
                {
                    return(null); //error
                }
                StringBuilder sbTrIds = new();
                trackingIds.ForEach(s => sbTrIds.Append($"{s}, "));

                try
                {
                    result = new();
                    result.RequiredAction       = serviceIssue.TrackingId;
                    result.SubmitedSubscription = subId;
                    result.ServiceIssueId       = serviceIssue.Id;
                    result.TrackingId           = serviceIssue.TrackingId;

                    var userEmail = await ApiIdentity.GetCurrentUserEmail();

                    if (userEmail.HasValueExt() && userEmail != defTicket.ContactDetails.PrimaryEmailAddress)
                    {
                        defTicket.ContactDetails.AdditionalEmailAddresses = new List <string> {
                            userEmail
                        }
                    }
                    ;

                    StringBuilder sb = new StringBuilder(DESCRIPTION_SINGLE_CONTS);
                    sb.Replace("1VWB-V9G", sbTrIds.ToString());

                    var desc = sb.ToString();

                    SupportTicketDetails supportTicketDetails = new SupportTicketDetails(desc, defTicket.ProblemClassificationId, "minimal"
                                                                                         , defTicket.ContactDetails, $"Refund for {nameof(serviceIssue.TrackingId)}#{serviceIssue.TrackingId}", defTicket.ServiceId);
                    supportTicketDetails.ProblemStartTime = serviceIssue.ImpactStartTime;
                    supportTicketDetails.Validate();
                    msClient.SubscriptionId = subId;

                    //return result; //only for test, to feed db with existing ticket

                    /*var supTicksCreated = await msClient.SupportTickets.CreateAsync(serviceIssue.TrackingId, supportTicketDetails)*/;
                    var supTicksCreated = await msClient.SupportTickets.CreateAsync(serviceIssue.TrackingId, supportTicketDetails);

                    if (supTicksCreated != null)
                    {
                        result.SupportTicketId = supTicksCreated.SupportTicketId;
                        result.Description     = supTicksCreated.Description;
                        result.Title           = supTicksCreated.Title;
                        result.ServiceIssue    = serviceIssue;
                    }
                }
                catch (Exception ex)
                {
                    //_logger.LogWarning($"{nameof(CreateSupportTicket)} failed for {serviceIssue.TrackingId} and sub {subId} with: {ex}");
                    throw;
                }

#if DEBUG
                stopWatch.Stop();
                _logger.LogInformation($"{nameof(CreateSupportTicket)} took {stopWatch.Elapsed}");
#endif
                return(result.SupportTicketId.HasValueExt() ? result : null);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#3
0
        public async Task <RefundSupportTicket> CreateSupportTicket(ServiceIssue serviceIssue)
        {
            RefundSupportTicket result = new();

            try
            {
#if DEBUG
                _logger.LogInformation($"{nameof(CreateSupportTicket)} started.");
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
#endif
                var apiToken = await base.ApiIdentity.GetAccessTokenForUserAsync(Scope);

                var cr       = new Microsoft.Rest.TokenCredentials(apiToken);
                var msClient = new MicrosoftSupportClient(cr, HttpClientBase, true);

                //test
                msClient.SubscriptionId = _testSubId; // can be only on sub
                var defTicket = await msClient.SupportTickets.GetAsync(_testSupportTicketId);

                //var coms = await msClient.Communications.ListAsync(SupportTicketId);

                var subIds = serviceIssue.ImpactedSubscriptions.GetSubcriptionIdsFromTextExt();
                if (subIds.IsNullOrEmptyCollection())
                {
                    return(null); //error
                }
                foreach (var subId in subIds)
                {
                    try
                    {
                        result = new();
                        result.RequiredAction       = null;
                        result.SubmitedSubscription = subId;
                        result.ServiceIssueId       = serviceIssue.Id;
                        result.TrackingId           = serviceIssue.TrackingId;

                        var userEmail = await ApiIdentity.GetCurrentUserEmail();

                        if (userEmail.HasValueExt() && userEmail != defTicket.ContactDetails.PrimaryEmailAddress)
                        {
                            defTicket.ContactDetails.AdditionalEmailAddresses = new List <string> {
                                userEmail
                            }
                        }
                        ;

                        StringBuilder sb = new StringBuilder(DESCRIPTION_CONTS);
                        sb.Replace("Tue, 21 Sep 2021, 12:00 am GMT+2", serviceIssue.ImpactStartTime.ToString("R"));
                        sb.Replace("ImpactMitigationTime", serviceIssue.ImpactMitigationTime.ToString("R"));
                        sb.Replace("LastUpdateTime", serviceIssue.LastUpdateTime.ToString("R"));
                        sb.Replace("TitlePlaceholder", serviceIssue.Title);
                        sb.Replace("1VWB-V9G", serviceIssue.TrackingId);
                        sb.Replace("ImpactedRegions", serviceIssue.ImpactedRegions);
                        sb.Replace("ImpactedServices", serviceIssue.ImpactedServices);
                        sb.Replace("Status", serviceIssue.Status);

                        #region ImpactedSubscriptions, pupulate with entire list, with ids only or split and store to RequiredAction

                        StringBuilder sbSubs   = new();
                        var           subPairs = serviceIssue.ImpactedSubscriptions.Split(",").ToList();
                        if (subPairs.Count > 1)
                        {
                            sbSubs.AppendLine(); //if more then 1, place subs into new line
                        }
                        subPairs.Where(a => a.Length > 1).ToList().ForEach(a => sbSubs.AppendLine(a.TrimStart().TrimEnd()));
                        var       desLenght = sb.Length + sbSubs.Length;
                        const int max       = 5000;
                        if (desLenght < max) //limit for des is 5000 char
                        {
                            sb.Replace(nameof(serviceIssue.ImpactedSubscriptions), sbSubs.ToString());
                        }
                        else
                        {
                            //try with ids only, ignore sub names
                            sbSubs.Clear();
                            subIds.ForEach(a => sbSubs.AppendLine(a));
                            desLenght = sb.Length + sbSubs.Length;
                            if (desLenght < max) //limit for des
                            {
                                sb.Replace(nameof(serviceIssue.ImpactedSubscriptions), sbSubs.ToString());
                            }
                            else
                            {
                                //real problem. Save into db filed RequiredAction
                                sbSubs.Clear();
                                StringBuilder sbRequiredAction = new("[Action]Additional subscriptions not included in tickets to be reported, because of 5000 limit for description in api:");
                                subPairs = serviceIssue.ImpactedSubscriptions.Split(",").ToList();
                                foreach (var item in subPairs)
                                {
                                    if (item.Length > 1)
                                    {
                                        desLenght = sb.Length + sbSubs.Length + 400; //some offset
                                        if (desLenght < max)                         //limit for des is 5000 char
                                        {
                                            sbSubs.AppendLine(item.TrimStart().TrimEnd());
                                        }
                                        else
                                        {
                                            sbRequiredAction.AppendLine(item.TrimStart().TrimEnd());
                                        }
                                    }
                                }
                                sb.Replace(nameof(serviceIssue.ImpactedSubscriptions), sbSubs.ToString());
                                result.RequiredAction = sbRequiredAction.ToString();
                            }
                        }
                        #endregion

                        var desc = sb.ToString();

                        SupportTicketDetails supportTicketDetails = new SupportTicketDetails(desc, defTicket.ProblemClassificationId, "minimal"
                                                                                             , defTicket.ContactDetails, $"Refund for {nameof(serviceIssue.TrackingId)}#{serviceIssue.TrackingId}", defTicket.ServiceId);
                        supportTicketDetails.ProblemStartTime = serviceIssue.ImpactStartTime;
                        supportTicketDetails.Validate();
                        msClient.SubscriptionId = subId;

                        //return result; //only for test, to feed db with existing ticket

                        var supTicksCreated = await msClient.SupportTickets.CreateAsync(serviceIssue.TrackingId, supportTicketDetails);

                        if (supTicksCreated != null)
                        {
                            result.SupportTicketId = supTicksCreated.SupportTicketId;
                            result.Description     = supTicksCreated.Description;
                            result.Title           = supTicksCreated.Title;
                            //result.CreatedBy = userEmail;
                            ////overide created time with ticket time
                            //refund.CreatedAt = supTicksCreated.CreatedDate;
                            result.ServiceIssue = serviceIssue;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        //_logger.LogWarning($"{nameof(CreateSupportTicket)} failed for {serviceIssue.TrackingId} and sub {subId} with: {ex}");
                        throw;
                    }
                }
#if DEBUG
                stopWatch.Stop();
                _logger.LogInformation($"{nameof(CreateSupportTicket)} took {stopWatch.Elapsed}");
#endif
                return(result.SupportTicketId.HasValueExt() ? result : null);
            }
            catch (Exception ex)
            {
                throw;
            }
        }