Exemplo n.º 1
0
 /// <summary>
 /// Asynchronous Execution Complete
 /// </summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e1">The unique async name reference.</param>
 /// <param name="e2">The operation result.</param>
 /// <param name="e3">The current async exception.</param>
 private void AsyncHandler_AsyncExecuteComplete(object sender, object e1, bool e2, System.Exception e3)
 {
     try
     {
         if (e1 is string)
         {
             object result = _asyncExecuteAssets.GetExecuteAsyncResult <object>(e1.ToString());
             if (AsyncComplete != null)
             {
                 AsyncComplete(this, result, e1.ToString());
             }
         }
     }
     catch (System.Exception ex)
     {
         if (AsyncError != null)
         {
             AsyncError(this, new System.Exception(ex.Message, _asyncExecuteAssets.GetExecuteAsyncException(e1.ToString())));
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Asynchronous Execution Complete
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e1">The unique async name reference.</param>
        /// <param name="e2">The operation result.</param>
        /// <param name="e3">The current async exception.</param>
        private void AsyncHandler_AsyncExecuteComplete(object sender, object e1, bool e2, System.Exception e3)
        {
            try
            {
                if (e1 is string)
                {
                    // Send the result.
                    object result = _asyncExecute.GetExecuteAsyncResult <object>(e1.ToString());
                    if (AsyncComplete != null)
                    {
                        AsyncComplete(this, result, e1.ToString());
                    }

                    // Sent the error.
                    if (AsyncError != null)
                    {
                        if (e3 != null)
                        {
                            AsyncError(this, e3);
                        }
                    }

                    // Send the async result.
                    object callback = null;
                    if (_callback.TryGetValue(e1, out callback))
                    {
                        Action <Nequeo.Threading.AsyncOperationResult <object> > callbackObject = (Action <Nequeo.Threading.AsyncOperationResult <object> >)callback;
                        callbackObject(new Nequeo.Threading.AsyncOperationResult <object>(result, _state[e1], e1));
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (AsyncError != null)
                {
                    AsyncError(this, new System.Exception(ex.Message, _asyncExecute.GetExecuteAsyncException(e1.ToString())));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Async execution complete handler,
        /// </summary>
        /// <param name="sender">The object sender</param>
        /// <param name="e1">The unique async name reference</param>
        /// <param name="e2">The operation result</param>
        /// <param name="e3">The event argument</param>
        private void TransferHandler_AsyncExecuteComplete(object sender, object e1, bool e2, System.Exception e3)
        {
            try
            {
                // If the e1 is of type string
                if (e1 is string)
                {
                    // Get the e1
                    switch (e1.ToString().ToLower())
                    {
                    case "uploadfile":
                        // Upload the data asynchronously
                        bool uploadResult = _asyncExecute.GetExecuteAsyncResult <bool>(e1.ToString());

                        if (!uploadResult)
                        {
                            // A remote stream instance could not be established
                            throw new Exception("A remote upload stream instance could not be established.");
                        }
                        else
                        {
                            OnAsyncUploadComplete(uploadResult);
                        }
                        break;

                    case "downloadfile":
                        // Download the data asynchronously
                        bool downloadResult = _asyncExecute.GetExecuteAsyncResult <bool>(e1.ToString());

                        if (!downloadResult)
                        {
                            // A remote stream instance could not be established
                            throw new Exception("A remote download stream instance could not be established.");
                        }
                        else
                        {
                            OnAsyncDownloadComplete(downloadResult);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                // Clean-up
                if (_localSourceTemp != null)
                {
                    _localSourceTemp.Close();
                }

                // Clean-up
                if (_localSource != null)
                {
                    _localSource.Close();
                }

                // Clean-up
                if (_localSourceUpload != null)
                {
                    _localSourceUpload.Close();
                }

                // Clean-up
                if (_responseUpload != null)
                {
                    _responseUpload.Close();
                }

                // Clean-up
                if (_requestUpload != null)
                {
                    if (_requestUpload.GetRequestStream() != null)
                    {
                        _requestUpload.GetRequestStream().Close();
                    }
                }

                try
                {
                    // Clean-up delete the temp structured file.
                    if (!String.IsNullOrEmpty(_tempStructedFile))
                    {
                        File.Delete(_tempStructedFile);
                    }
                }
                catch { }

                // Clean-up
                if (_responseDownload != null)
                {
                    _responseDownload.Close();
                }

                // Clean-up
                if (_requestDownload != null)
                {
                    if (_requestDownload.GetRequestStream() != null)
                    {
                        _requestDownload.GetRequestStream().Close();
                    }
                }

                // Clean-up
                if (_localDestinationDownload != null)
                {
                    _localDestinationDownload.Close();
                }

                try
                {
                    // Clean-up delete the download local file.
                    File.Delete(_localDestinationPathDownload);
                }
                catch { }

                // Send the error message to the client
                // from the async call.
                if (AsyncError != null)
                {
                    AsyncError(this,
                               new Nequeo.Custom.AsyncArgs(
                                   new Nequeo.Exceptions.AsyncException(ex.Message, _asyncExecute.GetExecuteAsyncException(e1.ToString()))));
                }
            }
        }