Example #1
0
 private async Task WriteExportAsync(ExportTicket export)
 {
     using (var fileStream = _fileService.CreateFile(ExportFile))
     {
         var serializer = _serializerResolver.Resolve(ExportFile);
         await serializer.SerializeAsync(export, fileStream);
     }
 }
Example #2
0
        public async Task ExecuteAsync()
        {
            _logger.LogInformation("Create ticket client for endpoint {0}...", _account.Endpoint);
            var ticketClient = _account.CreateTicketClient();

            _logger.LogInformation("Retrieve all tickets...");
            var ticketList = await ticketClient.GetTicketListAsync();

            _logger.LogInformation("{0} tickets were obtained.", ticketList?.Count);

            if (ticketList?.Count > 0)
            {
                _logger.LogInformation("Create ticket export...");
                var export = new ExportTicket();

                foreach (var ticket in ticketList)
                {
                    try
                    {
                        _logger.LogInformation("Processing ticket {0}...", ticket.Id);
                        var ticketItem = CreateTicketItem(ticket);
                        export.Tickets.Add(ticketItem);

                        _logger.LogInformation("Retrieve all ticket articles for ticket {0}...", ticket.Id);
                        var articleList = await ticketClient.GetTicketArticleListForTicketAsync(ticket.Id);

                        _logger.LogInformation("{0} ticket articles were obtained.", articleList?.Count);

                        if (articleList?.Count > 0)
                        {
                            foreach (var article in articleList)
                            {
                                _logger.LogInformation("Processing ticket article {0} from ticket {1}...", article.Id, ticket.Id);
                                var articleItem = CreateArticleItem(article);
                                ticketItem.Articles.Add(articleItem);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.LogError("Error by ticket {0}\r\n{1}", ticket.Id, e.Message);
                    }
                }

                await WriteExportAsync(export);
            }
        }