private static Activity ParseActivity(DcrGraph graph, XDocument doc, XElement eve) { var nestedEvents = eve.Descendants("event").Where(element => element.HasElements).ToList(); //Only takes event elements in events! bool isNestedGraph = nestedEvents.Count > 0; // Retrieve Id var id = eve.Attribute("id").Value; // Retrieve Name: var name = (from labelMapping in doc.Descendants("labelMapping") where labelMapping.Attribute("eventId").Value.Equals(id) select labelMapping.Attribute("labelId").Value).FirstOrDefault(); // Check to see if Activity was already parsed if (graph.GetActivities().ToList().Exists(x => x.Id == id && x.Name == name)) return null; Activity activityToReturn; if (isNestedGraph) { var nestedActivities = new HashSet<Activity>(); foreach (var nestedEvent in nestedEvents) { nestedActivities.Add(ParseActivity(graph, doc, nestedEvent)); } activityToReturn = graph.MakeNestedGraph(id, name, nestedActivities); } else // Not a nested graph --> Treat as single activity { // Add activity to graph activityToReturn = graph.AddActivity(id, name); // Assigning Roles: var roles = eve.Descendants("role"); var rolesList = new List<string>(); foreach (var role in roles) { if (role.Value != "") graph.AddRolesToActivity(id,role.Value); } // Mark Included if ((from includedEvent in doc.Descendants("included").Elements() select includedEvent.FirstAttribute.Value).Contains(id)) graph.SetIncluded(true, id); // Mark Pending: if ((from pendingEvent in doc.Descendants("pendingResponses").Elements() select pendingEvent.FirstAttribute.Value).Contains(id)) graph.SetPending(true, id); // Mark Executed: if ((from executedEvent in doc.Descendants("executed").Elements() select executedEvent.FirstAttribute.Value).Contains(id)) graph.SetExecuted(true, id); } return activityToReturn; }