public ConnectorBuildItem(ParentTicket ticket)
 {
     ParentTicket = ticket;
     //StageColors = new Dictionary<string, ChildTicket>();
 }
 private string BuildStoryTicketJql(ParentTicket parentTicket)
 {
     return StoryJQLQueryBase + parentTicket.Key;
 }
        private void GetAndApplyUpdates()
        {
            var lastUpdateTime = FileWriter.GetLastUpdateTime();
            if (lastUpdateTime == null)
                lastUpdateTime = "2016-01-01 00:00:00";

            if(Jira != null)
            {
                try
                {
                    
                    var jqlQuery = string.Format(UpdatedTicketsQuery, lastUpdateTime, lastUpdateTime.Substring(0, 10));
                    var updatedIssues = Jira.GetIssuesFromJql(jqlQuery).ToList();
                    FileWriter.Log("Got " + updatedIssues.Count + " tickets updated since " + lastUpdateTime);
                    //Update Epics within FinalBuilds.
                    foreach (var issue in updatedIssues.Where(x => x.Type.Name == "Epic"))
                    {
                        var newEpic = new ParentTicket(issue);
                        bool update = false;
                        for (int i = 0; i < FinalBuilds.Count; i++)
                        {
                            if(FinalBuilds[i].ParentTicket.Key == newEpic.Key)
                            {
                                newEpic.Stories = FinalBuilds[i].ParentTicket.Stories;
                                FinalBuilds[i].ParentTicket = newEpic;
                                update = true;
                            }
                        }

                        if (!update) //Insert new CBI
                        {
                            FinalBuilds.Add(new ConnectorBuildItem(newEpic));
                        }
                    }

                    //Update Stories
                    foreach (var issue in updatedIssues.Where(x => x.Type.Name == "Story"))
                    {
                        var newStory = new ChildTicket(issue, true);
                        bool update = false;

                        for (int i = 0; i < FinalBuilds.Count; i ++)
                            if(FinalBuilds[i].ParentTicket.Key == newStory.EpicLink)
                            {
                                for( int j = 0; j < FinalBuilds[i].ParentTicket.Stories.Count; j++)
                                    if(FinalBuilds[i].ParentTicket.Stories[j].Key == newStory.Key)
                                    {
                                        FinalBuilds[i].ParentTicket.Stories[j] = newStory;
                                        update = true;
                                    }

                                if(!update)
                                    FinalBuilds[i].ParentTicket.Stories.Add(newStory);
                            }
                    }

                    //Update story sub-tickets
                    foreach (var issue in updatedIssues.Where(x => x.Type.IsSubTask))
                    {
                        var child = new ChildTicket(issue, true);
                        var parent = AllChildren.Where(x => x.Key == issue.ParentIssueKey).FirstOrDefault();
                        bool update = false;
                        for(int i = 0; i < FinalBuilds.Count; i++)
                            if(FinalBuilds[i].ParentTicket.Key == parent.EpicLink)
                                for(int j = 0; j < FinalBuilds[i].ParentTicket.Stories.Count; j++)
                                    if(FinalBuilds[i].ParentTicket.Stories[j].Key == parent.Key)
                                    {
                                        for (int k = 0; k < FinalBuilds[i].ParentTicket.Stories[j].SubTickets.Count; k++)
                                            if(FinalBuilds[i].ParentTicket.Stories[j].SubTickets[k].Key == child.Key)
                                            {
                                                FinalBuilds[i].ParentTicket.Stories[j].SubTickets[k] = child;
                                                update = true;
                                            }

                                        if(!update)
                                            FinalBuilds[i].ParentTicket.Stories[j].SubTickets.Add(child);
                                    }
                    }

                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }
        }
        private async Task<List<ChildTicket>> GetChildrenAndSubTicketsAsync(ParentTicket parent)
        {
            var ticketList = new List<ChildTicket>();
            var test = BuildStoryTicketJql(parent);
            var stories = await Jira.GetIssuesFromJqlAsync(BuildStoryTicketJql(parent), 100, 0, System.Threading.CancellationToken.None);

            foreach (var story in stories)
                ticketList.Add(new ChildTicket(story, ChildrenWithWorkLogged.Contains(story.Key.ToString())));

            Debug.WriteLine(DateTime.Now + " : --- Got " + stories.Count() + " stories for: " + parent.Summary);

            return ticketList;
        }
        private void GetParents()
        {
            if (Jira != null)
            {
                try
                {
                    var issues = Jira.GetIssuesFromJql(EpicJQLQuery).ToList();

                    foreach (var issue in issues)
                    {
                        var parent = new ParentTicket(issue);
                        if(!AllParents.Contains(parent))
                        {
                            AllParents.Add(parent);
                            FinalBuilds.Add(new ConnectorBuildItem(parent));
                        }      
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }

            }
        }