Пример #1
0
        private string AppendSuffix(string parentId, string suffix, char delimiter)
        {
#if DEBUG
            suffix = OperationName.Replace('.', '-') + "-" + suffix;
#endif
            if (parentId.Length + suffix.Length < RequestIdMaxLength)
            {
                return(parentId + suffix + delimiter);
            }

            //Id overflow:
            //find position in RequestId to trim
            int trimPosition = RequestIdMaxLength - 9; // overflow suffix + delimiter length is 9
            while (trimPosition > 1)
            {
                if (parentId[trimPosition - 1] == '.' || parentId[trimPosition - 1] == '_')
                {
                    break;
                }
                trimPosition--;
            }

            //ParentId is not valid Request-Id, let's generate proper one.
            if (trimPosition == 0)
            {
                return(GenerateRootId());
            }

            //generate overflow suffix
            string overflowSuffix = ((int)GetRandomNumber()).ToString("x8");
            return(parentId.Substring(0, trimPosition) + overflowSuffix + '#');
        }
Пример #2
0
        private string GenerateRootId()
        {
            if (s_uniqPrefix == null)
            {
                // Here we make an ID to represent the Process/AppDomain.   Ideally we use process ID but
                // it is unclear if we have that ID handy.   Currently we use low bits of high freq tick
                // as a unique random number (which is not bad, but loses randomness for startup scenarios).
                Interlocked.CompareExchange(ref s_uniqPrefix, GenerateInstancePrefix(), null);
            }
#if DEBUG
            string ret = s_uniqPrefix + "-" + OperationName.Replace('.', '-') + "-" + Interlocked.Increment(ref s_currentRootId).ToString("x") + '.';
#else       // To keep things short, we drop the operation name
            string ret = s_uniqPrefix + "-" + Interlocked.Increment(ref s_currentRootId).ToString("x") + '.';
#endif
            return(ret);
        }