public override void Render(LogEvent logEvent, TokenEmitter emitToken)
        {
            var moniker       = LevelOutputFormat.GetLevelMoniker(logEvent.Level, _levelToken.Format);
            var alignedOutput = Padding.Apply(moniker, _levelToken.Alignment);

            emitToken(alignedOutput);
        }
 public override void RefreshLayout()
 {
     if (Content != null)
     {
         Content.UnitBound = Padding.Apply(UnitBound.Padding(9));
         Content.RefreshLayout();
     }
 }
Ejemplo n.º 3
0
 public override void Render(LogEvent logEvent, TokenEmitter emitToken)
 {
     if (_alignment is not null)
     {
         emitToken(Padding.Apply(Environment.NewLine, _alignment.Value.Widen(Environment.NewLine.Length)));
     }
     else
     {
         emitToken(Environment.NewLine);
     }
 }
 public override void Render(LogEvent logEvent, TextWriter output)
 {
     if (_alignment.HasValue)
     {
         Padding.Apply(output, Environment.NewLine, _alignment.Value.Widen(Environment.NewLine.Length));
     }
     else
     {
         output.WriteLine();
     }
 }
Ejemplo n.º 5
0
        public override void Apply(Generator gen, LevelGenerator levelGen, Level level)
        {
            var rnd   = new Random(gen.Seed);
            var bound = Padding.Apply(new Rectangle(0, 0, level.Width, level.Height));
            var tree  = BspTree.BuildBspTree((int)Padding.Left, (int)Padding.Top,
                                             level.Width - (int)Padding.Left - (int)Padding.Right,
                                             level.Height - (int)Padding.Top - (int)Padding.Bottom,
                                             Depth, rnd);

            Build(tree.Root, rnd, level);
        }
Ejemplo n.º 6
0
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            var moniker = LevelOutputFormat.GetLevelMoniker(logEvent.Level, _levelToken.Format);

            if (!Levels.TryGetValue(logEvent.Level, out var levelStyle))
            {
                levelStyle = HtmlThemeStyle.Invalid;
            }

            using (_theme.Apply(output, levelStyle))
                Padding.Apply(output, moniker, _levelToken.Alignment);
        }
 public override void Evaluate(LogEvent logEvent, TextWriter output, IFormatProvider?formatProvider)
 {
     if (_alignment == null)
     {
         EvaluateUnaligned(logEvent, output, formatProvider);
     }
     else
     {
         var writer = new StringWriter();
         EvaluateUnaligned(logEvent, writer, formatProvider);
         Padding.Apply(output, writer.ToString(), _alignment.Value);
     }
 }
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            if (_token.Alignment == null || !_theme.CanBuffer)
            {
                _renderer.Render(logEvent.MessageTemplate, logEvent.Properties, output);
                return;
            }

            var buffer    = new StringWriter();
            var invisible = _renderer.Render(logEvent.MessageTemplate, logEvent.Properties, buffer);
            var value     = buffer.ToString();

            Padding.Apply(output, value, _token.Alignment.Value.Widen(invisible));
        }
Ejemplo n.º 9
0
        public static ProcessResultArray <Clip> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata)
        {
            var clips = new Clip[incomingClips.Length];

            for (var i = 0; i < incomingClips.Length; i++)
            {
                clips[i] = new Clip(incomingClips[i]);
            }

            return(command.Id switch
            {
                TokenType.Arpeggiate => Arpeggiate.Apply(command, clips),
                TokenType.Concat => Concat.Apply(clips),
                TokenType.Crop => Crop.Apply(command, clips),
                TokenType.Filter => Filter.Apply(command, clips),
                TokenType.Interleave => Interleave.Apply(command, targetMetadata, clips),
                TokenType.Legato => Legato.Apply(clips),
                TokenType.Mask => Mask.Apply(command, clips),
                TokenType.Monophonize => Monophonize.Apply(clips),
                TokenType.Padding => Padding.Apply(command, clips),
                TokenType.Quantize => Quantize.Apply(command, clips),
                TokenType.Ratchet => Ratchet.Apply(command, clips),
                TokenType.Relength => Relength.Apply(command, clips),
                TokenType.Remap => Remap.Apply(command, clips),
                TokenType.Resize => Resize.Apply(command, clips),
                TokenType.Scale => Scale.Apply(command, clips),
                TokenType.Scan => Scan.Apply(command, clips),
                TokenType.SetLength => SetLength.Apply(command, clips),
                TokenType.SetPitch => SetPitch.Apply(command, clips),
                TokenType.SetRhythm => SetRhythm.Apply(command, clips),
                TokenType.Shuffle => Shuffle.Apply(command, clips),
                TokenType.Skip => Skip.Apply(command, clips),
                TokenType.Slice => Slice.Apply(command, clips),
                TokenType.Take => Take.Apply(command, clips),
                TokenType.Transpose => Transpose.Apply(command, clips),
                TokenType.VelocityScale => VelocityScale.Apply(command, clips),
                TokenType.InterleaveEvent => ((Func <ProcessResultArray <Clip> >)(() =>
                {
                    var(success, msg) = OptionParser.TryParseOptions(command, out InterleaveOptions options);
                    if (!success)
                    {
                        return new ProcessResultArray <Clip>(msg);
                    }

                    options.Mode = InterleaveMode.Event;
                    return Interleave.Apply(options, targetMetadata, clips);
                }))(),
                _ => new ProcessResultArray <Clip>($"Unsupported command {command.Id}")
            });
Ejemplo n.º 10
0
    public static ProcessResult <Clip[]> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata)
    {
        var clips = new Clip[incomingClips.Length];

        for (var i = 0; i < incomingClips.Length; i++)
        {
            clips[i] = new Clip(incomingClips[i]);
        }

        return(command.Id switch
        {
            TokenType.Arpeggiate => Arpeggiate.Apply(command, clips),
            TokenType.Concat => Concat.Apply(clips),
            TokenType.Crop => Crop.Apply(command, clips),
            TokenType.Echo => Echo.Apply(command, clips),
            TokenType.Extract => Take.Apply(command, clips, true),
            TokenType.Filter => Filter.Apply(command, clips),
            TokenType.Invert => Invert.Apply(command, clips),
            TokenType.Interleave => Interleave.Apply(command, targetMetadata, clips, InterleaveMode.NotSpecified),
            TokenType.InterleaveEvent => Interleave.Apply(command, targetMetadata, clips, InterleaveMode.Event),
            TokenType.Legato => Legato.Apply(clips),
            TokenType.Loop => Loop.Apply(command, clips),
            TokenType.Mask => Mask.Apply(command, clips),
            TokenType.Monophonize => Monophonize.Apply(clips),
            TokenType.Padding => Padding.Apply(command, clips),
            TokenType.Quantize => Quantize.Apply(command, clips),
            TokenType.Ratchet => Ratchet.Apply(command, clips),
            TokenType.Relength => Relength.Apply(command, clips),
            TokenType.Remap => Remap.Apply(command, clips),
            TokenType.Resize => Resize.Apply(command, clips),
            TokenType.Scale => Scale.Apply(command, clips),
            TokenType.Scan => Scan.Apply(command, clips),
            TokenType.SetLength => SetLength.Apply(command, clips),
            TokenType.SetPitch => SetPitch.Apply(command, clips),
            TokenType.SetRhythm => SetRhythm.Apply(command, clips),
            TokenType.Shuffle => Shuffle.Apply(command, clips),
            TokenType.Skip => Skip.Apply(command, clips),
            TokenType.Slice => Slice.Apply(command, clips),
            TokenType.Take => Take.Apply(command, clips),
            TokenType.Transpose => Transpose.Apply(command, clips),
            TokenType.VelocityScale => VelocityScale.Apply(command, clips),
            _ => new ProcessResult <Clip[]>($"Unsupported command {command.Id}")
        });
        public override void Render(LogEvent logEvent, TokenEmitter emitToken)
        {
            // If a property is missing, don't render anything (message templates render the raw token here).
            if (!logEvent.Properties.TryGetValue(_token.PropertyName, out var propertyValue))
            {
                if (_token.Alignment is not null)
                {
                    emitToken(Padding.Apply(string.Empty, _token.Alignment));
                }
                return;
            }

            var writer = new StringWriter();

            // If the value is a scalar string, support some additional formats: 'u' for uppercase
            // and 'w' for lowercase.
            if (propertyValue is ScalarValue {
                Value : string literalString
            })
Ejemplo n.º 12
0
        public override void Render(LogEvent logEvent, TokenEmitter emitToken)
        {
            // We need access to ScalarValue.Render() to avoid this alloc; just ensures
            // that custom format providers are supported properly.
            var sv     = new ScalarValue(logEvent.Timestamp);
            var buffer = new StringWriter();

            sv.Render(buffer, _token.Format, _formatProvider);
            var str = buffer.ToString();

            if (_token.Alignment is not null)
            {
                emitToken(Padding.Apply(str, _token.Alignment));
            }
            else
            {
                emitToken(str);
            }
        }
Ejemplo n.º 13
0
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            // If a property is missing, don't render anything (message templates render the raw token here).
            if (!logEvent.Properties.TryGetValue(_token.PropertyName, out var propertyValue))
            {
                Padding.Apply(output, string.Empty, _token.Alignment);
                return;
            }

            var _ = 0;

            using (_theme.Apply(output, RichTextBoxThemeStyle.SecondaryText, ref _))
            {
                var writer = _token.Alignment.HasValue ? new StringWriter() : output;

                // If the value is a scalar string, support some additional formats: 'u' for uppercase
                // and 'w' for lowercase.
                if (propertyValue is ScalarValue {
                    Value : string literalString
                })
Ejemplo n.º 14
0
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            var included = logEvent.Properties
                           .Where(p => !TemplateContainsPropertyName(logEvent.MessageTemplate, p.Key) &&
                                  !TemplateContainsPropertyName(_outputTemplate, p.Key))
                           .Select(p => new LogEventProperty(p.Key, p.Value));

            var value = new StructureValue(included);

            if (_token.Alignment is null || !_theme.CanBuffer)
            {
                _valueFormatter.Format(value, output, null);
                return;
            }

            var buffer    = new StringWriter(new StringBuilder(value.Properties.Count * 16));
            var invisible = _valueFormatter.Format(value, buffer, null);
            var str       = buffer.ToString();

            Padding.Apply(output, str, _token.Alignment.Value.Widen(invisible));
        }
Ejemplo n.º 15
0
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            // We need access to ScalarValue.Render() to avoid this alloc; just ensures
            // that custom format providers are supported properly.
            var sv = new ScalarValue(logEvent.Timestamp);

            using (_theme.Apply(output, HtmlThemeStyle.SecondaryText))
            {
                if (_token.Alignment is null)
                {
                    sv.Render(output, _token.Format);
                }
                else
                {
                    var buffer = new StringWriter();
                    sv.Render(buffer, _token.Format);
                    var str = buffer.ToString();
                    Padding.Apply(output, str, _token.Alignment);
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Render the token to the output.
        /// </summary>
        /// <param name="properties">Properties that may be represented by the token.</param>
        /// <param name="output">Output for the rendered string.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        public override void Render(IReadOnlyDictionary <string, LogEventPropertyValue> properties, TextWriter output, IFormatProvider formatProvider = null)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            LogEventPropertyValue propertyValue;

            if (!properties.TryGetValue(PropertyName, out propertyValue))
            {
                output.Write(_rawText);
                return;
            }

            if (!Alignment.HasValue)
            {
                propertyValue.Render(output, Format, formatProvider);
                return;
            }

            var valueOutput = new StringWriter();

            propertyValue.Render(valueOutput, Format, formatProvider);
            var value = valueOutput.ToString();

            if (value.Length >= Alignment.Value.Width)
            {
                output.Write(value);
                return;
            }

            Padding.Apply(output, value, Alignment.Value);
        }
Ejemplo n.º 17
0
        int RenderAlignedPropertyTokenUnbuffered(PropertyToken pt, TextWriter output, LogEventPropertyValue propertyValue)
        {
            var valueOutput = new StringWriter();

            RenderValue(NoTheme, _unthemedValueFormatter, propertyValue, valueOutput, pt.Format);

            var valueLength = valueOutput.ToString().Length;

            // ReSharper disable once PossibleInvalidOperationException
            if (valueLength >= pt.Alignment.Value.Width)
            {
                return(RenderValue(_theme, _valueFormatter, propertyValue, output, pt.Format));
            }

            if (pt.Alignment.Value.Direction == AlignmentDirection.Left)
            {
                var invisible = RenderValue(_theme, _valueFormatter, propertyValue, output, pt.Format);
                Padding.Apply(output, string.Empty, pt.Alignment.Value.Widen(-valueLength));
                return(invisible);
            }

            Padding.Apply(output, string.Empty, pt.Alignment.Value.Widen(-valueLength));
            return(RenderValue(_theme, _valueFormatter, propertyValue, output, pt.Format));
        }
Ejemplo n.º 18
0
        public override void Render(LogEvent logEvent, TextWriter output)
        {
            // If a property is missing, don't render anything (message templates render the raw token here).
            LogEventPropertyValue propertyValue;

            if (!logEvent.Properties.TryGetValue(_token.PropertyName, out propertyValue))
            {
                Padding.Apply(output, "", _token.Alignment);
                return;
            }

            var _ = 0;

            using (_theme.Apply(output, ConsoleThemeStyle.SecondaryText, ref _))
            {
                var writer = _token.Alignment.HasValue ? new StringWriter() : output;

                // If the value is a scalar string, support some additional formats: 'u' for uppercase
                // and 'w' for lowercase.
                if (propertyValue is ScalarValue sv && sv.Value is string literalString)
                {
                    var cased = Casing.Format(literalString, _token.Format);
                    writer.Write(cased);
                }
        /// <summary>
        /// Format the log event into the output.
        /// </summary>
        /// <param name="logEvent">The event to format.</param>
        /// <param name="output">The output.</param>
        public void Format(LogEvent logEvent, TextWriter output)
        {
            if (logEvent == null) throw new ArgumentNullException(nameof(logEvent));
            if (output == null) throw new ArgumentNullException(nameof(output));

            foreach (var token in _outputTemplate.Tokens)
            {
                if (token is TextToken tt)
                {
                    MessageTemplateRenderer.RenderTextToken(tt, output);
                    continue;
                }

                var pt = (PropertyToken)token;
                if (pt.PropertyName == OutputProperties.LevelPropertyName)
                {
                    var moniker = LevelOutputFormat.GetLevelMoniker(logEvent.Level, pt.Format);
                    Padding.Apply(output, moniker, pt.Alignment);
                }
                else if (pt.PropertyName == OutputProperties.NewLinePropertyName)
                {
                    Padding.Apply(output, Environment.NewLine, pt.Alignment);
                }
                else if (pt.PropertyName == OutputProperties.ExceptionPropertyName)
                {
                    var exception = logEvent.Exception == null ? "" : logEvent.Exception + Environment.NewLine;
                    Padding.Apply(output, exception, pt.Alignment);
                }
                else
                {
                    // In this block, `writer` may be used to buffer output so that
                    // padding can be applied.
                    var writer = pt.Alignment.HasValue ? new StringWriter() : output;

                    if (pt.PropertyName == OutputProperties.MessagePropertyName)
                    {
                        MessageTemplateRenderer.Render(logEvent.MessageTemplate, logEvent.Properties, writer, pt.Format, _formatProvider);
                    }
                    else if (pt.PropertyName == OutputProperties.TimestampPropertyName)
                    {
                        ScalarValue.Render(logEvent.Timestamp, writer, pt.Format, _formatProvider);
                    }
                    else if (pt.PropertyName == OutputProperties.PropertiesPropertyName)
                    {
                        PropertiesOutputFormat.Render(logEvent.MessageTemplate, logEvent.Properties, _outputTemplate, writer, pt.Format, _formatProvider);
                    }
                    else
                    {
                        // If a property is missing, don't render anything (message templates render the raw token here).
                        LogEventPropertyValue propertyValue;
                        if (!logEvent.Properties.TryGetValue(pt.PropertyName, out propertyValue))
                            continue;

                        // If the value is a scalar string, support some additional formats: 'u' for uppercase
                        // and 'w' for lowercase.
                        var sv = propertyValue as ScalarValue;
                        if (sv?.Value is string literalString)
                        {
                            var cased = Casing.Format(literalString, pt.Format);
                            writer.Write(cased);
                        }
                        else
                        {
                            propertyValue.Render(writer, pt.Format, _formatProvider);
                        }
                    }

                    if (pt.Alignment.HasValue)
                        Padding.Apply(output, ((StringWriter)writer).ToString(), pt.Alignment);
                }
            }
        }