forked from microsoft/PSRule
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b6be55
commit cdc08bb
Showing
86 changed files
with
2,352 additions
and
2,026 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Emitters | ||
namespace PSRule.Emitters; | ||
|
||
internal class InternalFileStream | ||
{ | ||
internal class InternalFileStream | ||
public InternalFileStream() | ||
{ | ||
public InternalFileStream() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Badges; | ||
|
||
/// <summary> | ||
/// An instance of a badge created by the Badge API. | ||
/// </summary> | ||
internal sealed class Badge : IBadge | ||
{ | ||
private readonly string _LeftText; | ||
private readonly string _RightText; | ||
private readonly double _LeftWidth; | ||
private readonly double _RightWidth; | ||
private readonly int _MidPadding; | ||
private readonly int _BorderPadding; | ||
private readonly string _Fill; | ||
|
||
internal Badge(string left, string right, string fill) | ||
{ | ||
_LeftWidth = BadgeResources.Measure(left); | ||
_RightWidth = BadgeResources.Measure(right); | ||
|
||
_LeftText = left; | ||
_RightText = right; | ||
_MidPadding = 3; | ||
_BorderPadding = 7; | ||
_Fill = fill; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
return ToSvg(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public string ToSvg() | ||
{ | ||
var w = (int)Math.Round(_LeftWidth + _RightWidth + 2 * _BorderPadding + 2 * _MidPadding); | ||
var x = (int)Math.Round(_LeftWidth + _BorderPadding + _MidPadding); | ||
|
||
var builder = new SvgBuilder( | ||
width: w, | ||
height: 20, | ||
textScale: 10, | ||
midPoint: x, | ||
rounding: 2, | ||
borderPadding: _BorderPadding, | ||
midPadding: _MidPadding); | ||
builder.Begin(string.Concat(_LeftText, ": ", _RightText)); | ||
builder.Backfill(_Fill); | ||
builder.TextBlock(_LeftText, _RightText, 110); | ||
builder.End(); | ||
return builder.ToString(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void ToFile(string path) | ||
{ | ||
path = Environment.GetRootedPath(path); | ||
var parentPath = Directory.GetParent(path); | ||
if (!parentPath.Exists) | ||
Directory.CreateDirectory(path: parentPath.FullName); | ||
|
||
File.WriteAllText(path, contents: ToSvg()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Badges; | ||
|
||
/// <summary> | ||
/// The type of badge. | ||
/// </summary> | ||
public enum BadgeType | ||
{ | ||
/// <summary> | ||
/// A badge that reports an unknown state. | ||
/// </summary> | ||
Unknown = 0, | ||
|
||
/// <summary> | ||
/// A badge reporting a successful state. | ||
/// </summary> | ||
Success = 1, | ||
|
||
/// <summary> | ||
/// A badge reporting a failed state. | ||
/// </summary> | ||
Failure = 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace PSRule.Badges; | ||
|
||
/// <summary> | ||
/// An instance of a badge created by the badge API. | ||
/// </summary> | ||
public interface IBadge | ||
{ | ||
/// <summary> | ||
/// Get the badge as SVG text content. | ||
/// </summary> | ||
string ToSvg(); | ||
|
||
/// <summary> | ||
/// Write the SVG badge content directly to disk. | ||
/// </summary> | ||
void ToFile(string path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using PSRule.Pipeline; | ||
|
||
namespace PSRule.Badges; | ||
|
||
/// <summary> | ||
/// A builder for the badge API. | ||
/// </summary> | ||
public interface IBadgeBuilder | ||
{ | ||
/// <summary> | ||
/// Create a badge for the worst case of an analyzed object. | ||
/// </summary> | ||
/// <param name="result">A single result. The worst case for all records of an object is used for the badge.</param> | ||
/// <returns>An instance of a badge.</returns> | ||
IBadge Create(InvokeResult result); | ||
|
||
/// <summary> | ||
/// Create a badge for the worst case of all analyzed objects. | ||
/// </summary> | ||
/// <param name="result">A enumeration of results. The worst case from all results is used for the badge.</param> | ||
/// <returns>An instance of a badge.</returns> | ||
IBadge Create(IEnumerable<InvokeResult> result); | ||
|
||
/// <summary> | ||
/// Create a custom badge. | ||
/// </summary> | ||
/// <param name="title">The left badge text.</param> | ||
/// <param name="type">Determines if the result is Unknown, Success, or Failure.</param> | ||
/// <param name="label">The right badge text.</param> | ||
/// <returns>An instance of a badge.</returns> | ||
IBadge Create(string title, BadgeType type, string label); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Diagnostics; | ||
|
||
namespace PSRule.Configuration; | ||
|
||
internal static class BindingOptionExtensions | ||
{ | ||
[DebuggerStepThrough] | ||
public static StringComparer GetComparer(this BindingOption option) | ||
{ | ||
return option.IgnoreCase.GetValueOrDefault(BindingOption.Default.IgnoreCase.Value) ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal; | ||
} | ||
} |
Oops, something went wrong.