Example #1
0
 public static MediaResource Create(string url)
 {
     if (!string.IsNullOrWhiteSpace(url))
     {
         try
         {
             return(new MediaResource(url));
         }
         catch (Exception e)
         {
             SecucardTrace.Error("MediaResource.Create", "Url= {0},{1} ", url, e.Message);
             // ignore here, value could be just an id as well
         }
     }
     return(null);
 }
Example #2
0
        private void AwaitReceipt(string rcptId, int?timeoutSec)
        {
            if (timeoutSec == null)
            {
                timeoutSec = _config.MessageTimeoutSec;
            }

            var found       = false;
            var maxWaitTime = DateTime.Now.AddSeconds(timeoutSec.Value);

            while (DateTime.Now <= maxWaitTime && _isConnected && _error == null)
            {
                DateTime rcptDateTime;
                if (_receipts.TryRemove(rcptId, out rcptDateTime))
                {
                    found = true;
                    break;
                }
                Thread.Sleep(200);
            }

            // we can treat error as reason to disconnect
            if (_error != null || !found)
            {
                if (_isConnected)
                {
                    try
                    {
                        Disconnect();
                    }
                    catch (Exception ex)
                    {
                        SecucardTrace.Error("StompClient.AwaitReceipt", ex.Message);
                    }
                }
                if (_error != null)
                {
                    var body    = _error.Body;
                    var headers = _error.Headers;
                    _error = null;
                    throw new StompError(body, headers);
                }
                throw new NoReceiptException("No receipt frame received for sent message.");
            }
            // consider receipt as successful disconnect
        }