// Problem:
 // Enter Test data
 // (Delete it) optional
 // Enter Test data again
 // Because we cached it and passed it to citeproc, it has stuff added to it
 // and is no longer suitable to put into the inline text
 // Need to store multiple items per itemSource incl. First raw data
 // That is what gets put into inline text whereas the rest can be reused.
 // Note. This may not be enough and if an identical citation is inserted
 // later and we reuse cached item, may be a problem. RawJSCitation seems untouched
 // and could be reused.
 // DocumentController.CreateInlineCitation currently sets Locator, this should be
 // done in here once and for all.
 // Change ItemData to "item" may solve the problem of duplicate data but the inlined code
 // text still has the sort keys
 // CitationInserter.CreateFieldCodeText is the key - it is using JSON Before it gets sent
 // to CiteProc - Edit/refresh/Reuse however will have had the additional items in there
 // but we only need to get the original JSON information from the cache.
 public JSInlineCitationItem CreateJSInlineCitationItem(EntryAndPagePair itemSource)
 {
     return(new JSInlineCitationItem(this)
     {
         ID = itemSource.Entry.Name,                         // Note no '#'!!
         Locator = itemSource.PageNumberOverride,
         AuthorOnly = itemSource.AuthorProcessorControl == AuthorProcessorControl.AuthorOnly ? (object)1 : null,
         SuppressAuthor = itemSource.AuthorProcessorControl == AuthorProcessorControl.SuppressAuthor ? (object)1 : null,
         ItemData = FetchOrCreateJSRawCitationItem(itemSource.ID)
     });
 }
        public JSRawCitationItem CreateJSRawCitationItem(EntryAndPagePair entryAndPagePair)
        {
            if (entryAndPagePair == null) throw new ArgumentNullException("entryAndPagePair");

            var result = new JSRawCitationItem(context)
                         	{
                         		ID = entryAndPagePair.ID,
                                Type = GetType(entryAndPagePair.Entry.Classification)
                         	};

            new Converter(result, entryAndPagePair.Entry).ConvertItem();

            return result;
        }
        JSRawCitationItem FetchOrCreateJSRawCitationItem(string id)
        {
            JSRawCitationItem result;

            if (!jsRawCitationItemCache.TryGetValue(id, out result))
            {
                EntryAndPagePair thePair = CreateEntryAndPagePairByID(id);

                result = new BibTexToCSLConverter(this).CreateJSRawCitationItem(thePair);

                jsRawCitationItemCache[id] = result;
            }

            return(result);
        }
        public JSRawCitationItem CreateJSRawCitationItem(EntryAndPagePair entryAndPagePair)
        {
            if (entryAndPagePair == null)
            {
                throw new ArgumentNullException("entryAndPagePair");
            }

            var result = new JSRawCitationItem(context)
            {
                ID   = entryAndPagePair.ID,
                Type = GetType(entryAndPagePair.Entry.Classification)
            };

            new Converter(result, entryAndPagePair.Entry).ConvertItem();

            return(result);
        }
		// Problem:
		// Enter Test data
		// (Delete it) optional
		// Enter Test data again
		// Because we cached it and passed it to citeproc, it has stuff added to it
		// and is no longer suitable to put into the inline text
		// Need to store multiple items per itemSource incl. First raw data
		// That is what gets put into inline text whereas the rest can be reused.
		// Note. This may not be enough and if an identical citation is inserted
		// later and we reuse cached item, may be a problem. RawJSCitation seems untouched
		// and could be reused.
		// DocumentController.CreateInlineCitation currently sets Locator, this should be
		// done in here once and for all.
		// Change ItemData to "item" may solve the problem of duplicate data but the inlined code
		// text still has the sort keys
		// CitationInserter.CreateFieldCodeText is the key - it is using JSON Before it gets sent
		// to CiteProc - Edit/refresh/Reuse however will have had the additional items in there
		// but we only need to get the original JSON information from the cache.
		public JSInlineCitationItem CreateJSInlineCitationItem(EntryAndPagePair itemSource)
		{            
			return new JSInlineCitationItem(this)
			       	{
			       		ID = itemSource.Entry.Name, // Note no '#'!!
			       		Locator = itemSource.PageNumberOverride,
						AuthorOnly = itemSource.AuthorProcessorControl == AuthorProcessorControl.AuthorOnly ? (object) 1 : null,
						SuppressAuthor = itemSource.AuthorProcessorControl == AuthorProcessorControl.SuppressAuthor ? (object) 1 : null,
			       		ItemData = FetchOrCreateJSRawCitationItem(itemSource.ID)
			       	};
		}
			public JSInlineCitation CreateInlineCitation(EntryAndPagePair itemSource, object idToUse = null) { return CreateInlineCitation(new[] { itemSource }, idToUse); }
		public void CheckSameReferenceWithDifferentPagesProducesSingleEntryInBibliography()
		{
			var citeProc = new CiteProcRunner(MlaCslStyle, () => DocearDatabase);
			var citeInserter = new TestCitationInserter(citeProc);

			var citation1 = new EntryAndPagePair(DocearDatabase["price65"], "1");
			var citation2 = new EntryAndPagePair(DocearDatabase["price65"], "2");

			var entryAndPagePairs =
				new[]
					{
						citation1,
						citation2
					};

			var inlineCitation1 = citeInserter.CreateInlineCitation(citation1);
			var inlineCitation2 = citeInserter.CreateInlineCitation(citation2);

			var jsCitations = new object[0];
			var jsResult = citeProc.RestoreProcessorState(jsCitations);



			var bibliographyResult = citeProc.MakeBibliography();

		}