private TimestampResult DoGetTimeStamp(byte[] contentToStamp, string filePath, string authority) { var usedPrividers = new HashSet <Authority>(); Authority?authorityEnum = null; if (!string.IsNullOrWhiteSpace(authority)) { try { authorityEnum = (Authority)Enum.Parse(typeof(Authority), authority); } catch { } } usedPrividers.Add(authorityEnum ?? DefaultAuthority); var tsGenerator = new TimestampGenerator(authorityEnum ?? DefaultAuthority); if (RetryTimestampingOnError) { // retry механизъм var policy = Policy.Handle <Exception>() .Retry(2, onRetry: (exception, retryCount, context) => { if (false == usedPrividers.Contains(Authority.Evotrust)) { tsGenerator.ChangeAutorithyInfo(Authority.Evotrust); usedPrividers.Add(Authority.Evotrust); } else if (false == usedPrividers.Contains(Authority.Infonotary)) { tsGenerator.ChangeAutorithyInfo(Authority.Infonotary); usedPrividers.Add(Authority.Infonotary); } }); var timestampResult = policy.Execute(() => tsGenerator.Generate(contentToStamp, filePath)); return(timestampResult); } else { var timestampResult = tsGenerator.Generate(contentToStamp, filePath); return(timestampResult); } }
public void OnOrderPostReceived(IMessage message) { var timeout = TimeSpan.FromSeconds(HTTP_TIMEOUT_SECONDS); var textMessage = (ITextMessage)message; var replyQueue = textMessage.NMSReplyTo; var correlationId = textMessage.NMSCorrelationID; var order = JsonConvert.DeserializeObject <Order>(textMessage.Text); Console.WriteLine($"{_timestamp.Generate()} POST OrderId={order.OrderId}, Customer={order.Customer}"); using (var producer = _mqSession.Session.CreateProducer(replyQueue)) { var serialized = JsonConvert.SerializeObject(order); var replyMessage = _mqSession.Session.CreateTextMessage(textMessage.Text); replyMessage.NMSCorrelationID = correlationId; replyMessage.NMSTimeToLive = timeout; producer.Send(replyMessage); } }