Ejemplo n.º 1
0
 private void ImageRead(PipeRequest request, Pipe pipe)
 {
     if (Active)
     {
         _imageRequest = null;
         try
         {
             if (request.Result.IsNative)
             {
                 byte[] resultBytes = request.Result.AsByteArray;
                 SetImage(System.Drawing.Image.FromStream(new MemoryStream(resultBytes, 0, resultBytes.Length, false, true)));
             }
             else
             {
                 using (Stream stream = request.Result.OpenStream())
                 {
                     MemoryStream copyStream = new MemoryStream();
                     StreamUtility.CopyStream(stream, copyStream);
                     SetImage(System.Drawing.Image.FromStream(copyStream));
                 }
             }
         }
         catch
         {
             SetImage(ImageUtility.GetErrorImage());
         }
     }
 }
Ejemplo n.º 2
0
 protected void ImageRead(PipeRequest request, Pipe pipe)
 {
     _imageRequest = null;
     try
     {
         if (request.Result.IsNative)
         {
             byte[] resultBytes = request.Result.AsByteArray;
             _image = System.Drawing.Image.FromStream(new MemoryStream(resultBytes, 0, resultBytes.Length, false, true));
         }
         else
         {
             using (Stream stream = request.Result.OpenStream())
             {
                 MemoryStream copyStream = new MemoryStream();
                 StreamUtility.CopyStream(stream, copyStream);
                 _image = System.Drawing.Image.FromStream(copyStream);
             }
         }
     }
     catch
     {
         _image = ImageUtility.GetErrorImage();
     }
     FCallBack(this, new EventArgs());
 }
Ejemplo n.º 3
0
 private void CancelImageRequest()
 {
     if (_imageRequest != null)
     {
         HostNode.Pipe.CancelRequest(_imageRequest);
         _imageRequest = null;
     }
 }
Ejemplo n.º 4
0
 /// <summary> Queues up an asynchronous request for a document. </summary>
 public void QueueRequest(PipeRequest pipeRequest)
 {
     lock (_asyncLock)
     {
         _queue.Add(pipeRequest);
         _queueSignal.Set();
     }
 }
Ejemplo n.º 5
0
 private void UpdateImage()
 {
     CancelImageRequest();
     if (_imageExpression == String.Empty)
     {
         ClearImage();
     }
     else
     {
         // Queue up an asynchronous request
         _imageRequest = new PipeRequest(_imageExpression, new PipeResponseHandler(ImageRead), new PipeErrorHandler(ImageError));
         _requester.HostNode.Pipe.QueueRequest(_imageRequest);
     }
 }
Ejemplo n.º 6
0
 /// <summary> Removes a request from the queue or cancels the request if it is being processed. </summary>
 /// <remarks> The caller is not guaranteed that after calling this that a response will not be sent. </remarks>
 public void CancelRequest(PipeRequest pipeRequest)
 {
     lock (_asyncLock)
     {
         if (pipeRequest == _currentRequest)
         {
             CancelCurrent();
         }
         else
         {
             _queue.Remove(pipeRequest);
             if (_queue.Count == 0)
             {
                 _queueSignal.Reset();
             }
         }
     }
 }
Ejemplo n.º 7
0
        // TODO: change this to use the AsyncImageRequest class

        /// <summary> Make sure that the image is loaded or creates an async request for it. </summary>
        private void InternalUpdateImage()
        {
            if (HostNode.Session.AreImagesLoaded())
            {
                CancelImageRequest();
                if (Image == String.Empty)
                {
                    SetImage(null);
                }
                else
                {
                    // Queue up an asynchronous request
                    _imageRequest = new PipeRequest(Image, new PipeResponseHandler(ImageRead), new PipeErrorHandler(ImageError));
                    HostNode.Pipe.QueueRequest(_imageRequest);
                }
            }
            else
            {
                SetImage(null);
            }
        }
Ejemplo n.º 8
0
 protected void ImageRead(PipeRequest request, Pipe pipe)
 {
     _imageRequest = null;
     try
     {
         if (request.Result.IsNative)
         {
             _image = ImageUtility.BitmapImageFromBytes(request.Result.AsByteArray);
         }
         else
         {
             using (Stream stream = request.Result.OpenStream())
                 _image = ImageUtility.BitmapImageFromStream(stream);
         }
     }
     catch
     {
         _image = ImageUtility.GetErrorImage();
     }
     FCallBack(this, new EventArgs());
 }
Ejemplo n.º 9
0
 private void ImageRead(PipeRequest request, Pipe pipe)
 {
     if (Active)
     {
         _imageRequest = null;
         try
         {
             if (request.Result.IsNative)
             {
                 SetImage(ImageUtility.BitmapImageFromBytes(request.Result.AsByteArray));
             }
             else
             {
                 using (Stream stream = request.Result.OpenStream())
                     SetImage(ImageUtility.BitmapImageFromStream(stream));
             }
         }
         catch
         {
             SetImage(ImageUtility.GetErrorImage());
         }
     }
 }
Ejemplo n.º 10
0
 private void ImageError(PipeRequest request, Pipe pipe, Exception exception)
 {
     _imageRequest = null;
     SetImage(ImageUtility.GetErrorImage());
 }
Ejemplo n.º 11
0
        /// <summary> Main asynchronous thread loop. </summary>
        private void ProcessAsync()
        {
            for (;;)
            {
                try
                {
                    // Wait until an item is enqueued or shut-down occurs
                    _queueSignal.WaitOne();

                    // Check for shut-down
                    if (_stoppingAsync)
                    {
                        break;
                    }

                    lock (_asyncLock)
                    {
                        // Dequeue an item
                        if (_queue.Count > 0)
                        {
                            _currentRequest = _queue[0];
                            _queue.RemoveAt(0);
                            if (_queue.Count == 0)
                            {
                                _queueSignal.Reset();
                            }
                        }
                    }
                    try
                    {
                        try
                        {
                            // Make the request
                            _currentRequest._result = InternalRequest(_currentRequest.Document, _asyncProcess);
                        }
                        catch (Exception exception)
                        {
                            // Error callback
                            // Can't take a lock to ensure that FCancellingCurrent doesn't change before we invoke (might dead-lock on the SafelyInvoke back to the main thread... which might be waiting on the FAsyncLock)
                            if ((_currentRequest.ErrorHandler != null) && !_cancellingCurrent)
                            {
                                SafelyInvoke(_currentRequest.ErrorHandler, new object[] { _currentRequest, this, exception });
                            }
                            // Don't rethrow
                            continue;                             // Skip the success callback
                        }

                        // Success callback
                        // Can't take a lock to ensure that FCancellingCurrent doesn't change before we invoke (might dead-lock on the SafelyInvoke back to the main thread... which might be waiting on the FAsyncLock)
                        if ((_currentRequest.ResponseHandler != null) && !_cancellingCurrent)
                        {
                            SafelyInvoke(_currentRequest.ResponseHandler, new object[] { _currentRequest, this });
                        }
                    }
                    catch (ThreadAbortException)
                    {
                        // An abort above will cause this thread to terminate.  This is because a catch will not
                        //  prevent abort exception propagation.  Must prevent this by resetting the abort state.
                                                #if !SILVERLIGHT
                        System.Threading.Thread.ResetAbort();
                                                #endif
                        // Don't rethrow - unnecessary
                    }
                    finally
                    {
                        lock (_asyncLock)
                        {
                            try
                            {
                                try
                                {
                                    // Free up the result resources
                                    if (_currentRequest._result != null)
                                    {
                                        _currentRequest._result.Dispose();
                                    }
                                }
                                finally
                                {
                                    // Clear the current request
                                    _currentRequest = null;
                                }
                            }
                            finally
                            {
/*
 *                                                              if (FCancellingCurrent)
 *                                                              {
 *                                                                      // Reset the cancel flag
 *                                                                      FCancellingCurrent = false;
 *
 *                                                                      // Start a new process, the old one was stopped
 *                                                                      CreateAsyncProcess();
 *                                                              }
 */
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    Error.Warn(exception.ToString());
                    // Don't rethrow.  We do not want an error here to stop the worker thread (and terminate the application).
                }
            }
            _queueSignal.Close();
        }
Ejemplo n.º 12
0
 protected void ImageError(PipeRequest request, Pipe pipe, Exception exception)
 {
     _imageRequest = null;
     _image        = ImageUtility.GetErrorImage();
     FCallBack(this, new EventArgs());
 }