コード例 #1
0
        private async void AliveSendTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                if (!Connected || !State.SystemsAlive)
                {
                    return;
                }

                var ao = new AliveObject {
                    Ticks = TLCFIClient.CurrentTicks, Time = TimestampGenerator.GetTimestamp()
                };
                var reply = await TLCProxy.AliveAsync(ao, _sessionCancellationToken);

                if (reply != null && reply.Ticks == ao.Ticks && reply.Time == ao.Time)
                {
                    return;
                }

                _aliveSendFailCounter++;
                if (_aliveSendFailCounter > 2)
                {
                    StopAliveTimers();
                    SendAliveTimeoutOccured?.Invoke(this, EventArgs.Empty);
                }
            }
            catch
            {
                // ignored
            }
        }
コード例 #2
0
        public void ProgramStarts_GetTimestampCalled_ReturnsTimeSince1970()
        {
            var t       = TimestampGenerator.GetTimestamp();
            var timenow = DateTime.Now;

            // Check year and days
            Assert.AreEqual(timenow.Year - 1970, (int)(t / 31557600000));
            // TODO need to round days upwards
            Assert.AreEqual(
                timenow.DayOfYear - 1 + Math.Round((timenow.Year - 1970) * 365.25) +
                ((((timenow.Year - 1970) * 365.25) % 1.0) > 0 ? 1 : 0), (int)(t / 86400000));
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 public Orders(MqSession mqSession)
 {
     _mqSession = mqSession;
     _timestamp = new TimestampGenerator();
 }
コード例 #5
0
        /// <summary>
        /// Валидация на timestamp. Още не е импленетирано както трябва.
        /// </summary>
        /// <param name="tsr"></param>
        /// <returns></returns>
        public string Validate(byte[] tsr)
        {
            var generator = new TimestampGenerator(DefaultAuthority);

            return(generator.Validate(tsr));
        }
コード例 #6
0
 public async Task WriteMessages(IEnumerable <WriteMessage> messages, Consistency?consistency = null, string retentionPolicy = null)
 {
     await RequestProcessor.WriteMessages(Database, messages, consistency ?? DefaultConsistency, retentionPolicy, TimestampGenerator.GetTimestamp(), TimestampGenerator.Precision).ConfigureAwait(false);
 }