Example #1
0
        public int Compare(Citation x, Citation y)
        {
            /*
             *      This is an example of a custom sort macro that sorts all references of type 'internet document' on top of the bibliography.
             *      The internet documents themselves are sorted according to a different logic than the rest of the cited documents.
             *      Return values:
             *      0:					x is considered the same as y sorting-wise, so we cannot tell a difference based on the algorithm below
             *      > 0 (positive):		x should go after y, x is greater than y
             *      < 0 (negative):		x should go before y, x is less than
             */

            //First we make sure we are comparing BibliographyCitations only
            var xBibliographyCitation = x as BibliographyCitation;
            var yBibliographyCitation = y as BibliographyCitation;

            if (xBibliographyCitation == null || yBibliographyCitation == null)
            {
                return(0);
            }
            var xReference = xBibliographyCitation.Reference;
            var yReference = yBibliographyCitation.Reference;

            if (xReference == null || yReference == null)
            {
                return(0);
            }


            var xBibliographyEntry = x.GetTextUnits().ToString();
            var yBibliographyEntry = y.GetTextUnits().ToString();

            if (string.IsNullOrEmpty(xBibliographyEntry) || string.IsNullOrEmpty(yBibliographyEntry))
            {
                return(0);
            }

            var xFirstLetter = xBibliographyEntry.Substring(0, 1);
            var yFirstLetter = yBibliographyEntry.Substring(0, 1);

            var xIsCyrillic = IsCyrillic(xFirstLetter);
            var yIsCyrillic = IsCyrillic(yFirstLetter);

            if ((xIsCyrillic && yIsCyrillic) || (!xIsCyrillic && !yIsCyrillic))
            {
                return(xBibliographyEntry.CompareTo(yBibliographyEntry));
            }
            else if (xIsCyrillic && !yIsCyrillic)
            {
                return(-1);
            }
            else if (!xIsCyrillic && yIsCyrillic)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
        public int Compare(Citation x, Citation y)
        {
            //First we make sure we are comparing BibliographyCitations only
            var xBibliographyCitation = x as BibliographyCitation;
            var yBibliographyCitation = y as BibliographyCitation;

            if (xBibliographyCitation == null || yBibliographyCitation == null)
            {
                return(0);
            }
            var xReference = xBibliographyCitation.Reference;
            var yReference = yBibliographyCitation.Reference;

            if (xReference == null || yReference == null)
            {
                return(0);
            }


            var xBibliographyEntry = GetTextForSorting(x.GetTextUnits().ToString());
            var yBibliographyEntry = GetTextForSorting(y.GetTextUnits().ToString());

            return(xBibliographyEntry.CompareTo(yBibliographyEntry));
        }
Example #3
0
        public int Compare(Citation x, Citation y)
        {
            //First we make sure we are comparing BibliographyCitations only
            var xBibliographyCitation = x as BibliographyCitation;
            var yBibliographyCitation = y as BibliographyCitation;

            if (xBibliographyCitation == null || yBibliographyCitation == null)
            {
                return(0);
            }
            var xReference = xBibliographyCitation.Reference;
            var yReference = yBibliographyCitation.Reference;

            if (xReference == null || yReference == null)
            {
                return(0);
            }


            var xYearResolved = xReference.YearResolved;
            var yYearResolved = yReference.YearResolved;

            var xBibliographyEntry = x.GetTextUnits().ToString();
            var yBibliographyEntry = y.GetTextUnits().ToString();

            string xBibliographyEntryBeforeYear = xBibliographyEntry;
            string yBibliographyEntryBeforeYear = yBibliographyEntry;

            //Autor, Herausgeber oder Institution oder was auch immer im Template zu Beginn vor der Jahresangabe steht, aufsteigend
            if (!string.IsNullOrEmpty(xYearResolved))
            {
                int xIndexOfYearResolved = xBibliographyEntry.IndexOf(xYearResolved, 0);
                if (xIndexOfYearResolved > 0)
                {
                    xBibliographyEntryBeforeYear = xBibliographyEntry.Substring(0, xIndexOfYearResolved);
                }
            }
            if (!string.IsNullOrEmpty(yYearResolved))
            {
                int yIndexOfYearResolved = yBibliographyEntry.IndexOf(yYearResolved, 0);
                if (yIndexOfYearResolved > 0)
                {
                    yBibliographyEntryBeforeYear = yBibliographyEntry.Substring(0, yIndexOfYearResolved);
                }
            }
            var alphabeticalSortResult = xBibliographyEntryBeforeYear.CompareTo(yBibliographyEntryBeforeYear);

            if (alphabeticalSortResult != 0)
            {
                return(alphabeticalSortResult);
            }

            //Jahr ermittelt, absteigend
            var sortDescriptors = new List <PropertySortDescriptor <Reference> >();

            sortDescriptors.Add(new PropertySortDescriptor <Reference>(ReferencePropertyDescriptor.YearResolved, ListSortDirection.Descending));
            var yearComparer   = new CitationComparer(sortDescriptors);
            var yearSortResult = yearComparer.Compare(x, y);

            if (yearSortResult != 0)
            {
                return(yearSortResult);
            }

            //Titel, aufsteigend
            sortDescriptors.Clear();
            sortDescriptors.Add(new PropertySortDescriptor <Reference>(ReferencePropertyDescriptor.Title, ListSortDirection.Ascending));
            var titleComparer   = new CitationComparer(sortDescriptors);
            var titleSortResult = titleComparer.Compare(x, y);

            if (titleSortResult != 0)
            {
                return(titleSortResult);
            }

            //Band, absteigend
            sortDescriptors.Clear();
            sortDescriptors.Add(new PropertySortDescriptor <Reference>(ReferencePropertyDescriptor.Volume, ListSortDirection.Descending));
            var volumeComparer   = new CitationComparer(sortDescriptors);
            var volumeSortResult = volumeComparer.Compare(x, y);

            if (volumeSortResult != 0)
            {
                return(volumeSortResult);
            }

            //Datum des Zugriffs, absteigend
            sortDescriptors.Clear();
            sortDescriptors.Add(new PropertySortDescriptor <Reference>(ReferencePropertyDescriptor.AccessDate, ListSortDirection.Descending));
            var accessDateComparer   = new CitationComparer(sortDescriptors);
            var accessDateSortResult = accessDateComparer.Compare(x, y);

            return(accessDateSortResult);
        }