private void ListboxCommits_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Clear data when selection changes ClearSecondaryData(); // Get model from selected item var model = ComboModels.SelectedItem as Model; // Get secureUrl from event as object if (ListboxCommits.SelectedItem is Commit commit) { // Show the report generation button BtnCompareChanges.Visibility = Visibility.Visible; var eventUrl = new Uri(Unifi.GetSecureUrl(_unifiToken, model, commit.EventId).ToString()); // Set event data from event URL SelectedEvent = Unifi.GetEventData(eventUrl); // Set all commit symbols foreach (var symbol in SelectedEvent.Data.ProjectFamilies.FamilySymbols) { Symbols.Add(symbol); } // Add family instances as items in listbox foreach (var instance in SelectedEvent.Data.ProjectFamilies.FamilyInstances) { FamilyInstances.Add(instance); } ListboxSecondary.ItemsSource = FamilyInstances; } if (ListboxCommits.SelectedItem == null) { // Hide the report generation button BtnCompareChanges.Visibility = Visibility.Hidden; } }
private void BtnCompareChanges_Click(object sender, RoutedEventArgs e) { // Get model from selected item var model = ComboModels.SelectedItem as Model; // Get secureUrl from event as object var latestEventUrl = new Uri(Unifi.GetSecureUrl(_unifiToken, model, LatestCommit.EventId).ToString()); // Set event data from event URL var latestEvent = Unifi.GetEventData(latestEventUrl); // Get latest and selected event families as lists var latestEventFamilies = latestEvent.Data.ProjectFamilies.FamilyInstances.ToList(); var selectedEventFamilies = SelectedEvent.Data.ProjectFamilies.FamilyInstances.ToList(); // Retrieves all of the families that have been added to the project model since the selected sync var addedFamilies = Unifi.GetNewFamilies(selectedEventFamilies, latestEventFamilies); // Retrieves all of the families that have been deleted from the project model since the selected sync var deletedFamilies = Unifi.GetDeletedFamilies(selectedEventFamilies, latestEventFamilies); // Calculate the elapsed time between syncs var elapsedTime = latestEvent.CollectionTime.Subtract(SelectedEvent.CollectionTime); // Store the results of the test in a string var reportData = "# Revit Model Changelog\n"; // Add a summary of data regarding the report reportData += "This report was generated using the UNIFI Project Analytics API. For access to the source code, visit " + "[https://github.com/unifilabs/UNIFI-ProjectAnalytics-API-Sample]." + "\n---\n" + "*Model:* " + (ComboModels.SelectedItem as Model)?.Filename + "\n" + "*Dates Compared:* " + SelectedEvent.CollectionTime.LocalDateTime + " => " + latestEvent.CollectionTime.LocalDateTime + "\n" + "*Time elapsed:* " + elapsedTime.Days + " days, " + elapsedTime.Hours + " hours, " + elapsedTime.Minutes + " minutes, " + elapsedTime.Seconds + " seconds"; reportData += "\n---\n"; // Add the added families to the report string reportData += "## Families Added\n"; // Get number of added families var numberOfAddedFamilies = addedFamilies.Count(); if (numberOfAddedFamilies != 0) { // Create a counter the generate an ordered list var counter = 1; reportData = reportData + ($"{numberOfAddedFamilies:n0}" + " families have been added.\n\n"); // Add an ordered list item for each family in the list foreach (var fam in addedFamilies) { // Write data to a line in the report reportData += counter + ". [" + fam.ElementId + "] " + fam.Name + "\n"; // Increase the counter by one to continue the ordered list counter += 1; } } else { reportData += "No families were added.\n"; } reportData += "\n---\n"; // Add the deleted families to the report string reportData += "## Families Deleted\n"; if (deletedFamilies.Count() != 0) { // Create a counter the generate an ordered list var counter = 1; reportData += $"{deletedFamilies.Count():n0}" + " families have been deleted.\n\n"; // Add an ordered list item for each family in the list foreach (var fam in deletedFamilies) { // Write data to a line in the report reportData += counter + ". [" + fam.ElementId + "] " + fam.Name + "\n"; // Increase the counter by one to continue the ordered list counter += 1; } } else { reportData += "No families were deleted.\n"; } reportData += "\n---\n"; // Save the string as a text file var save = new SaveFileDialog { FileName = "UNIFI Project Analytics Changelog", Filter = "Markdown Text File | *.md" }; if (save.ShowDialog() == true) { var writer = new StreamWriter(save.OpenFile()); writer.Write(reportData); writer.Dispose(); writer.Close(); MessageBox.Show("Report saved to: " + save.FileName); } }