Skip to content

Commit 43a8b21

Browse files
committed
Version 1.0.4.2
1 parent ed4654d commit 43a8b21

File tree

370 files changed

+9978
-9175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

370 files changed

+9978
-9175
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ You could see PowerCommands as your CLI application starter kit. It is a structu
33

44
[Follow progress on twitter](https://twitter.com/PowerCommands) <img src="https://github.com/PowerCommands/PowerCommands2022/blob/main/Docs/images/Twitter.png?raw=true" alt="drawing" width="20"/>
55

6+
7+
## Version 1.0.4.2
8+
**Released 2025-01-27**
9+
- New feature InfoPanel
610
## Version 1.0.4.1
711
**Released 2025-01-21**
812
- PowerCommandPrivacyAttribute to prevent sensitive data leak out to the logfile.

Templates/PowerCommands.zip

6.38 KB
Binary file not shown.

Templates/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ I recommend you to use the option ```Place solution in the same directory``` som
1818
![Alt text](../Docs/images/VS_solution_option.png?raw=true "Command Base")
1919

2020
# What is new?
21+
## Version 1.0.4.2
22+
**Released 2025-01-27**
23+
- New feature InfoPanel
2124
## Version 1.0.4.1
2225
**Released 2025-01-21**
2326
- PowerCommandPrivacyAttribute to prevent sensitive data leak out to the logfile.
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using $safeprojectname$.DomainObjects;
22

3-
namespace $safeprojectname$.Contracts;
4-
5-
public interface IConfigurationService
3+
namespace $safeprojectname$.Contracts
64
{
7-
YamlContainer<T> Get<T>(string inputFileName = "") where T : new();
8-
string SaveChanges<T>(T configuration, string inputFileName = "") where T : new();
9-
void Create<T>(T configuration, string fullFileName) where T : new();
10-
YamlContainer<T> GetAppDataConfiguration<T>(string inputFileName = "") where T : new();
11-
YamlContainer<T> GetByNodeName<T>(string filePath, string nodeName) where T : new();
5+
public interface IConfigurationService
6+
{
7+
YamlContainer<T> Get<T>(string inputFileName = "") where T : new();
8+
string SaveChanges<T>(T configuration, string inputFileName = "") where T : new();
9+
void Create<T>(T configuration, string fullFileName) where T : new();
10+
YamlContainer<T> GetAppDataConfiguration<T>(string inputFileName = "") where T : new();
11+
YamlContainer<T> GetByNodeName<T>(string filePath, string nodeName) where T : new();
12+
}
1213
}

Templates/src/Core/PainKiller.PowerCommands.Configuration/ConfigurationService.cs

Lines changed: 101 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -5,127 +5,128 @@
55
using YamlDotNet.Serialization;
66
using YamlDotNet.Serialization.NamingConventions;
77

8-
namespace $safeprojectname$;
9-
10-
public class ConfigurationService : IConfigurationService
8+
namespace $safeprojectname$
119
{
12-
private ConfigurationService(){}
13-
14-
private static readonly Lazy<IConfigurationService> Lazy = new(() => new ConfigurationService());
15-
public static IConfigurationService Service => Lazy.Value;
16-
public YamlContainer<T> Get<T>(string inputFileName = "") where T : new()
10+
public class ConfigurationService : IConfigurationService
1711
{
18-
var fileName = string.IsNullOrEmpty(inputFileName) ? $"{typeof(T).Name}.yaml".GetSafePathRegardlessHowApplicationStarted() : inputFileName.GetSafePathRegardlessHowApplicationStarted();
19-
var yamlContent = File.ReadAllText(fileName);
12+
private ConfigurationService() { }
2013

21-
var deserializer = new DeserializerBuilder()
22-
.WithNamingConvention(CamelCaseNamingConvention.Instance)
23-
.Build();
24-
try
14+
private static readonly Lazy<IConfigurationService> Lazy = new(() => new ConfigurationService());
15+
public static IConfigurationService Service => Lazy.Value;
16+
public YamlContainer<T> Get<T>(string inputFileName = "") where T : new()
2517
{
26-
return deserializer.Deserialize<YamlContainer<T>>(yamlContent);
18+
var fileName = string.IsNullOrEmpty(inputFileName) ? $"{typeof(T).Name}.yaml".GetSafePathRegardlessHowApplicationStarted() : inputFileName.GetSafePathRegardlessHowApplicationStarted();
19+
var yamlContent = File.ReadAllText(fileName);
20+
21+
var deserializer = new DeserializerBuilder()
22+
.WithNamingConvention(CamelCaseNamingConvention.Instance)
23+
.Build();
24+
try
25+
{
26+
return deserializer.Deserialize<YamlContainer<T>>(yamlContent);
27+
}
28+
catch (Exception)
29+
{
30+
Console.WriteLine($"Could not deserialize the configuration file, default configuration will be loaded instead\nA template configuration file named default_{typeof(T).Name}.yaml will be created in application root.");
31+
var defaultConfig = new T();
32+
SaveChanges(defaultConfig, $"default_{typeof(T).Name}.yaml");
33+
return new YamlContainer<T>();
34+
}
2735
}
28-
catch (Exception)
36+
public YamlContainer<T> GetByNodeName<T>(string filePath, string nodeName) where T : new()
2937
{
30-
Console.WriteLine($"Could not deserialize the configuration file, default configuration will be loaded instead\nA template configuration file named default_{typeof(T).Name}.yaml will be created in application root.");
31-
var defaultConfig = new T();
32-
SaveChanges(defaultConfig, $"default_{typeof(T).Name}.yaml");
33-
return new YamlContainer<T>();
34-
}
35-
}
36-
public YamlContainer<T> GetByNodeName<T>(string filePath, string nodeName) where T : new()
37-
{
38-
var stringBuilder = new StringBuilder();
39-
stringBuilder.AppendLine("version: 1.0\r\nconfiguration:");
40-
var nodeFound = false;
41-
var nodeIndentation = 0;
38+
var stringBuilder = new StringBuilder();
39+
stringBuilder.AppendLine("version: 1.0\r\nconfiguration:");
40+
var nodeFound = false;
41+
var nodeIndentation = 0;
4242

43-
using (var reader = new StreamReader(filePath))
44-
{
45-
while (reader.ReadLine() is { } line)
43+
using (var reader = new StreamReader(filePath))
4644
{
47-
if (line.Trim().StartsWith(nodeName + ":"))
45+
while (reader.ReadLine() is { } line)
4846
{
49-
nodeFound = true;
50-
nodeIndentation = line.TakeWhile(Char.IsWhiteSpace).Count();
47+
if (line.Trim().StartsWith(nodeName + ":"))
48+
{
49+
nodeFound = true;
50+
nodeIndentation = line.TakeWhile(Char.IsWhiteSpace).Count();
51+
stringBuilder.AppendLine(line);
52+
continue;
53+
}
54+
if (!nodeFound) continue;
55+
var currentIndentation = line.TakeWhile(Char.IsWhiteSpace).Count();
56+
if (string.IsNullOrWhiteSpace(line) || currentIndentation <= nodeIndentation) break;
5157
stringBuilder.AppendLine(line);
52-
continue;
5358
}
54-
if (!nodeFound) continue;
55-
var currentIndentation = line.TakeWhile(Char.IsWhiteSpace).Count();
56-
if (string.IsNullOrWhiteSpace(line) || currentIndentation <= nodeIndentation) break;
57-
stringBuilder.AppendLine(line);
5859
}
59-
}
6060

61-
var yamlContent = stringBuilder.ToString();
62-
var deserializer = new DeserializerBuilder()
63-
.WithNamingConvention(CamelCaseNamingConvention.Instance)
64-
.Build();
65-
try
66-
{
67-
return deserializer.Deserialize<YamlContainer<T>>(yamlContent);
61+
var yamlContent = stringBuilder.ToString();
62+
var deserializer = new DeserializerBuilder()
63+
.WithNamingConvention(CamelCaseNamingConvention.Instance)
64+
.Build();
65+
try
66+
{
67+
return deserializer.Deserialize<YamlContainer<T>>(yamlContent);
68+
}
69+
catch (Exception)
70+
{
71+
Console.WriteLine($"Could not deserialize the configuration file, default configuration will be loaded instead\nA template configuration file named default_{typeof(T).Name}.yaml will be created in application root.");
72+
return new YamlContainer<T>();
73+
}
74+
6875
}
69-
catch (Exception)
76+
public string SaveChanges<T>(T configuration, string inputFileName = "") where T : new()
7077
{
71-
Console.WriteLine($"Could not deserialize the configuration file, default configuration will be loaded instead\nA template configuration file named default_{typeof(T).Name}.yaml will be created in application root.");
72-
return new YamlContainer<T>();
73-
}
74-
75-
}
76-
public string SaveChanges<T>(T configuration, string inputFileName = "") where T : new()
77-
{
78-
if (configuration is null) return "";
79-
var fileName = string.IsNullOrEmpty(inputFileName) ? $"{configuration.GetType().Name}.yaml".GetSafePathRegardlessHowApplicationStarted() : inputFileName.GetSafePathRegardlessHowApplicationStarted();
80-
81-
var yamlContainer = new YamlContainer<T> { Configuration = configuration, Version = "1.0" };
82-
var serializer = new SerializerBuilder()
83-
.WithNamingConvention(CamelCaseNamingConvention.Instance)
84-
.Build();
85-
var yamlData = serializer.Serialize(yamlContainer);
86-
File.WriteAllText(fileName, yamlData);
87-
return fileName;
88-
}
89-
public void Create<T>(T configuration, string fullFileName) where T : new()
90-
{
91-
if (configuration is null) return;
92-
var yamlContainer = new YamlContainer<T> { Configuration = configuration, Version = "1.0" };
93-
var serializer = new SerializerBuilder()
94-
.WithNamingConvention(CamelCaseNamingConvention.Instance)
95-
.Build();
96-
var yamlData = serializer.Serialize(yamlContainer);
97-
File.WriteAllText(fullFileName, yamlData);
98-
}
78+
if (configuration is null) return "";
79+
var fileName = string.IsNullOrEmpty(inputFileName) ? $"{configuration.GetType().Name}.yaml".GetSafePathRegardlessHowApplicationStarted() : inputFileName.GetSafePathRegardlessHowApplicationStarted();
9980

100-
/// <summary>
101-
/// Return a configuration file stored in the AppData/Roaming/PowerCommands directory, if the file does not exist it will be created.
102-
/// </summary>
103-
/// <typeparam name="T"></typeparam>
104-
/// <param name="defaultIfMissing"></param>
105-
/// <param name="inputFileName"></param>
106-
/// <returns></returns>
107-
public YamlContainer<T> GetAppDataConfiguration<T>(string inputFileName = "") where T : new()
108-
{
109-
var directory = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{nameof(PowerCommands)}";
110-
var fileName = Path.Combine(directory, inputFileName);
111-
if (!File.Exists(fileName)) return new YamlContainer<T>();
112-
var yamlContent = File.ReadAllText(fileName);
113-
var deserializer = new DeserializerBuilder()
114-
.WithNamingConvention(CamelCaseNamingConvention.Instance)
115-
.Build();
116-
return deserializer.Deserialize<YamlContainer<T>>(yamlContent);
117-
}
118-
private string CreateContent<T>(T item) where T : new()
119-
{
120-
if (item is not null)
81+
var yamlContainer = new YamlContainer<T> { Configuration = configuration, Version = "1.0" };
82+
var serializer = new SerializerBuilder()
83+
.WithNamingConvention(CamelCaseNamingConvention.Instance)
84+
.Build();
85+
var yamlData = serializer.Serialize(yamlContainer);
86+
File.WriteAllText(fileName, yamlData);
87+
return fileName;
88+
}
89+
public void Create<T>(T configuration, string fullFileName) where T : new()
12190
{
122-
var yamlContainer = new YamlContainer<T> { Configuration = item, Version = "1.0" };
91+
if (configuration is null) return;
92+
var yamlContainer = new YamlContainer<T> { Configuration = configuration, Version = "1.0" };
12393
var serializer = new SerializerBuilder()
12494
.WithNamingConvention(CamelCaseNamingConvention.Instance)
12595
.Build();
12696
var yamlData = serializer.Serialize(yamlContainer);
127-
return yamlData;
97+
File.WriteAllText(fullFileName, yamlData);
98+
}
99+
100+
/// <summary>
101+
/// Return a configuration file stored in the AppData/Roaming/PowerCommands directory, if the file does not exist it will be created.
102+
/// </summary>
103+
/// <typeparam name="T"></typeparam>
104+
/// <param name="defaultIfMissing"></param>
105+
/// <param name="inputFileName"></param>
106+
/// <returns></returns>
107+
public YamlContainer<T> GetAppDataConfiguration<T>(string inputFileName = "") where T : new()
108+
{
109+
var directory = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{nameof(PowerCommands)}";
110+
var fileName = Path.Combine(directory, inputFileName);
111+
if (!File.Exists(fileName)) return new YamlContainer<T>();
112+
var yamlContent = File.ReadAllText(fileName);
113+
var deserializer = new DeserializerBuilder()
114+
.WithNamingConvention(CamelCaseNamingConvention.Instance)
115+
.Build();
116+
return deserializer.Deserialize<YamlContainer<T>>(yamlContent);
117+
}
118+
private string CreateContent<T>(T item) where T : new()
119+
{
120+
if (item is not null)
121+
{
122+
var yamlContainer = new YamlContainer<T> { Configuration = item, Version = "1.0" };
123+
var serializer = new SerializerBuilder()
124+
.WithNamingConvention(CamelCaseNamingConvention.Instance)
125+
.Build();
126+
var yamlData = serializer.Serialize(yamlContainer);
127+
return yamlData;
128+
}
129+
return "--- item is null and can not be serialized ---";
128130
}
129-
return "--- item is null and can not be serialized ---";
130131
}
131132
}
Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
namespace $safeprojectname$.DomainObjects;
2-
3-
public class ArtifactPathsConfiguration
1+
namespace $safeprojectname$.DomainObjects
42
{
5-
public string Name { get; set; } = "Name";
6-
public string Download { get; set; } = "PainKiller.PowerCommands.MyExampleCommands";
7-
public string Templates { get; set; } = "{appdata}|templates";
8-
public string[] ValidProjectFiles { get; set; } = {
9-
"PainKiller.PowerCommands.Bootstrap\\PainKiller.PowerCommands.Bootstrap.csproj",
10-
"PainKiller.PowerCommands.PowerCommandsConsole\\PainKiller.PowerCommands.PowerCommandsConsole.csproj",
11-
"Core",
12-
"Third party components",
13-
"Third party components\\PainKiller.SerilogExtensions\\PainKiller.SerilogExtensions.csproj",
14-
"Core\\$safeprojectname$\\$safeprojectname$.csproj",
15-
"Core\\PainKiller.PowerCommands.Core\\PainKiller.PowerCommands.Core.csproj",
16-
"Core\\PainKiller.PowerCommands.ReadLine\\PainKiller.PowerCommands.ReadLine.csproj",
17-
"Core\\PainKiller.PowerCommands.Security\\PainKiller.PowerCommands.Security.csproj",
18-
"Core\\PainKiller.PowerCommands.Shared\\PainKiller.PowerCommands.Shared.csproj",
19-
"PainKiller.PowerCommands.MyExampleCommands\\PainKiller.PowerCommands.MyExampleCommands.csproj"
20-
};
3+
public class ArtifactPathsConfiguration
4+
{
5+
public string Name { get; set; } = "Name";
6+
public string Download { get; set; } = "PainKiller.PowerCommands.MyExampleCommands";
7+
public string Templates { get; set; } = "{appdata}|templates";
8+
public string[] ValidProjectFiles { get; set; } = {
9+
"PainKiller.PowerCommands.Bootstrap\\PainKiller.PowerCommands.Bootstrap.csproj",
10+
"PainKiller.PowerCommands.PowerCommandsConsole\\PainKiller.PowerCommands.PowerCommandsConsole.csproj",
11+
"Core",
12+
"Third party components",
13+
"Third party components\\PainKiller.SerilogExtensions\\PainKiller.SerilogExtensions.csproj",
14+
"Core\\$safeprojectname$\\$safeprojectname$.csproj",
15+
"Core\\PainKiller.PowerCommands.Core\\PainKiller.PowerCommands.Core.csproj",
16+
"Core\\PainKiller.PowerCommands.ReadLine\\PainKiller.PowerCommands.ReadLine.csproj",
17+
"Core\\PainKiller.PowerCommands.Security\\PainKiller.PowerCommands.Security.csproj",
18+
"Core\\PainKiller.PowerCommands.Shared\\PainKiller.PowerCommands.Shared.csproj",
19+
"PainKiller.PowerCommands.MyExampleCommands\\PainKiller.PowerCommands.MyExampleCommands.csproj"
20+
};
2121

22-
public string[] Commands { get; set; } = { "Demo", "Config", "Dir", "Doc"};
23-
public string[] TemplateCommands { get; set; } = { "Default" };
24-
public string VsCode { get; set; } = "PowerCommands2022\\.vscode\\";
25-
public string CustomComponents { get; set; } = "PowerCommands2022\\src\\PainKiller.PowerCommands\\Custom Components\\";
26-
public string DocsDbFile { get; set; } = "PowerCommands2022\\src\\PainKiller.PowerCommands\\Core\\PainKiller.PowerCommands.Core\\DocsDB.data";
27-
public string DocsDbGithub { get; set; } = "https://raw.githubusercontent.com/PowerCommands/PowerCommands2022/main/src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/DocsDB.data";
28-
public string GithubRoot { get; set; } = "https://raw.githubusercontent.com/PowerCommands/PowerCommands2022/main/src/PainKiller.PowerCommands";
29-
public ArtifactSourcePaths Source { get; set; } = new();
30-
public ArtifactTargetPaths Target { get; set; } = new();
22+
public string[] Commands { get; set; } = { "Demo", "Config", "Dir", "Doc" };
23+
public string[] TemplateCommands { get; set; } = { "Default" };
24+
public string VsCode { get; set; } = "PowerCommands2022\\.vscode\\";
25+
public string CustomComponents { get; set; } = "PowerCommands2022\\src\\PainKiller.PowerCommands\\Custom Components\\";
26+
public string DocsDbFile { get; set; } = "PowerCommands2022\\src\\PainKiller.PowerCommands\\Core\\PainKiller.PowerCommands.Core\\DocsDB.data";
27+
public string DocsDbGithub { get; set; } = "https://raw.githubusercontent.com/PowerCommands/PowerCommands2022/main/src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/DocsDB.data";
28+
public string GithubRoot { get; set; } = "https://raw.githubusercontent.com/PowerCommands/PowerCommands2022/main/src/PainKiller.PowerCommands";
29+
public ArtifactSourcePaths Source { get; set; } = new();
30+
public ArtifactTargetPaths Target { get; set; } = new();
31+
}
3132
}

0 commit comments

Comments
 (0)