internal static String FormatValue(
            ISecretMasker secretMasker,
            Object value,
            ValueKind kind)
        {
            switch (kind)
            {
            case ValueKind.Null:
                return(ExpressionConstants.Null);

            case ValueKind.Boolean:
                return(((Boolean)value) ? ExpressionConstants.True : ExpressionConstants.False);

            case ValueKind.Number:
                var strNumber = ((Double)value).ToString(ExpressionConstants.NumberFormat, CultureInfo.InvariantCulture);
                return(secretMasker != null?secretMasker.MaskSecrets(strNumber) : strNumber);

            case ValueKind.String:
                // Mask secrets before string-escaping.
                var strValue = secretMasker != null?secretMasker.MaskSecrets(value as String) : value as String;

                return($"'{StringEscape(strValue)}'");

            case ValueKind.Array:
            case ValueKind.Object:
                return(kind.ToString());

            default:     // Should never reach here.
                throw new NotSupportedException($"Unable to convert to realized expression. Unexpected value kind: {kind}");
            }
        }
Beispiel #2
0
        // This is not thread safe, the caller need to take lock before calling issue()
        public void AddIssue(Issue issue)
        {
            ArgUtil.NotNull(issue, nameof(issue));
            issue.Message = _secretMasker.MaskSecrets(issue.Message);
            if (issue.Type == IssueType.Error)
            {
                if (_record.ErrorCount <= _maxIssueCount)
                {
                    _record.Issues.Add(issue);
                }

                _record.ErrorCount++;
            }
            else if (issue.Type == IssueType.Warning)
            {
                if (_record.WarningCount <= _maxIssueCount)
                {
                    _record.Issues.Add(issue);
                }

                _record.WarningCount++;
            }

            _jobServerQueue.QueueTimelineRecordUpdate(_mainTimelineId, _record);
        }
Beispiel #3
0
 private void Trace(TraceEventType eventType, string message)
 {
     ArgUtil.NotNull(_traceSource, nameof(_traceSource));
     _traceSource.TraceEvent(
         eventType: eventType,
         id: 0,
         message: _secretMasker.MaskSecrets(message));
 }
        internal ExpressionException(ISecretMasker secretMasker, String message)
        {
            if (secretMasker != null)
            {
                message = secretMasker.MaskSecrets(message);
            }

            m_message = message;
        }
Beispiel #5
0
 private void Trace(TraceEventType eventType, string message)
 {
     ArgUtil.NotNull(_traceSource, nameof(_traceSource));
     _traceSource.TraceEvent(eventType, 0, _secretMasker.MaskSecrets(message));
     if (_lastFlush.ElapsedTicks > _flushThreshold)
     {
         _traceSource.Flush();
         _lastFlush = Stopwatch.StartNew();
     }
 }
Beispiel #6
0
        // This is not thread safe, the caller need to take lock before calling issue()
        public void AddIssue(Issue issue)
        {
            ArgUtil.NotNull(issue, nameof(issue));
            issue.Message = _secretMasker.MaskSecrets(issue.Message);

            if (issue.Type == IssueType.Error)
            {
                // tracking line number for each issue in log file
                // log UI use this to navigate from issue to log
                if (!string.IsNullOrEmpty(issue.Message))
                {
                    long logLineNumber = Write(WellKnownTags.Error, issue.Message);
                    issue.Data["logFileLineNumber"] = logLineNumber.ToString();
                }

                if (_record.ErrorCount <= _maxIssueCount)
                {
                    _record.Issues.Add(issue);
                }

                _record.ErrorCount++;
            }
            else if (issue.Type == IssueType.Warning)
            {
                // tracking line number for each issue in log file
                // log UI use this to navigate from issue to log
                if (!string.IsNullOrEmpty(issue.Message))
                {
                    long logLineNumber = Write(WellKnownTags.Warning, issue.Message);
                    issue.Data["logFileLineNumber"] = logLineNumber.ToString();
                }

                if (_record.WarningCount <= _maxIssueCount)
                {
                    _record.Issues.Add(issue);
                }

                _record.WarningCount++;
            }

            _jobServerQueue.QueueTimelineRecordUpdate(_mainTimelineId, _record);
        }
        // Do not add a format string overload. In general, execution context messages are user facing and
        // therefore should be localized. Use the Loc methods from the StringUtil class. The exception to
        // the rule is command messages - which should be crafted using strongly typed wrapper methods.
        public void Write(string tag, string message)
        {
            string msg = _secretMasker.MaskSecrets($"{tag}{message}");

            lock (_loggerLock)
            {
                _logger.Write(msg);
            }

            // write to job level execution context's log file.
            var parentContext = _parentExecutionContext as ExecutionContext;

            if (parentContext != null)
            {
                lock (parentContext._loggerLock)
                {
                    parentContext._logger.Write(msg);
                }
            }

            _jobServerQueue.QueueWebConsoleLine(msg);
        }