Ejemplo n.º 1
0
 /// <summary>
 /// replaces an enqueued request with an updated version of that request. Is the old request not found, then the replacement will be added normaly,
 /// </summary>
 /// <param name="toReplace"></param>
 /// <param name="replacement"></param>
 public void Replace(IPdfRequest toReplace, IPdfRequest replacement)
 {
     lock (synchronisationLock)
     {
         if (firstElement == null || firstElement.value.Priority < replacement.Priority)
         {
             firstElement = new QueueElement <IPdfRequest>(replacement, firstElement);
             Monitor.Pulse(synchronisationLock);
         }
         else if (firstElement.value == toReplace)
         {
             firstElement.value = replacement;
         }
         else
         {
             QueueElement <IPdfRequest> element = firstElement;
             while (element.next != null && element.next.value.Priority >= toReplace.Priority && element.next.value != toReplace)
             {
                 element = element.next;
             }
             if (element.next != null && element.next.value == toReplace)
             {
                 element.next.value = replacement;
             }
             else
             {
                 element.next = new QueueElement <IPdfRequest>(replacement, element.next);
                 Monitor.Pulse(synchronisationLock);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void CancelRequest(IPdfRequest request)
 {
     requestQueue.CancelRequest(request);
     if (request.GetType().IsInstanceOfType(typeof(PdfLoadThumbnailRequest)))
     {
         thumbnailCache.CancelPendingRequest((PdfLoadThumbnailRequest)request);
     }
     else if (request.GetType().IsInstanceOfType(typeof(PdfGetPageRectRequest)))
     {
         pageCache.CancelPendingRequest((PdfGetPageRectRequest)request);
     }
     else if (request.GetType().IsInstanceOfType(typeof(PdfGetTextFragmentsRequest)))
     {
         textFragmentCache.CancelPendingRequest((PdfGetTextFragmentsRequest)request);
     }
     request.Cancel();
 }
Ejemplo n.º 3
0
 public void CancelRequest(IPdfRequest request)
 {
     lock (synchronisationLock)
     {
         if (firstElement == null)
         {
             return;
         }
         QueueElement <IPdfRequest> element = firstElement;
         while (element.next != null)
         {
             if (element.next.value.Equals(request))
             {
                 element.next = element.next.next;//remove request
                 return;
             }
             element = element.next;
         }
     }
 }
Ejemplo n.º 4
0
        public void Add(IPdfRequest request, bool overtakeRequestsWithSamePriority = false)
        {
            lock (synchronisationLock)
            {
                if (firstElement == null)
                {
                    firstElement = new QueueElement <IPdfRequest>(request, null);
                }
                else
                {
                    //traverse queue until we reach the location where to insert the request
                    QueueElement <IPdfRequest> element = firstElement;
                    while (element.next != null && (element.next.value.Priority >= request.Priority || (element.next.value.Priority > request.Priority)))
                    {
                        element = element.next;
                    }

                    //now insert request in between element and element.next
                    element.next = new QueueElement <IPdfRequest>(request, element.next);
                }
                Monitor.Pulse(synchronisationLock);
            }
        }
Ejemplo n.º 5
0
        // source and targetrects may be empty! (due to crops with pages etc.)
        public PdfDrawRequest Draw(int width, int height, Resolution resolution, int rotation, IDictionary <int, PdfSourceRect> pageRects, PdfViewerController.Viewport viewport)
        {
            IList <KeyValuePair <int, PdfSourceRect> > newPageRects = new List <KeyValuePair <int, PdfSourceRect> >();

            foreach (int key in pageRects.Keys)
            {
                int newKey;
                if (key - 1 < _pageOrder.Count)
                {
                    newKey = _pageOrder[key - 1];
                }
                else
                {
                    continue;
                }

                if (newKey > document.PageCount)
                {
                    continue;
                }
                newPageRects.Add(new KeyValuePair <int, PdfSourceRect>(newKey, pageRects[key]));
            }

            PdfDrawRequest request = new PdfDrawRequest(new DrawArgs(width, height, resolution, rotation, newPageRects, viewport));

            if (lastDrawRequest == null)
            {
                requestQueue.Add(request);
            }
            else
            {
                requestQueue.Replace(lastDrawRequest, request);
            }
            lastDrawRequest = request;
            //add new draw request
            return(request);
        }