Exemple #1
0
        public async Task <List <SupportTicketDetails> > GetMsSupportTickets(List <string> subIds)
        {
            try
            {
#if DEBUG
                _logger.LogInformation($"{nameof(GetMsSupportTickets)} started.");
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
#endif
                if (subIds.IsNullOrEmptyCollection())
                {
                    subIds = new();
                    subIds.Add(_testSubId);
                }

                var apiToken = await AuthCsroService.GetAccessTokenForUserAsync(Scope);

                var cr       = new Microsoft.Rest.TokenCredentials(apiToken);
                var msClient = new MicrosoftSupportClient(cr, HttpClientBase, true);
                Dictionary <string, SupportTicketDetails> dic = new();
                foreach (var sub in subIds)
                {
                    msClient.SubscriptionId = sub;
                    var supTicks = await msClient.SupportTickets.ListAsync();

                    if (supTicks.HasAnyInCollection())
                    {
                        foreach (var item in supTicks)
                        {
                            if (!dic.ContainsKey(item.SupportTicketId))
                            {
                                if (!dic.TryAdd(item.SupportTicketId, item))
                                {
                                    ;//waring failed to add
                                }
                            }
                        }
                    }
                }
#if DEBUG
                stopWatch.Stop();
                _logger.LogInformation($"{nameof(GetMsSupportTickets)} took {stopWatch.Elapsed}");
#endif

                return(dic.Values.ToList());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #2
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 AuthCsroService.GetAccessTokenForUserAsync(Scope);

                var cr       = new Microsoft.Rest.TokenCredentials(apiToken);
                var msClient = new MicrosoftSupportClient(cr, HttpClientBase, true);
                msClient.SubscriptionId = submitedSubscription;
                var email = await AuthCsroService.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;
            }
        }
Exemple #3
0
        public async Task <List <CommunicationDetails> > GetMsSupportTicketsCommunication(string submitedSubscription, string supportTicketId, string trackingId)
        {
            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));
            }

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

                var cr       = new Microsoft.Rest.TokenCredentials(apiToken);
                var msClient = new MicrosoftSupportClient(cr, HttpClientBase, true);
                try
                {
                    msClient.SubscriptionId = submitedSubscription;
                    var coms = await msClient.Communications.ListAsync(supportTicketId);

                    if (coms.HasAnyInCollection())
                    {
                        return(coms.ToList());
                    }
                }
                catch (Exception ex)
                {
                    //if case is submited from prog api, it will only work via trackingId
                    var coms = await msClient.Communications.ListAsync(trackingId);

                    if (coms.HasAnyInCollection())
                    {
                        return(coms.ToList());
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(null);
        }
Exemple #4
0
        public async Task <List <SupportTicketDetails> > GetMsSupportTicketsParallel(List <string> subIds, string primaryEmail = null)
        {
            try
            {
#if DEBUG
                _logger.LogInformation($"{nameof(GetMsSupportTickets)} started.");
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
#endif
                if (subIds.IsNullOrEmptyCollection())
                {
                    subIds = new();
                    subIds.Add(_testSubId);
                }

                var apiToken = await AuthCsroService.GetAccessTokenForUserAsync(Scope);

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

                Dictionary <string, MicrosoftSupportClient> dicClients = new();
                foreach (var id in subIds)
                {
                    if (!dicClients.ContainsKey(id))
                    {
                        var cl = new MicrosoftSupportClient(cr, HttpClientBase, true)
                        {
                            SubscriptionId = id
                        };
                        dicClients.Add(id, cl);
                    }
                }

                ConcurrentDictionary <string, SupportTicketDetails> conDic = new();

                Parallel.ForEach(subIds, (sub) =>
                {
                    try
                    {
                        //msClient.SubscriptionId = sub;
                        //var t = msClient.SupportTickets.ListAsync();
                        var t = dicClients[sub].SupportTickets.ListAsync();
                        t.Wait();
                        var supTicks = t.Result;
                        if (supTicks.HasAnyInCollection())
                        {
                            foreach (var item in supTicks)
                            {
                                if (primaryEmail.HasValueExt() && item?.ContactDetails?.PrimaryEmailAddress != primaryEmail)
                                {
                                    continue;
                                }

                                if (!conDic.ContainsKey(item.SupportTicketId))
                                {
                                    conDic.AddOrUpdate(item.SupportTicketId, item, (key, old) => item);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogErrorCsro(ex, $"{nameof(GetMsSupportTicketsParallel)} for sub {sub}");
                    }
                });

                //subIds.AsParallel().ForAll(async sub =>
                //{
                //    msClient.SubscriptionId = sub;
                //    var supTicks = await msClient.SupportTickets.ListAsync();
                //    if (supTicks.HasAnyInCollection())
                //    {
                //        foreach (var item in supTicks)
                //        {
                //            if (!conDic.ContainsKey(item.SupportTicketId))
                //                conDic.AddOrUpdate(item.SupportTicketId, item, (key, old) => item);
                //            else
                //                ;//already in list
                //        }
                //    }
                //});

#if DEBUG
                stopWatch.Stop();
                _logger.LogInformation($"{nameof(GetMsSupportTickets)} took {stopWatch.Elapsed}");
#endif

                return(conDic.Values.ToList());
            }
            catch (Exception ex)
            {
                throw;
            }
        }