private static InTextCitation GetPreviousVisibleInTextCitation(InTextCitation thisInTextCitation) { if (thisInTextCitation == null) { return(null); } InTextCitation previousInTextCitation = thisInTextCitation; //consider bibonly do { previousInTextCitation = previousInTextCitation.PreviousInTextCitation; if (previousInTextCitation == null) { return(null); } } while (previousInTextCitation.BibOnly == true); //still here? found one! return(previousInTextCitation); }
private static Citation GetPreviousVisibleCitation(Citation citation) { if (citation == null) { return(null); } #region Bibliography if (citation.CitationType == CitationType.Bibliography) { BibliographyCitation previousBibliographyCitation = citation as BibliographyCitation; if (previousBibliographyCitation == null) { return(null); } //consider nobib do { previousBibliographyCitation = previousBibliographyCitation.PreviousBibliographyCitation; if (previousBibliographyCitation == null) { return(null); } } while (previousBibliographyCitation.NoBib == true); //still here? found one! return(previousBibliographyCitation); } #endregion Bibliography #region InText if (citation.CitationType == CitationType.InText) { InTextCitation previousInTextCitation = citation as InTextCitation; if (previousInTextCitation == null) { return(null); } //consider bibonly do { previousInTextCitation = previousInTextCitation.PreviousInTextCitation; if (previousInTextCitation == null) { return(null); } } while (previousInTextCitation.BibOnly == true); //still here? found one! return(previousInTextCitation); } #endregion InText #region Footnote if (citation.CitationType == CitationType.Footnote) { FootnoteCitation previousFootnoteCitation = citation as FootnoteCitation; if (previousFootnoteCitation == null) { return(null); } //consider bibonly do { previousFootnoteCitation = previousFootnoteCitation.PreviousFootnoteCitation; if (previousFootnoteCitation == null) { return(null); } } while (previousFootnoteCitation.BibOnly == true); //still here? found one! return(previousFootnoteCitation); } #endregion Footnote //still here? no visible previous citation found! return(null); }
//Other reference of same author(s)/editor(s)/organization(s) cited BEFORE public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { var testEqualityBy = PersonIdentityTest.ByInternalID; //adjust here to your needs //e.g. PersonIdentityTest.ByLastNameFirstName //e.g. PersonIdentityText.ByFullName //e.g. PersonIdentityTest.ByInternalID <- recommended for most cases bool considerNoBibInBibliographyCitations = false; bool considerNoBibInInTextCitations = false; bool considerNoBibInFootnoteCitations = false; if (citation == null) { return(false); } CitationManager citationManager = citation.CitationManager; if (citationManager == null) { return(false); } Reference currentReference = citation.Reference; if (currentReference == null) { return(false); } IEnumerable <Person> currentPersons = currentReference.AuthorsOrEditorsOrOrganizations; if (currentPersons == null || currentPersons.Count() == 0) { return(false); } IEnumerable <PublicationCitation> allCitations = null; PublicationCitation currentPublicationCitation = citation as PublicationCitation; if (currentPublicationCitation == null) { return(false); } #region InTextCitations InTextCitation currentInTextCitation = citation as InTextCitation; if (currentInTextCitation != null) { if (currentInTextCitation.BibOnly) { return(false); } allCitations = considerNoBibInInTextCitations ? citationManager.InTextCitations.Where(item => !item.BibOnly).Cast <PublicationCitation>() : citationManager.InTextCitations.Where(item => !item.BibOnly && item.CorrespondingBibliographyCitation != null && !item.CorrespondingBibliographyCitation.NoBib.GetValueOrDefault(false)); } #endregion #region FootnoteCitations if (allCitations == null) { FootnoteCitation currentFootnoteCitation = citation as FootnoteCitation; if (currentFootnoteCitation != null) { if (currentFootnoteCitation.BibOnly) { return(false); } allCitations = considerNoBibInFootnoteCitations ? citationManager.FootnoteCitations.Where(item => !item.BibOnly).Cast <PublicationCitation>() : citationManager.FootnoteCitations.Where(item => !item.BibOnly && item.CorrespondingBibliographyCitation != null && !item.CorrespondingBibliographyCitation.NoBib.GetValueOrDefault(false)); } } #endregion #region BibliographyCitations if (allCitations == null) { BibliographyCitation currentBibliographyCitation = citation as BibliographyCitation; if (currentBibliographyCitation.NoBib.GetValueOrDefault(false)) { return(false); } if (currentBibliographyCitation != null) { allCitations = citationManager.BibliographyCitations.Where(item => !item.NoBib.GetValueOrDefault(false)).Cast <PublicationCitation>(); } } #endregion IEnumerable <string> currentIdentifiers = GetPersonIdentifiers(currentPersons, testEqualityBy); foreach (PublicationCitation otherPublicationCitation in allCitations) { if (otherPublicationCitation == null) { continue; } if (otherPublicationCitation == currentPublicationCitation) { break; } var otherReference = otherPublicationCitation.Reference; if (otherReference == null) { continue; } if (otherReference == currentReference) { continue; } var otherPersons = otherReference.AuthorsOrEditorsOrOrganizations; if (otherPersons == null || otherPersons.Count() == 0) { continue; } var otherIdentifiers = GetPersonIdentifiers(otherPersons, testEqualityBy); if (testEqualityBy == PersonIdentityTest.ByInternalID) { //object identity if (otherPersons.SequenceEqual(currentPersons)) { return(true); } } else { if (otherIdentifiers.SequenceEqual(currentIdentifiers)) { return(true); } } } return(false); }
public bool IsTemplateForReference(ConditionalTemplate template, Citation citation) { if (citation == null) { return(false); } if (citation.CitationManager == null) { return(false); } if (citation.Reference == null) { return(false); } if (citation.Reference.Periodical == null) { return(false); } FootnoteCitation currentFootnoteCitation = citation as FootnoteCitation; if (currentFootnoteCitation != null) { if (currentFootnoteCitation.RuleSetOverride != RuleSetOverride.None) { return(false); } if (currentFootnoteCitation.YearOnly || currentFootnoteCitation.PersonOnly) { return(false); } foreach (FootnoteCitation otherFootnoteCitation in citation.CitationManager.FootnoteCitations) { if (otherFootnoteCitation == currentFootnoteCitation) { break; } if (otherFootnoteCitation.Reference == null) { continue; } if (otherFootnoteCitation.Reference.Periodical == null) { continue; } if (otherFootnoteCitation.Reference.Periodical.Equals(currentFootnoteCitation.Reference.Periodical)) { return(true); } } //still here? return(false); } InTextCitation currentInTextCitation = citation as InTextCitation; if (currentInTextCitation != null) { if (currentInTextCitation.RuleSetOverride != RuleSetOverride.None) { return(false); } if (currentInTextCitation.YearOnly || currentInTextCitation.PersonOnly) { return(false); } foreach (InTextCitation otherInTextCitation in citation.CitationManager.InTextCitations) { if (otherInTextCitation == currentInTextCitation) { break; } if (otherInTextCitation.Reference == null) { continue; } if (otherInTextCitation.Reference.Periodical == null) { continue; } if (otherInTextCitation.Reference.Periodical.Equals(currentInTextCitation.Reference.Periodical)) { return(true); } } //still here? return(false); } BibliographyCitation currentBibliographyCitation = citation as BibliographyCitation; if (currentBibliographyCitation != null) { foreach (BibliographyCitation otherBibliographyCitation in citation.CitationManager.BibliographyCitations) { if (otherBibliographyCitation == currentBibliographyCitation) { break; } if (otherBibliographyCitation.Reference == null) { continue; } if (otherBibliographyCitation.Reference.Periodical == null) { continue; } if (otherBibliographyCitation.Reference.Periodical.Equals(currentBibliographyCitation.Reference.Periodical)) { return(true); } } //still here return(false); } return(false); }