コード例 #1
0
        private static List <Person> GetPersonsDisplayed(PersonFieldElement element, Reference reference)
        {
            if (element == null)
            {
                return(null);
            }
            if (reference == null)
            {
                return(null);
            }

            ReferencePersonCollection personCollection = reference.GetValue(element.PropertyId) as ReferencePersonCollection;

            if (personCollection == null || personCollection.Count == 0)
            {
                return(null);
            }

            List <Person> persons = new List <Person>(personCollection);

            return(persons);
        }
        public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled)
        {
            //change the following to "true", if you want "id.", "eid.", "ead.", "eaed." written in italics or other font styles
            bool outputInItalics   = true;
            bool outputInSmallCaps = false;
            bool outputInBold      = false;
            bool outputUnderlined  = false;

            //NOTE: If you want a prefix such as "In: " and a suffix " (Hrsg)", you can define them as group prefix and suffix on the field element inside the component part editor

            handled = false;

            if (componentPart == null)
            {
                return(null);
            }
            if (componentPart.Elements == null || componentPart.Elements.Count == 0)
            {
                return(null);
            }

            if (citation == null)
            {
                return(null);
            }

            Reference reference = citation.Reference;

            if (reference == null)
            {
                return(null);
            }

            Reference parentReference = reference.ParentReference;

            if (parentReference == null)
            {
                return(null);
            }


            //get editor person field elements (or authors in case of CollectedWorks) and make it a separate List<>, since we are going to change that collection below
            List <PersonFieldElement> editorPersonFieldElements =
                parentReference.ReferenceType == ReferenceType.CollectedWorks ?
                componentPart.Elements.OfType <PersonFieldElement>().Where(element => element.PropertyId == ReferencePropertyId.Authors).ToList() :
                componentPart.Elements.OfType <PersonFieldElement>().Where(element => element.PropertyId == ReferencePropertyId.Editors).ToList();

            if (editorPersonFieldElements == null || editorPersonFieldElements.Count() == 0)
            {
                return(null);
            }



            //we DO have a valid citation/reference that is a parent's child
            ReferencePersonCollection childAuthorsCollection = reference.Authors;

            if (childAuthorsCollection == null || childAuthorsCollection.Count == 0)
            {
                return(null);
            }
            List <Person> childAuthors = new List <Person>(childAuthorsCollection);

            ReferencePersonCollection parentEditorsCollection = parentReference.ReferenceType == ReferenceType.CollectedWorks ? parentReference.Authors : parentReference.Editors;

            if (parentEditorsCollection == null || parentEditorsCollection.Count == 0)
            {
                return(null);
            }
            List <Person> parentEditors = new List <Person>(parentEditorsCollection);

            bool usePlural = parentEditors.Count() > 1;

            PersonEquality equality = CheckPersonEquality(childAuthors, parentEditors);

            if (equality == PersonEquality.None)
            {
                return(null);
            }


            //we DO have some equality, so let's check what we need to output instead of the person's name(s)
            var textIdem = string.Empty;

            switch (equality)
            {
            //see http://en.wiktionary.org/wiki/idem#Inflection
            case PersonEquality.M:
            case PersonEquality.N:
                textIdem = "id.";
                break;

            case PersonEquality.F:
                textIdem = "ead.";
                break;

            case PersonEquality.NN:
                textIdem = "ead.";
                break;

            case PersonEquality.MM:
                textIdem = "iid.";
                break;

            case PersonEquality.MN:
            case PersonEquality.FM:
            case PersonEquality.FMN:
                textIdem = "eid.";
                break;

            case PersonEquality.FF:
            case PersonEquality.FN:
                textIdem = "eaed.";
                break;
            }

            foreach (PersonFieldElement editors in editorPersonFieldElements)
            {
                TextUnitCollection output = new TextUnitCollection();

                #region GroupPrefix

                if (usePlural && !string.IsNullOrEmpty(editors.GroupPrefixPlural.Text))
                {
                    output.Add(new LiteralTextUnit(editors.GroupPrefixPlural.Text, editors.GroupPrefixPlural.FontStyle));
                }
                else if (!usePlural & !string.IsNullOrEmpty(editors.GroupPrefixSingular.Text))
                {
                    output.Add(new LiteralTextUnit(editors.GroupPrefixSingular.Text, editors.GroupPrefixSingular.FontStyle));
                }

                #endregion GroupPrefix

                SwissAcademic.Drawing.FontStyle fontStyle;
                fontStyle = SwissAcademic.Drawing.FontStyle.Neutral;
                if (outputInItalics)
                {
                    fontStyle |= SwissAcademic.Drawing.FontStyle.Italic;
                }
                if (outputInSmallCaps)
                {
                    fontStyle |= SwissAcademic.Drawing.FontStyle.SmallCaps;
                }
                if (outputInBold)
                {
                    fontStyle |= SwissAcademic.Drawing.FontStyle.Bold;
                }
                if (outputUnderlined)
                {
                    fontStyle |= SwissAcademic.Drawing.FontStyle.Underline;
                }

                var fontStyleNeutral = SwissAcademic.Drawing.FontStyle.Neutral;

                output.Add(new LiteralTextUnit(textIdem, fontStyle));

                #region GroupSuffix

                if (usePlural && !string.IsNullOrEmpty(editors.GroupSuffixPlural.Text))
                {
                    output.Add(new LiteralTextUnit(editors.GroupSuffixPlural.Text, editors.GroupSuffixPlural.FontStyle));
                }
                else if (!usePlural && !string.IsNullOrEmpty(editors.GroupSuffixSingular.Text))
                {
                    output.Add(new LiteralTextUnit(editors.GroupSuffixSingular.Text, editors.GroupSuffixSingular.FontStyle));
                }

                #endregion GroupSuffix


                //inject this as LiteralElements into the componentPart, replacing the editors person field element
                componentPart.Elements.ReplaceItem(editors, TextUnitsToLiteralElements(output, componentPart));                 //for some reason this does not work
            }

            handled = false;
            return(null);
        }
コード例 #3
0
        private bool IsConditionMet(Reference reference, ReferencePropertyDescriptor property, Ensure ensure)
        {
            if (ensure == Ensure.Ignore)
            {
                return(true);
            }
            if (reference == null)
            {
                return(true);
            }
            if (property == null)
            {
                return(true);
            }

            #region String

            if (property.DataType == typeof(string))
            {
                string content = (string)reference.GetValue(property.PropertyId);
                if (string.IsNullOrEmpty(content))
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion String

            #region ReferencePersonCollection or NotificationCollection<Person>

            if (property.DataType == typeof(ReferencePersonCollection))
            {
                ReferencePersonCollection persons = (ReferencePersonCollection)reference.GetValue(property.PropertyId);
                if (persons == null || persons.Count == 0)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            if (property.DataType == typeof(NotificationCollection <Person>))
            {
                NotificationCollection <Person> persons = (NotificationCollection <Person>)reference.GetValue(property.PropertyId);
                if (persons == null || persons.Count == 0)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion ReferencePersonCollection or NotificationCollection<Person>

            #region ReferenceCategoryCollection

            if (property.DataType == typeof(ReferenceCategoryCollection))
            {
                if (reference.Categories == null || reference.Categories.Count == 0)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion ReferenceCategoryCollection

            #region ReferenceChildReferenceCollection

            if (property.DataType == typeof(ReferenceChildReferenceCollection))
            {
                if (reference.ChildReferences == null || reference.ChildReferences.Count == 0)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion ReferenceChildReferenceCollection

            #region bool

            if (property.DataType == typeof(bool))
            {
                bool?boolValue = (bool)reference.GetValue(property.PropertyId);
                if (!boolValue.GetValueOrDefault(false))
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion bool

            #region Isbn

            if (property.DataType == typeof(Isbn))
            {
                Isbn isbn = (Isbn)reference.GetValue(property.PropertyId);
                if (string.IsNullOrWhiteSpace(isbn.InputString))
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion Isbn

            #region ReferenceKeywordCollection

            if (property.DataType == typeof(ReferenceKeywordCollection))
            {
                if (reference.Keywords == null || reference.Keywords.Count == 0)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion ReferenceKeywordCollection

            #region ReferenceLocationCollection

            if (property.DataType == typeof(ReferenceLocationCollection))
            {
                if (reference.Locations == null || reference.Locations.Count == 0)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion ReferenceLocationCollection

            #region ParentReference

            if (property.DataType == typeof(Reference))
            {
                if (reference.ParentReference == null)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion ParentReference

            #region Periodical

            if (property.DataType == typeof(Periodical))
            {
                if (reference.Periodical == null)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion Periodical

            #region ReferencePublisherCollection

            if (property.DataType == typeof(ReferencePublisherCollection))
            {
                if (reference.Publishers == null || reference.Publishers.Count == 0)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion ReferencePublisherCollection

            #region RefernceQuotationCollection

            if (property.DataType == typeof(ReferenceQuotationCollection))
            {
                if (reference.Quotations == null || reference.Quotations.Count == 0)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion ReferenceQuotationCollection

            #region SeriesTitle

            if (property.DataType == typeof(SeriesTitle))
            {
                if (reference.SeriesTitle == null)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion SeriesTitle

            #region Editors

            if (property.DataType == SeriesTitlePropertyDescriptor.Editors.DataType)
            {
                if (reference.Editors == null || !reference.Editors.Any())
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion Editors

            #region ReferenceReferenceTaskCollection

            if (property.DataType == typeof(ReferenceReferenceTaskCollection))
            {
                if (reference.Tasks == null || reference.Tasks.Count == 0)
                {
                    return(ensure == Ensure.IsEmpty);
                }
                else
                {
                    return(ensure == Ensure.IsNotEmpty);
                }
            }

            #endregion Reference

            return(true);
        }