Exemple #1
0
 /// <summary>
 /// Construct from marshaled data
 /// </summary>
 /// <param name="byteArray">The marshaled data.</param>
 /// <param name="offset">The starting offset.</param>
 public TokenPairRecord(byte[] byteArray, int offset)
 {
     if (byteArray.Length - offset < TokenPairRecSize)
     {
         throw new ArgumentException(string.Format("Array length must be >= {0}", TokenPairRecSize));
     }
     T1 = new Token(byteArray, offset);
     T2 = new Token(byteArray, Token.TokenSize + offset);
     offset += (2 * Token.TokenSize);
     Ts = 0;
     // little Endian
     for (int index = 0; index < sizeof(long); ++index)
     {
         Ts |= ((long)byteArray[offset + index] << (index * 8));
     }
 }
Exemple #2
0
 /// <summary>
 /// Convenience Constructor
 /// </summary>
 public TokenPairRecord(Token t1, Token t2, long timestamp)
 {
     T1 = t1;
     T2 = t2;
     Ts = timestamp;
 }
Exemple #3
0
        /// <summary>
        /// Changes the event state of the token.
        /// </summary>
        /// <param name="eventId">The new event id.</param>
        /// <param name="currentRecord">The original token value.</param>
        /// <param name="factory">An ITokenPairRecord factory(T1, T2, Ts).</param>
        /// <returns>A new ITokenPairRecord.</returns>
        public ITokenPairRecord AddEvent(byte eventId, ulong currentRecord,
            Func<Token, Token, long, ITokenPairRecord> factory = null)
        {
            if (!_isEnabled || (currentRecord == SkippedTokenValue))
                return SkippedTokenReference;

            long timestamp = Stopwatch.GetTimestamp();
            var currentToken = new Token(currentRecord);
            var nextToken = new Token(currentToken.Value) { EventId = eventId };
            var nextRecord = (factory ?? _defaultFactory)(currentToken, nextToken, timestamp);
            _processingQueue.Enqueue(nextRecord);
            return nextRecord;
        }
Exemple #4
0
        /// <summary>
        /// Constructs and queues a new token with the original token as a token pair rec.
        /// This represents a 'split' in the event chain.
        /// This signature is for the C++ wrapper types.
        /// </summary>
        /// <param name="eventId">The event id porition of the new token.</param>
        /// <param name="currentRecord">The original token value.</param>
        /// <param name="factory">An ITokenPairRecord factory(T1, T2, Ts).</param>
        /// <returns>A new ITokenPairRecord.</returns>
        public ITokenPairRecord SplitToken(byte eventId, ulong currentRecord,
            Func<Token, Token, long, ITokenPairRecord> factory = null)
        {
            if (!_isEnabled
                || (currentRecord == SkippedTokenValue)
                ||  ShouldNotSample())
                return SkippedTokenReference;

            var currentToken = new Token(currentRecord);
            long timestamp = Stopwatch.GetTimestamp();
            long id = Interlocked.Increment(ref _previousId);
            var nextToken = new Token(_applicationId, eventId, (ulong)id);
            var nextRecord = (factory ?? _defaultFactory)(currentToken, nextToken, timestamp);
            _processingQueue.Enqueue(nextRecord);
            return nextRecord;
        }
Exemple #5
0
        static void OutputToken( Token token )
        {
            var ae = new ASCIIEncoding();

            byte[] outBytes = ae.GetBytes(token.AppId.ToString());
            _outStream.Write(outBytes, 0, outBytes.Length);
            _outStream.WriteByte((byte)',');
            outBytes = ae.GetBytes(token.EventId.ToString("g"));
            _outStream.Write(outBytes, 0, outBytes.Length);
            _outStream.WriteByte((byte)',');
            outBytes = ae.GetBytes(token.Id.ToString());
            _outStream.Write(outBytes, 0, outBytes.Length);
        }