Beispiel #1
0
        public string GenerateInlineCitation(string selectedText)
        {
            string[] allReferences = GetAllReferences(selectedText);
            if (allReferences.Length == 0)
            {
                return(null);
            }

            string finalReference             = "";
            int    workingWithReferenceNumber = 0;

            foreach (string reference in allReferences)
            {
                workingWithReferenceNumber++;

                ReferenceObject referenceParts = GetReferenceParts(reference);
                if (referenceParts == null)
                {
                    continue;
                }
                if (referenceParts.authors.Length == 0)
                {
                    continue;
                }

                if (referenceParts.useEtAl)
                {
                    finalReference += referenceParts.authors[0] + " et al.";
                }
                else
                {
                    foreach (string author in referenceParts.authors)
                    {
                        finalReference += author + " and ";
                    }

                    finalReference = finalReference.Substring(0, finalReference.Length - 5); //chop of the last and
                }

                if ((allReferences.Length - 1) == workingWithReferenceNumber)
                {
                    finalReference += " (" + referenceParts.date + ") and ";
                }
                else
                {
                    finalReference += " (" + referenceParts.date + "), ";
                }
            }

            finalReference = finalReference.Trim();

            if (!string.IsNullOrWhiteSpace(finalReference))
            {
                finalReference = finalReference.Substring(0, finalReference.Length - 1); //chop off last ,
            }

            return(finalReference);
        }
Beispiel #2
0
        public string GenerateEndCitation(string selectedText)
        {
            string[] allReferences = GetAllReferences(selectedText);
            if (allReferences.Length == 0)
            {
                return(null);
            }

            string finalReference = "";

            foreach (string reference in allReferences)
            {
                ReferenceObject referenceParts = GetReferenceParts(reference);
                if (referenceParts == null)
                {
                    continue;
                }
                if (referenceParts.authors.Length == 0)
                {
                    continue;
                }

                if (referenceParts.useEtAl)
                {
                    finalReference += referenceParts.authors[0] + " et al.";
                }
                else
                {
                    foreach (string author in referenceParts.authors)
                    {
                        finalReference += author + "&";
                    }

                    finalReference = finalReference.Substring(0, finalReference.Length - 1); //chop of the last &
                }

                //add the date
                finalReference += ", " + referenceParts.date + "; ";
            }

            if (!string.IsNullOrWhiteSpace(finalReference))
            {
                finalReference = finalReference.Trim();
                finalReference = finalReference.Substring(0, finalReference.Length - 1);
                finalReference = "(" + finalReference + ")";
            }

            return(finalReference);
        }
Beispiel #3
0
        private ReferenceObject GetReferenceParts(string selectedText)
        {
            string referenceText = GetReferenceText(selectedText);

            ReferenceObject referenceParts = new ReferenceObject();

            if (string.IsNullOrWhiteSpace(referenceText))
            {
                return(null);
            }

            //find the date
            var    indexOfLastComma   = referenceText.LastIndexOf(",");
            string possibleDateString = referenceText.Substring(indexOfLastComma + 1);
            int    result             = -1;

            int.TryParse(possibleDateString, out result);
            if (result > -1)
            {
                if (result.ToString().Length == 4)
                {
                    referenceParts.date = result.ToString();
                }
            }

            //chop off the date
            referenceText = referenceText.Replace(possibleDateString, "");
            referenceParts.referenceText = referenceText;

            //split the authors
            referenceParts.authors = referenceText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (referenceParts.authors.Length > 1)
            {
                referenceParts.useEtAl = true;
            }

            return(referenceParts);
        }