public async static Task RunAsync(MainForm mainForm) { var referencesWithUrl = mainForm.GetFilteredReferences().Where(reference => !string.IsNullOrEmpty(reference?.OnlineAddress) && GetRemoteUriLocation(reference) != null).ToList(); if (referencesWithUrl.Count == 0) { MessageBox.Show(mainForm, Resources.NoReferencesFoundedMessage, mainForm.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); return; } try { var result = await GenericProgressDialog.RunTask(mainForm, CheckReferencesAsync, referencesWithUrl); if (result.InvalidCount != 0) { if (MessageBox.Show(string.Format(Resources.MacroResultMessage, referencesWithUrl.Count, result.ChangedCount, result.InvalidCount), mainForm.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes && result.InvalidReferences.Count > 0) { var filter = new ReferenceFilter(result.InvalidReferences, Resources.ReferenceInvalidFilterName, false); mainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> { filter }); } } else { MessageBox.Show(string.Format(Resources.MacroResultMessageWithoutSelection, referencesWithUrl.Count.ToString(), result.ChangedCount.ToString(), result.InvalidCount.ToString()), mainForm.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (OperationCanceledException) { } }
public void Test_IsMatch() { using (LogGroup logGroup = LogGroup.Start("Testing the ReferenceFilter.IsMatch function.", NLog.LogLevel.Debug)) { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); TestCategory category = new TestCategory(); category.ID = Guid.NewGuid(); article.Categories = new TestCategory[] { category }; DataAccess.Data.Saver.Save(category); DataAccess.Data.Saver.Save(article); ReferenceFilter filter = (ReferenceFilter)DataAccess.Data.CreateFilter(typeof(ReferenceFilter)); filter.Operator = FilterOperator.Equal; filter.PropertyName = "Categories"; filter.ReferencedEntityID = category.ID; filter.ReferenceType = typeof(TestCategory); filter.AddType(typeof(TestArticle)); bool isMatch = filter.IsMatch(article); Assert.IsTrue(isMatch, "The IsMatch function returned false when it should have been true."); } }
public async static void Run(MainForm mainForm, MacroSettings settings) { var referencesWithDoi = mainForm.GetFilteredReferences() .Where(reference => !string.IsNullOrEmpty(reference.PubMedId)) .ToList(); try { var mergedReferences = await GenericProgressDialog.RunTask(mainForm, RunAsync, Tuple.Create(mainForm.Project, referencesWithDoi, settings)); if (mergedReferences.Count() != 0) { if (MessageBox.Show(mainForm, UpdateBibliographicDataFromPubMedSearchResources.ProcessFinishWithChangesMessage.FormatString(mergedReferences.Count()), mainForm.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { var filter = new ReferenceFilter(mergedReferences, "References with locations from file", false); mainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> { filter }); } } else { MessageBox.Show(mainForm, UpdateBibliographicDataFromPubMedSearchResources.ProcessFinishWithoutChangesMessage, mainForm.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (OperationCanceledException) { // What exactly does Task.WhenAll do when a cancellation is requested? We don't know and are too lazy to find out ;-) // To be on the safe side, we catch a possible exception and return; return; } }
public void Test_GetEntitiesByFilterGroup_EmptyGroup() { using (LogGroup logGroup = LogGroup.Start("Testing a simple query with the PropertyFilter.", NLog.LogLevel.Debug)) { TestUser user = new TestUser(); user.ID = Guid.NewGuid(); user.FirstName = "Test"; user.LastName = "User"; user.Username = "******"; TestRole role = new TestRole(); role.ID = Guid.NewGuid(); role.Name = "Test role"; user.Roles = new TestRole[] { role }; DataAccess.Data.Saver.Save(role); DataAccess.Data.Saver.Save(user); ReferenceFilter filter = (ReferenceFilter)DataAccess.Data.CreateReferenceFilter(); filter.PropertyName = "Roles"; filter.ReferencedEntityID = role.ID; filter.ReferenceType = role.GetType(); filter.AddType(typeof(TestUser)); PropertyFilter filter2 = (PropertyFilter)DataAccess.Data.CreatePropertyFilter(); filter2.PropertyName = "Username"; filter2.PropertyValue = user.Username; filter2.AddType(typeof(TestUser)); FilterGroup filterGroup = new FilterGroup(); // Leave empty by not adding filters //filterGroup.Add(filter); //filterGroup.Add(filter2); IEntity[] found = (IEntity[])DataAccess.Data.Indexer.GetEntities(filterGroup); Assert.IsNotNull(found, "Null value returned"); if (found != null) { Assert.IsTrue(found.Length > 0, "No results found."); if (found.Length > 0) { TestUser foundUser = (TestUser)found[0]; Assert.IsNotNull(foundUser, "foundUser == null"); Assert.AreEqual(user.ID, foundUser.ID, "The IDs don't match."); } } } }
void KnowledgeOrganizerFilters_CollectionChanged(object sender, CollectionChangedEventArgs <KnowledgeItemFilter> e) { if (_eventsSuspended) { return; } var eventsSuspended = _eventsSuspended; try { _eventsSuspended = true; var activeMainForm = GetActiveMainFormOrDefault(mainForm => sender == mainForm.KnowledgeOrganizerFilterSet.Filters); if (activeMainForm == null) { return; } if (activeMainForm.KnowledgeOrganizerFilterSet.Filters.Count == 1) { if (activeMainForm.KnowledgeOrganizerFilterSet.Filters[0].Category != null) { var filter = new ReferenceFilter(activeMainForm.KnowledgeOrganizerFilterSet.Filters[0].Category); var list = new List <ReferenceFilter> { filter }; activeMainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(list); } else if (activeMainForm.KnowledgeOrganizerFilterSet.Filters[0].Keyword != null) { var filter = new ReferenceFilter(activeMainForm.KnowledgeOrganizerFilterSet.Filters[0].Keyword); var list = new List <ReferenceFilter> { filter }; activeMainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(list); } } } finally { _eventsSuspended = eventsSuspended; } }
private void GetMarginUtilisationByProduct(String reference) { // Create a new MarginUtilisation ByProductQuery muByProductq = new ByProductQuery(null); // Create a new filter for the query // Note the only filter supported by this query is a ReferenceFilter. // The Reference provided must be the Reference retrieved from a // MarginUtilisationItem retrieved from the MarginUtilisationQuery ReferenceFilter filter = new ReferenceFilter(); filter.AddFilterCriteria(ReferenceFilter.FilterBy.Reference, reference); // Provide a query handler and start the query. muByProductq.QueryResponse += muByProductq_QueryResponse; muByProductq.Start(filter); }
public void Test_GetEntitiesByReferenceFilter_Exclusion() { using (LogGroup logGroup = LogGroup.Start("Testing a simple query with the PropertyFilter.", NLog.LogLevel.Debug)) { TestUser user = new TestUser(); user.ID = Guid.NewGuid(); user.FirstName = "Test"; user.LastName = "User"; TestRole role = new TestRole(); role.ID = Guid.NewGuid(); role.Name = "Test role"; // This should remain commented out to check for exclusion //user.Roles = new TestRole[]{role}; DataAccess.Data.Saver.Save(user); DataAccess.Data.Saver.Save(role); ReferenceFilter filter = (ReferenceFilter)DataAccess.Data.CreateFilter(typeof(ReferenceFilter)); filter.PropertyName = "Roles"; filter.ReferencedEntityID = role.ID; //filter.ReferenceType = role.GetType(); filter.AddType(typeof(TestUser)); IEntity[] found = (IEntity[])DataAccess.Data.Indexer.GetEntities(filter); Assert.IsNotNull(found, "Null value returned"); if (found != null) { Assert.IsTrue(found.Length == 0, "Results returned when none should have been returned."); /*if (found.Length > 0) * { * TestUser foundUser = (TestUser)found[0]; * * Assert.AreEqual(user.ID, foundUser.ID, "The IDs don't match."); * }*/ } } }
void SynchronizeFilterChangeWithPreview(MainForm mainForm) { if (mainForm == null) { return; } var list = mainForm.GetFilteredReferences(); foreach (var previewMainForm in GetPreviewMainForms(mainForm.Project)) { previewMainForm.ReferenceEditorFilterSet.Filters.Clear(); if (list.Count == 0) { continue; } var referenceFilter = new ReferenceFilter(list, "temp", false); previewMainForm.ReferenceEditorFilterSet.Filters.Add(referenceFilter); } }
void SetFilterInPreview(MainForm previewMainForm) { var mainForm = GetMainForm(previewMainForm.Project); if (mainForm == null) { return; } var filteredReferences = mainForm.GetFilteredReferences(); previewMainForm.ReferenceEditorFilterSet.Filters.Clear(); if (filteredReferences.Count == 0) { return; } var referenceFilter = new ReferenceFilter(filteredReferences, "temp", false); previewMainForm.ReferenceEditorFilterSet.Filters.Add(referenceFilter); }
public async static void Run(MainForm mainForm) { var referencesWithUrl = mainForm.GetFilteredReferences() .Where(reference => !String.IsNullOrEmpty(reference.OnlineAddress)) .ToList(); if (referencesWithUrl.Count == 0) { MessageBox.Show(mainForm, CheckUrlAndSetDateResources.NoReferencesFoundedMessage, mainForm.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); return; } var isCanceled = false; MacroResult result = null; try { result = await GenericProgressDialog.RunTask(mainForm, CheckReferences, referencesWithUrl); } catch (OperationCanceledException) { isCanceled = true; } if (isCanceled) { return; } if (MessageBox.Show(string.Format(CheckUrlAndSetDateResources.MacroResultMessage, referencesWithUrl.Count.ToString(), result.ChangedCount.ToString(), result.InvalidCount.ToString()), mainForm.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes && result.InvalidReferences.Count > 0) { var filter = new ReferenceFilter(result.InvalidReferences, CheckUrlAndSetDateResources.ReferenceInvalidFilterName, false); mainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> { filter }); } }
void Run(MainForm mainForm, IEnumerable <string> clipboardFiles) { var foundedReferences = new List <Reference>(); try { foreach (var reference in mainForm.Project.References) { foreach (var location in reference.Locations.ToList()) { var path = location.Address.Resolve().GetLocalPathSafe(); if (clipboardFiles.Contains(path)) { foundedReferences.Add(reference); break; } } } if (foundedReferences.Any()) { var filter = new ReferenceFilter(foundedReferences, "References with locations from file", false); mainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> { filter }); } } finally { if (!foundedReferences.Any()) { MessageBox.Show(Strings.FoundNoMatches, Program.ActiveProjectShell.PrimaryMainForm.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public void SetFilter(string fieldName, ReferenceFilter filterType, object value, string text) { SetFilter(fieldName, filterType, value, (object)text); }
public static void ExportBookmarks(List <Reference> references) { List <Reference> exportFailed = new List <Reference>(); int exportCounter = 0; PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl; if (previewControl != null) { previewControl.ShowNoPreview(); } foreach (Reference reference in references) { List <KnowledgeItem> quotations = reference.Quotations.Where(q => q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); List <LinkedResource> linkedResources = reference.Locations.Where(l => l.LocationType == LocationType.ElectronicAddress).Select(l => (LinkedResource)l.Address).ToList(); List <KnowledgeItem> quickReferences = quotations.Where(q => q.QuotationType == QuotationType.QuickReference && q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); foreach (LinkedResource linkedResource in linkedResources) { string pathToFile = linkedResource.Resolve().LocalPath; if (!System.IO.File.Exists(pathToFile)) { continue; } List <Rect> coveredRects = new List <Rect>(); Document document = new Document(pathToFile); if (document == null) { continue; } List <KnowledgeItem> quickReferencesAtThisLocation = quickReferences.Where(d => ((Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).Location.Address == linkedResource).ToList(); List <Annotation> quickReferenceAnnotationsAtThisLocation = quickReferencesAtThisLocation.Select(d => (Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).ToList(); DeleteExtraBookmarks(quickReferencesAtThisLocation, document); foreach (Annotation annotation in quickReferenceAnnotationsAtThisLocation) { ExportQuickReferenceAsBookmark(annotation, document); } try { document.Save(pathToFile, SDFDoc.SaveOptions.e_remove_unused); exportCounter++; } catch { exportFailed.Add(reference); } document.Close(); } } string message = "Bookmarks exported to {0} locations."; message = string.Format(message, exportCounter); if (exportFailed.Count == 0) { MessageBox.Show(message, "Citavi", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { DialogResult showFailed = MessageBox.Show(message + "\n Would you like to show a selection of references where export has failed?", "Citavi Macro", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (showFailed == DialogResult.Yes) { var filter = new ReferenceFilter(exportFailed, "Export failed", false); Program.ActiveProjectShell.PrimaryMainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> { filter }); } } }
public static void Main() { //**************************************************************************************************************** // This macro checks URLs for validity and sets AccessDate to today's date or the error message of the URL check // Version 1.5 -- 2016-01-19 // // // EDIT HERE int timeOut = 3000; // time in milliseconds until URL check is aborted string setToDate = null; // if not null, string is used for AccessDate, e.g. setToDate = "05.02.2013", otherwise today's date; bool setDateAlways = false; // if true, AccessDate is set regardless of outcome of URL check // DO NOT EDIT BELOW THIS LINE // **************************************************************************************************************** if (Program.ProjectShells.Count == 0) { return; //no project open } if (IsBackupAvailable() == false) { return; //user wants to backup his/her project first } string dateTimeFormat = Program.Engine.Settings.General.DateTimeFormat; string newAccessDate = setToDate; if (setToDate == null) { newAccessDate = DateTime.Today.ToString(dateTimeFormat); } //iterate over all references in the current filter (or over all, if there is no filter) List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetFilteredReferences(); List <Reference> referencesWithUrl = references.Where(reference => !String.IsNullOrEmpty(reference.OnlineAddress)).ToList(); List <Reference> referencesWithInvalidUrls = new List <Reference>(); //reference to active Project Project activeProject = Program.ActiveProjectShell.Project; int loopCounter = 0; int changeCounter = 0; int invalidCounter = 0; string urlResult = null; //Welcome message DebugMacro.WriteLine(String.Format("Checking links for {0} reference(s) with URLs out of {1} reference(s) in total.", referencesWithUrl.Count.ToString(), references.Count.ToString())); foreach (Reference reference in referencesWithUrl) { loopCounter++; DebugMacro.WriteLine(String.Format("Checking {0} of {1}: {2}", loopCounter.ToString(), referencesWithUrl.Count.ToString(), reference.ShortTitle)); // get URL to check string url = reference.OnlineAddress; DebugMacro.WriteLine(string.Format("Processing URL '{0}'", url)); string oldAccessDate = reference.AccessDate; // get previous last access date // Check URL and set fields bool urlExists = RemoteFileExists(url, timeOut, out urlResult); if (urlExists) { DebugMacro.WriteLine("URL is valid."); reference.Notes += String.Format(" *** Link {0} checked on {1}: {2}; original access date: {3} ***", reference.OnlineAddress, DateTime.Now.ToString(), urlResult, oldAccessDate); reference.AccessDate = newAccessDate; changeCounter++; } else { DebugMacro.WriteLine("URL is NOT valid: " + urlResult); reference.Notes += String.Format(" *** Link {0} checked on {1}: {2}; original access date: {3} ***", reference.OnlineAddress, DateTime.Now.ToString(), urlResult, oldAccessDate); if (setDateAlways) { reference.AccessDate = newAccessDate; } invalidCounter++; referencesWithInvalidUrls.Add(reference); } } string message = "{0} links checked:\n{1} URLs valid\n{2} URLs not reachable\n Would you like to show a selection with references having an unreachable Online Address?"; message = string.Format(message, referencesWithUrl.Count.ToString(), changeCounter.ToString(), invalidCounter.ToString()); DialogResult showSelection = MessageBox.Show(message, "Report", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (showSelection == DialogResult.Yes && referencesWithInvalidUrls.Count > 0) { ReferenceFilter filter = new ReferenceFilter(referencesWithInvalidUrls, "References with invalid URLs", false); List <ReferenceFilter> referenceFilters = new List <ReferenceFilter>(); referenceFilters.Add(filter); Program.ActiveProjectShell.PrimaryMainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(referenceFilters); } else { return; } }
public static void ChangeShorthands() { bool handled; List <Reference> references = new List <Reference>(); SwissAcademic.Citavi.Project activeProject = Program.ActiveProjectShell.Project; List <Reference> activeProjectReferencesList = new List <Reference>(); // We copy the active project references in a list so that the changes don't affect the order of the list we later loop through foreach (Reference reference in activeProject.References) { if (reference.ReferenceType != ReferenceType.CourtDecision) { continue; } activeProjectReferencesList.Add(reference); } // Select the references to be renamed DialogResult dialogResult = MessageBox.Show("Do you want to modify the value of the short title (citation key) field of the selected references (including their parallel reporters)?", "Change Short Title (Citation Key)", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { List <Reference> selectedReferences = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences(); foreach (Reference reference in selectedReferences) { references.Add(reference); } } else if (dialogResult == DialogResult.Cancel) { return; } string shortTitleString; int i = 0; List <Reference> dateChangedList = new List <Reference>(); List <string> shortTitlesList = new List <string>(); foreach (Reference currentReference in references) { string data; string ret = ReferenceForms.NewCitationKeyForm("Please enter the new citation key:", out data); shortTitleString = currentReference.ShortTitle.ToStringSafe(); currentReference.CitationKey = ret; currentReference.CitationKeyUpdateType = UpdateType.Manual; i = i + 1; shortTitlesList.Add(shortTitleString); dateChangedList.Add(currentReference); string Date = currentReference.Date; foreach (Reference reference in activeProjectReferencesList) { if (reference == currentReference) { continue; } if (reference.Periodical == null) { continue; } if (!currentReference.Organizations.SequenceEqual(reference.Organizations)) { continue; } if (currentReference.Title != reference.Title) { continue; } if (String.IsNullOrEmpty(currentReference.Title) && (String.IsNullOrEmpty(currentReference.SpecificField2) || currentReference.SpecificField2 != reference.SpecificField2)) { continue; } shortTitleString = reference.ShortTitle.ToStringSafe(); shortTitlesList.Add(shortTitleString); reference.CitationKey = ret; reference.CitationKeyUpdateType = UpdateType.Manual; dateChangedList.Add(reference); i = i + 1; continue; } } DialogResult showFailed = MessageBox.Show(i.ToStringSafe() + " references have been changed:\n •" + String.Join("\n • ", shortTitlesList) + "\nWould you like to show a selection of references where the short title (citation key) has been adjusted?", "Citavi Macro", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (showFailed == DialogResult.Yes) { var filter = new ReferenceFilter(dateChangedList, "Date changed", false); Program.ActiveProjectShell.PrimaryMainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> { filter }); } }
public static void MoveAttachment() { if (Program.ProjectShells.Count == 0) { return; //no project open } Program.ActiveProjectShell.PrimaryMainForm.PreviewControl.ShowNoPreview(); // User Options // Static Variables List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences(); List <Location> locations = references.SelectMany(r => r.Locations).Where(l => l.Address.LinkedResourceType == LinkedResourceType.AttachmentFile).ToList(); Project activeProject = Program.ActiveProjectShell.Project; string citaviAttachmentsFolderPath = activeProject.Addresses.AttachmentsFolderPath; // Dynamic Variables string targetFolder = string.Empty; var fbd = new FolderBrowserDialog(); List <Reference> renamingFailed = new List <Reference>(); int renameCounter = 0; // The Magic targetFolder = citaviAttachmentsFolderPath; fbd.SelectedPath = targetFolder; DialogResult result = fbd.ShowDialog(); if (result == DialogResult.Cancel) { return; } targetFolder = fbd.SelectedPath; foreach (Location location in locations) { string oldFilePath = location.Address.Resolve().LocalPath; FileInfo fileInfo = new FileInfo(oldFilePath); string fileExtension = fileInfo.Extension; if (fileExtension.Equals("pdf", StringComparison.InvariantCultureIgnoreCase)) { return; } string fileName = fileInfo.Name; string newAbsoluteFilePath = targetFolder + @"\" + fileName; if (newAbsoluteFilePath.Equals(oldFilePath)) { continue; } if (File.Exists(newAbsoluteFilePath)) { renamingFailed.Add(location.Reference); continue; } try { location.Address.ChangeFilePathAsync(new System.Uri(newAbsoluteFilePath), AttachmentAction.Move); renameCounter++; } catch (Exception e) { MessageBox.Show("An error has occured while renaming " + location.Address + ":\n" + e.Message, "Citavi Macro", MessageBoxButtons.OK, MessageBoxIcon.Error); renamingFailed.Add(location.Reference); return; } } string message = "{0} locations have been moved."; message = string.Format(message, renameCounter); if (renamingFailed.Count == 0) { MessageBox.Show(message, "Citavi Macro", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { DialogResult showFailed = MessageBox.Show(message + "\n Would you like to show a selection of references where the move has failed?", "Citavi Macro", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (showFailed == DialogResult.Yes) { var filter = new ReferenceFilter(renamingFailed, "Renaming failed", false); Program.ActiveProjectShell.PrimaryMainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> { filter }); return; } } return; }
public static void ExportAnnotations(List <Reference> references) { List <Reference> exportFailed = new List <Reference>(); int exportCounter = 0; PreviewControl previewControl = PreviewMethods.GetPreviewControl(); if (previewControl != null) { previewControl.ShowNoPreview(); } foreach (Reference reference in references) { List <KnowledgeItem> quotations = reference.Quotations.Where(q => q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); List <LinkedResource> linkedResources = reference.Locations.Where(l => l.LocationType == LocationType.ElectronicAddress && l.Address.LinkedResourceType == LinkedResourceType.AttachmentFile).Select(l => (LinkedResource)l.Address).ToList(); List <KnowledgeItem> comments = quotations.Where(q => q.QuotationType == QuotationType.Comment && q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); List <KnowledgeItem> directQuotations = quotations.Where(q => q.QuotationType == QuotationType.DirectQuotation && q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); List <KnowledgeItem> indirectQuotations = quotations.Where(q => q.QuotationType == QuotationType.IndirectQuotation && q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); List <KnowledgeItem> quickReferences = quotations.Where(q => q.QuotationType == QuotationType.QuickReference && q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); List <KnowledgeItem> summaries = quotations.Where(q => q.QuotationType == QuotationType.Summary && q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); foreach (Location location in reference.Locations) { foreach (Annotation annotation in location.Annotations.Where(a => a.Visible == true && a.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() == 0).ToList()) { location.Annotations.Remove(annotation); } foreach (Annotation annotation in location.Annotations.Where(a => a.Visible == false && a.EntityLinks.Where(e => e.Indication == EntityLink.SourceAnnotLinkIndication).Count() == 0 && a.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() == 0).ToList()) { location.Annotations.Remove(annotation); } } foreach (LinkedResource linkedResource in linkedResources) { string pathToFile = linkedResource.Resolve().LocalPath; if (!System.IO.File.Exists(pathToFile)) { continue; } List <Rect> coveredRects = new List <Rect>(); Document document = new Document(pathToFile); if (document == null) { continue; } previewControl.ShowNoPreview(); List <KnowledgeItem> commentsAtThisLocation = comments.Where(d => ((Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).Location.Address == linkedResource).ToList(); List <KnowledgeItem> directQuotationsAtThisLocation = directQuotations.Where(d => d.EntityLinks != null && d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication) != null && ((Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).Location.Address == linkedResource).ToList(); List <KnowledgeItem> indirectQuotationsAtThisLocation = indirectQuotations.Where(d => d.EntityLinks != null && d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication) != null && ((Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).Location.Address == linkedResource).ToList(); List <KnowledgeItem> quickReferencesAtThisLocation = quickReferences.Where(d => ((Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).Location.Address == linkedResource).ToList(); List <KnowledgeItem> summariesAtThisLocation = summaries.Where(d => ((Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).Location.Address == linkedResource).ToList(); List <Annotation> commentAnnotationsAtThisLocation = commentsAtThisLocation.Select(d => (Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).ToList(); List <Annotation> directQuotationAnnotationsAtThisLocation = directQuotationsAtThisLocation.Select(d => (Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).ToList(); List <Annotation> indirectQuotationAnnotationsAtThisLocation = indirectQuotationsAtThisLocation.Select(d => (Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).ToList(); List <Annotation> quickReferenceAnnotationsAtThisLocation = quickReferencesAtThisLocation.Select(d => (Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).ToList(); List <Annotation> summaryAnnotationsAtThisLocation = summaries.Select(d => (Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).ToList(); DeleteExistingHighlights(document); foreach (Annotation annotation in commentAnnotationsAtThisLocation) { System.Drawing.Color highlightColor = KnownColors.AnnotationComment100; CreateHighlightAnnots(annotation, highlightColor, document, coveredRects, out coveredRects); } foreach (Annotation annotation in directQuotationAnnotationsAtThisLocation) { System.Drawing.Color highlightColor = KnownColors.AnnotationDirectQuotation100; CreateHighlightAnnots(annotation, highlightColor, document, coveredRects, out coveredRects); } foreach (Annotation annotation in indirectQuotationAnnotationsAtThisLocation) { System.Drawing.Color highlightColor = KnownColors.AnnotationIndirectQuotation100; CreateHighlightAnnots(annotation, highlightColor, document, coveredRects, out coveredRects); } foreach (Annotation annotation in quickReferenceAnnotationsAtThisLocation) { System.Drawing.Color highlightColor = KnownColors.AnnotationQuickReference100; CreateHighlightAnnots(annotation, highlightColor, document, coveredRects, out coveredRects); } foreach (Annotation annotation in summaryAnnotationsAtThisLocation) { System.Drawing.Color highlightColor = KnownColors.AnnotationSummary100; CreateHighlightAnnots(annotation, highlightColor, document, coveredRects, out coveredRects); } try { document.Save(pathToFile, SDFDoc.SaveOptions.e_remove_unused); exportCounter++; } catch { exportFailed.Add(reference); } document.Close(); } } string message = "Annotations exported to {0} locations."; message = string.Format(message, exportCounter); if (exportFailed.Count == 0) { MessageBox.Show(message, "Citavi", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { DialogResult showFailed = MessageBox.Show(message + "\n Would you like to show a selection of references where export has failed?", "Citavi Macro", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (showFailed == DialogResult.Yes) { var filter = new ReferenceFilter(exportFailed, "Export failed", false); Program.ActiveProjectShell.PrimaryMainForm.ReferenceEditorFilterSet.Filters.ReplaceBy(new List <ReferenceFilter> { filter }); } } }