Repository navigation
Feature: Add {{host}} variable to profile #3511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e15ec86
Feature: Migrate variable syntax to {{varname}}
BornToBeRoot 15a29ee
Feature: Add placeholder for host
BornToBeRoot 1d51b64
Feature: Add variable to profiles
BornToBeRoot 1e0a728
Docs: #3511
BornToBeRoot 99ff77d
refactor: use PlaceholderHelper in WebConsoleProfileUrlValidator
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
50 changes: 37 additions & 13 deletions
50
Source/NETworkManager.Localization/Resources/Strings.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,53 @@ | ||
| using System.Text.RegularExpressions; | ||
|
|
||
| namespace NETworkManager.Utilities; | ||
|
|
||
| /// <summary> | ||
| /// Helper class to resolve <c>{{name}}</c> placeholders in a string. | ||
| /// </summary> | ||
| public static class PlaceholderHelper | ||
| { | ||
| /// <summary> | ||
| /// Placeholder name for the host (e.g. of a profile). | ||
| /// </summary> | ||
| public const string Host = "host"; | ||
|
|
||
| /// <summary> | ||
| /// Placeholder name for a hostname. | ||
| /// </summary> | ||
| public const string Hostname = "hostname"; | ||
|
|
||
| /// <summary> | ||
| /// Placeholder name for an IP address. | ||
| /// </summary> | ||
| public const string IPAddress = "ipaddress"; | ||
|
|
||
| /// <summary> | ||
| /// Replaces a <c>{{name}}</c> placeholder (case-insensitive) with the given value. | ||
| /// </summary> | ||
| /// <param name="input">Input string that may contain the placeholder.</param> | ||
| /// <param name="name">Name of the placeholder, without the surrounding braces (e.g. <c>"hostname"</c>).</param> | ||
| /// <param name="value">Value to insert in place of the placeholder.</param> | ||
| /// <returns>The input with the placeholder resolved.</returns> | ||
| public static string Replace(string input, string name, string value) | ||
| { | ||
| return string.IsNullOrEmpty(input) | ||
| ? input | ||
| : Regex.Replace(input, $"\\{{\\{{{Regex.Escape(name)}\\}}\\}}", value ?? string.Empty, | ||
| RegexOptions.IgnoreCase); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Replaces multiple <c>{{name}}</c> placeholders (case-insensitive) with the given values. | ||
| /// </summary> | ||
| /// <param name="input">Input string that may contain the placeholders.</param> | ||
| /// <param name="placeholders">Placeholder name/value pairs to resolve, e.g. <c>(PlaceholderHelper.Host, "10.0.0.1")</c>.</param> | ||
| /// <returns>The input with all placeholders resolved.</returns> | ||
| public static string Resolve(string input, params (string name, string value)[] placeholders) | ||
| { | ||
| foreach (var (name, value) in placeholders) | ||
| input = Replace(input, name, value); | ||
|
|
||
| return input; | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
Source/NETworkManager.Validators/WebConsoleProfileUrlValidator.cs
This file contains hidden or 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,26 @@ | ||
| using System; | ||
| using System.Globalization; | ||
| using System.Text.RegularExpressions; | ||
| using System.Windows.Controls; | ||
| using NETworkManager.Localization.Resources; | ||
|
|
||
| namespace NETworkManager.Validators; | ||
|
|
||
| /// <summary> | ||
| /// Validates the WebConsole URL field on a profile, which may contain the <c>{{Host}}</c> placeholder. | ||
| /// </summary> | ||
| public class WebConsoleProfileUrlValidator : ValidationRule | ||
| { | ||
| public override ValidationResult Validate(object value, CultureInfo cultureInfo) | ||
| { | ||
| // Substitute the {{Host}} placeholder with a dummy host so the structural | ||
| // URL validation (scheme, format) still applies, without rejecting the placeholder itself. | ||
| var input = Regex.Replace(value as string ?? "", "\\{\\{host\\}\\}", "placeholder-host", | ||
| RegexOptions.IgnoreCase); | ||
|
|
||
| return Uri.TryCreate(input, UriKind.Absolute, out var uriResult) && | ||
| (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps) | ||
| ? ValidationResult.ValidResult | ||
| : new ValidationResult(false, Strings.EnterValidWebsiteUri); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest commit — replaced the inline
Regex.ReplacewithPlaceholderHelper.Replace(…, PlaceholderHelper.Host, "placeholder-host")and dropped the now-unusedSystem.Text.RegularExpressionsimport.