Davaaron
Davaaron
CC#
Created by Davaaron on 6/26/2024 in #help
Why do i need to pass in the generics here?
Hey, I have this code
using GitManager.Domain.Models;
using GitManager.GitCLI.Commands.Parsing;

namespace GitManager.GitCLI.Commands
{
public record GitPullBranchCommandInput : IGitCommandInput
{
public string LocalPath { get; }
/// <summary>
/// When not specified, the current local checked out branch will be pulled.
/// </summary>
public string? Branch { get; }

public GitPullBranchCommandInput(string localPath, string? branch = null)
{
LocalPath = localPath;
Branch = branch;
}
}
public class GitPullBranchCommand : IGitCommand<string, GitPullBranchCommandInput>
{
private readonly IGitCommandStrategy _gitCommandStrategy;

public GitPullBranchCommand(IGitCommandStrategy gitCommandStrategy)
{
_gitCommandStrategy = gitCommandStrategy;
}

public async Task<string> ExecuteAsync(GitPullBranchCommandInput input)
{
//var command = "branch --list --all";
var command = "pull";
var result = await _gitCommandStrategy.ExecuteAsync(command, input.LocalPath);

return result;
}
}
}
using GitManager.Domain.Models;
using GitManager.GitCLI.Commands.Parsing;

namespace GitManager.GitCLI.Commands
{
public record GitPullBranchCommandInput : IGitCommandInput
{
public string LocalPath { get; }
/// <summary>
/// When not specified, the current local checked out branch will be pulled.
/// </summary>
public string? Branch { get; }

public GitPullBranchCommandInput(string localPath, string? branch = null)
{
LocalPath = localPath;
Branch = branch;
}
}
public class GitPullBranchCommand : IGitCommand<string, GitPullBranchCommandInput>
{
private readonly IGitCommandStrategy _gitCommandStrategy;

public GitPullBranchCommand(IGitCommandStrategy gitCommandStrategy)
{
_gitCommandStrategy = gitCommandStrategy;
}

public async Task<string> ExecuteAsync(GitPullBranchCommandInput input)
{
//var command = "branch --list --all";
var command = "pull";
var result = await _gitCommandStrategy.ExecuteAsync(command, input.LocalPath);

return result;
}
}
}
and i want to use to probably like this
Branch branch = await gitHandler.ExecuteAsync(new GitPullBranchCommandInput(""));
Branch branch = await gitHandler.ExecuteAsync(new GitPullBranchCommandInput(""));
But it says i cannot the determine the types... why not?! they are clearly given..
5 replies
CC#
Created by Davaaron on 5/30/2024 in #help
Blazor validation - validation message not added?
Hi, i have created a base form component and I use another Blazor form component. The issue is that customly added validation messages are not shown in the ValidationSummary and the visual styles (red and green highlighted inputs) are not shown for my nested form, why is that? Can I use "DataAnnotationValidator" and add custom validation messages at the same time?
1 replies
CC#
Created by Davaaron on 7/26/2023 in #help
Add app created with ng new to solution
Hi, is there a way to include an app created with ng new to the solution? My goal is start that app without any host using npm run within Visual Studio. Is there some kind of *.proj file or any other way to do it? Actually, the app should also be visibile in Visual Studio, that's also why I want to add it to the solution file.
1 replies
CC#
Created by Davaaron on 5/31/2023 in #help
❔ WPF - Use command of viewmodel instead of item on click
Hi, I have a list of strings and display them as buttons. The list is held by a viewmodel and the viewmodel has a Command for the button click. Now, instead of creating an object for strings and add the Command to the items, I would like to have the Command at the viewmodel level.
<Grid x:Name="LayoutRoot" Margin="5">
<ItemsControl ItemsSource="{Binding Options}" Grid.Row="1">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,0,0" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="{Binding CloseDialogCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type vm:NotificationDialogViewModel}}}" CommandParameter="true" Content="{Binding }" MinWidth="75" Height="25" Margin="10,5,10,5" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<Grid x:Name="LayoutRoot" Margin="5">
<ItemsControl ItemsSource="{Binding Options}" Grid.Row="1">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,0,0" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="{Binding CloseDialogCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type vm:NotificationDialogViewModel}}}" CommandParameter="true" Content="{Binding }" MinWidth="75" Height="25" Margin="10,5,10,5" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
public class NotificationDialogViewModel : BindableBase, IDialogAware
{
private DelegateCommand<string> _closeDialogCommand;
public DelegateCommand<string> CloseDialogCommand =>
_closeDialogCommand ?? (_closeDialogCommand = new DelegateCommand<string>(CloseDialog));

protected virtual void CloseDialog(string parameter)
{
ButtonResult result = ButtonResult.None;

if (parameter?.ToLower() == "true")
result = ButtonResult.OK;
else if (parameter?.ToLower() == "false")
result = ButtonResult.Cancel;

RaiseRequestClose(new DialogResult(result, new DialogParameters($"parameter={parameter}")));
}

}
public class NotificationDialogViewModel : BindableBase, IDialogAware
{
private DelegateCommand<string> _closeDialogCommand;
public DelegateCommand<string> CloseDialogCommand =>
_closeDialogCommand ?? (_closeDialogCommand = new DelegateCommand<string>(CloseDialog));

protected virtual void CloseDialog(string parameter)
{
ButtonResult result = ButtonResult.None;

if (parameter?.ToLower() == "true")
result = ButtonResult.OK;
else if (parameter?.ToLower() == "false")
result = ButtonResult.Cancel;

RaiseRequestClose(new DialogResult(result, new DialogParameters($"parameter={parameter}")));
}

}
11 replies
CC#
Created by Davaaron on 5/30/2023 in #help
❔ Prism: Change view in region - How to add multiple views to region and activate?
Hey, currently I'm developing a WPF application that has a navigation menu on the left (basically a treeview) and a content panel on the right. Whenever I click on a treeview item, the details about that item should be displayed on the right side within the content panel. There are different types of items and each type has a view and a viewmodel. How do I add multiple views to a region and activate one at a time? I added the views like this
var regionmanager = Container.Resolve<IRegionManager>();
regionmanager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(PersonDetails));
regionmanager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(Overview));
var regionmanager = Container.Resolve<IRegionManager>();
regionmanager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(PersonDetails));
regionmanager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(Overview));
and PersonDetails is showed. When I run
RegionManager.Regions[RegionNames.ContentRegion].Activate(typeof(Overview));
RegionManager.Regions[RegionNames.ContentRegion].Activate(typeof(Overview));
I get an error
This RegionManager does not contain a Region with the name
This RegionManager does not contain a Region with the name
When I exchange "RegisterViewWithRegion" by "AddToRegion" I get another exception. What's wrong here?
3 replies
CC#
Created by Davaaron on 5/5/2023 in #help
❔ WPF
Hi, I would like to bind some events to some relay commands that I have defined using MVVM. I have installed the nuget package for xaml behaviors but it's absolutely not triggering my command 😦
xmlns:behavior="http://schemas.microsoft.com/xaml/behaviors"
<Grid>
<TreeView ItemsSource="{Binding RootNodes}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Items}">
<TextBlock Text="{Binding Title}">
<behavior:Interaction.Triggers>
<behavior:EventTrigger EventName="MouseClick">
<behavior:InvokeCommandAction Command="{Binding Mode=OneWay, Path=Action}"/>
</behavior:EventTrigger>
</behavior:Interaction.Triggers>

</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
xmlns:behavior="http://schemas.microsoft.com/xaml/behaviors"
<Grid>
<TreeView ItemsSource="{Binding RootNodes}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Items}">
<TextBlock Text="{Binding Title}">
<behavior:Interaction.Triggers>
<behavior:EventTrigger EventName="MouseClick">
<behavior:InvokeCommandAction Command="{Binding Mode=OneWay, Path=Action}"/>
</behavior:EventTrigger>
</behavior:Interaction.Triggers>

</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
Why is my RelayCommand Action not triggered?
4 replies
CC#
Created by Davaaron on 3/30/2023 in #help
❔ E2E Test - Start MVC project
Hi, im using a testing tool for E2E testing and wondered how to get a MVC project started so the tool can visit the URL of the application and do some stuff? I call this in the constructor of the test class
OtherProjRefNs.Program.CreateWebHostBuilder(null)
.UseStartup<Startup>()
.Build()
.Start();
OtherProjRefNs.Program.CreateWebHostBuilder(null)
.UseStartup<Startup>()
.Build()
.Start();
but when I navigate to the URL within a browser after the Start() method, it says the page is not reachable. How can I start my MVC project?
23 replies
CC#
Created by Davaaron on 2/17/2023 in #help
❔ Get an entity with Sql data client
Hi, Im trying to read some data with the sql data client and Im stuck. The data looks like this: ID (uniqueidentifer, PK), Forename (nvarchar), Lastname (nvarchar), Birthday (datetime) The code looks like this
// Set the connection, command, and then execute the command with query and return the reader.
public static SqlOutput<DataTable> ExecuteReader(String connectionString, String commandText,
CommandType commandType = CommandType.Text, params SqlParameter[] parameters)
{
return Execute(cmd =>
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read()) // HERE THE ERROR IS HAPPENING
{
Console.WriteLine(String.Format("{0}", reader[0]));
}
}
return new DataTable();
}, commandType, parameters);

}


var result = SqlHelper.ExecuteReader(ConnectionString, input.script, System.Data.CommandType.Text, input.parameters.Select(x => // input.parameters = @[{'E48CC209-4D6A-4594-BD02-AE74DBCF82EA'}]
{
var p = new SqlParameter(x.Key, System.Data.SqlDbType.UniqueIdentifier);
p.Value = Guid.Parse(x.Value);
return p;
}).ToArray());
// Set the connection, command, and then execute the command with query and return the reader.
public static SqlOutput<DataTable> ExecuteReader(String connectionString, String commandText,
CommandType commandType = CommandType.Text, params SqlParameter[] parameters)
{
return Execute(cmd =>
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read()) // HERE THE ERROR IS HAPPENING
{
Console.WriteLine(String.Format("{0}", reader[0]));
}
}
return new DataTable();
}, commandType, parameters);

}


var result = SqlHelper.ExecuteReader(ConnectionString, input.script, System.Data.CommandType.Text, input.parameters.Select(x => // input.parameters = @[{'E48CC209-4D6A-4594-BD02-AE74DBCF82EA'}]
{
var p = new SqlParameter(x.Key, System.Data.SqlDbType.UniqueIdentifier);
p.Value = Guid.Parse(x.Value);
return p;
}).ToArray());
The error message is:
System.Data.SqlClient.SqlException: "Error converting a character in "uniqueidentifer"."
System.Data.SqlClient.SqlException: "Error converting a character in "uniqueidentifer"."
Somebody has an idea what's wrong? That the script for the table
3 replies
CC#
Created by Davaaron on 2/17/2023 in #help
❔ Exclude sql from build
Hi, how can I exclude some files from the compile process? Imagine I have script like
CREATE DATABASE @name
CREATE DATABASE @name
and VS complains about the syntax near '@name'. Whatever, I know it better and want VS stop to care about these files, just have them in a *.resx file for now. I already set the build step to "None" but VS doesnt care... is this a bug?
4 replies
CC#
Created by Davaaron on 2/17/2023 in #help
❔ Load *.sql files (How to handle them?)
Hi, Im creating a backend in NET Core and I do not want to use EF Core as I need to extend my SQL knowledge, so I thought it's good to use SqlDataClient and raw SQL. So far so good. My solution structure is like this: - Domain (contains Models and SQL scripts) - Infrastructure (contains Repositories, Services, SQLManager [classes to create database, tables, call sql scripts, etc) - Web API (controllers that use the services in the infrastructure) My idea was to store the SQL scripts along the models as resource files and have them in a *.resx file or maybe call the files programmatically, but I think the first option is good for resolving compile errors. I wonder if I can reference the *.resx files from another project (infrastructure)? How do you typically deal with *.sql files that you call in your programs?
12 replies
CC#
Created by Davaaron on 11/25/2022 in #help
Map complex object (dictionary) from appsettings.json to model
Hi, i have a complex appsettings.json like this
"interceptor": {
"interactionType": "redirect",
"protectedResourceMap": [
["https://graph.microsoft.com/v1.0/me", ["user.read"]]
]
}
"interceptor": {
"interactionType": "redirect",
"protectedResourceMap": [
["https://graph.microsoft.com/v1.0/me", ["user.read"]]
]
}
How can I map this? I have a class definition
public class MSAL
{
public MSALInterceptorConfig Interceptor { get; set; }
}

public class MSALInterceptorConfig
{
public string? InteractionType { get; set; }
public List<Dictionary<string, List<string>>>? ProtectedResourceMap { get; set; }
}
public class MSAL
{
public MSALInterceptorConfig Interceptor { get; set; }
}

public class MSALInterceptorConfig
{
public string? InteractionType { get; set; }
public List<Dictionary<string, List<string>>>? ProtectedResourceMap { get; set; }
}
and read the config like
var builder = WebApplication.CreateBuilder(args);
var config = builder.Configuration;
var clientConfig = config.Get<MSAL>();
var builder = WebApplication.CreateBuilder(args);
var config = builder.Configuration;
var clientConfig = config.Get<MSAL>();
When I check the clientConfig object, I see that the ProtectedResourceMap has one entry: key="1" and value="user.read". How can I fix it so I have a list of dictionary entries?
9 replies