Beispiel #1
0
        private static TicketCategory CreateCategory(TicketCategory category)
        {
            Logger.Trace("Creating category: {0}", category.name);

            var content = JsonConvert.SerializeObject(category);

            var request = CreateRequest("ticketCategory", HttpMethod.Post);

            var dataArray = Encoding.UTF8.GetBytes(content);

            request.ContentLength = dataArray.Length;

            var requestStream = request.GetRequestStream();

            requestStream.Write(dataArray, 0, dataArray.Length);
            requestStream.Close();


            var result = GetObject <TicketCategory>(request);

            Categories.Add(result.name, result);

            return(result);
        }
Beispiel #2
0
        private static void ParseXml()
        {
            Logger.Trace("Parsing xml");

            var tickets = Xml.SelectNodes("/tickets/ticket");

            if (tickets == null)
            {
                return;
            }

            Logger.Debug("{0} tickets found in xml", tickets.Count);



            var currentTicket = 0;

            foreach (var xmlTicket in tickets.Cast <XmlElement>())
            {
                currentTicket++;

                var ticket = new Ticket(xmlTicket);

                Logger.Info("Parsing ticket: {0}/{1} ({2}%)",

                            currentTicket,
                            tickets.Count,

                            ((currentTicket / (decimal)tickets.Count) * 100.0m).ToString("n", CultureInfo.InvariantCulture)

                            );

                ticket.organizationId = GetOrganizationId(xmlTicket["organization-id"].InnerText);
                // map to organization id
                ticket.createdByUserId = GetUserId(xmlTicket["requester-id"].InnerText);                   // map to the user id
                if (ticket.createdByUserId == null)
                {
                    var id     = xmlTicket["requester-id"].InnerText;
                    var person = GetPerson(id);
                    if (person != null)
                    {
                        ticket.personId             = person.id;
                        ticket.createdByDisplayname = person.displayName;
                    }
                }

                ticket.assignedUserId       = GetUserId(xmlTicket["assignee-id"].InnerText);             //Map to the user id
                ticket.assignedDepartmentId = GetDepartmentId(xmlTicket["group-id"].InnerText);
                //Map to the department id

                // Tags
                ticket.tagsPerTicket = new List <TagsPerTicket>();
                var tags = xmlTicket["current-tags"].InnerText.Split(new[]
                {
                    ' '
                },
                                                                     StringSplitOptions.RemoveEmptyEntries);
                foreach (var tag in tags.Select(x => x.Replace("_", " ")))
                {
                    var ticketTag = new TagsPerTicket();
                    if (Tags.ContainsKey(tag))
                    {
                        ticketTag.tagId = Tags[tag].id;
                    }
                    else
                    {
                        var created = CreateTag(new TicketTag(tag));
                        ticketTag.tagId = created.id;
                    }
                    ticket.tagsPerTicket.Add(ticketTag);
                }

                var ticketFields = xmlTicket.SelectNodes("ticket-field-entries/ticket-field-entry");
                // Category
                var category = ticketFields.Cast <XmlElement>().FirstOrDefault();
                if (category != null && !String.IsNullOrWhiteSpace(category["value"].InnerText))
                {
                    var cat = new TicketCategory
                    {
                        name = category["value"].InnerText
                    };
                    if (Categories.ContainsKey(cat.name))
                    {
                        ticket.categoryId = Categories[cat.name].id;
                    }
                    else
                    {
                        var ticketCategory = CreateCategory(cat);
                        ticket.categoryId = ticketCategory.id;
                    }
                }

                // Priority
                if (ticketFields.Count > 3)
                {
                    var priorityMoscow = ticketFields.Cast <XmlElement>().ElementAt(3).InnerText;
                    if (!String.IsNullOrWhiteSpace(priorityMoscow))
                    {
                        var prio = new TicketPriority(priorityMoscow);
                        if (Priorities.ContainsKey(prio.name))
                        {
                            ticket.priorityId = Priorities[prio.name].id;
                        }
                        else
                        {
                            prio = CreatePriority(prio);
                            Priorities.Add(prio.name, prio);
                            ticket.priorityId = prio.id;
                        }
                    }
                }

                HandleHistory(ticket, xmlTicket);

                //set status of ticket (if solved, status done)
                var solvedAt = DateTimeParse.ParseNullableDateTime(xmlTicket["solved-at"].InnerText);
                ticket.statusId = solvedAt.HasValue ? StatusDone.id : StatusNew.id;


                Result.Add(ticket);
            }
        }