static void Main(string[] args)
        {
            // Setup support client and basic configuration like subscription ID
            serviceClientCredentials     = new CustomLoginCredentials();
            supportClient                = new MicrosoftSupportClient(serviceClientCredentials);
            supportClient.SubscriptionId = SUBID;

            // Setup options
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Welcome to Azure Support sample console app. Make sure to provide auth token and subscription id before running the app!");
            Console.WriteLine("");
            ConsoleKeyInfo option;
            var            cycleOptions = true;

            do
            {
                DisplayOptions();
                option = Console.ReadKey(false);
                while (Console.ReadKey(true).Key != ConsoleKey.Enter)
                {
                    continue;
                }
                Console.WriteLine("");
                switch (option.KeyChar.ToString())
                {
                case "1":
                    GetSupportTicketList(filter: "status eq 'Open' and CreatedDate gt " + DateTime.UtcNow.AddDays(-7).ToString("o"));
                    break;

                case "2":
                    ExecuteOption2();
                    break;

                case "3":
                    ExecuteOption3();
                    break;

                case "4":
                    ExecuteOption4();
                    break;

                case "5":
                    ExecuteOption5();
                    break;

                case "6":
                    cycleOptions = false;
                    break;

                default:
                    break;
                }
            } while (option.Key != ConsoleKey.Escape && cycleOptions);
        }
Ejemplo n.º 2
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 base.ApiIdentity.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
                                }
                            }
                            else
                            {
                                ;//already in list
                            }
                        }
                    }
                }
#if DEBUG
                stopWatch.Stop();
                _logger.LogInformation($"{nameof(GetMsSupportTickets)} took {stopWatch.Elapsed}");
#endif

                return(dic.Values.ToList());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        private static CommunicationDetails CreateCommunication(MicrosoftSupportClient client, string ticketName, string subject, string body)
        {
            var createCommunicationParameters = new CommunicationDetails
            {
                Subject = subject,
                Body    = body
            };

            var communicationName = TestUtilities.GenerateName("Communication");

            Console.WriteLine($"Creating communication with name: {communicationName} for ticket {ticketName}");

            var communicationDetails = client.Communications.Create(ticketName, communicationName, createCommunicationParameters);

            return(communicationDetails);
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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;
            }
        }
Ejemplo n.º 7
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;
            }
        }
Ejemplo n.º 8
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;
            }
        }