Davaaron
Davaaron
CC#
Created by Davaaron on 6/26/2024 in #help
Why do i need to pass in the generics here?
If i cannot get this done I already have some ideas in mind 😄 transition to a big static class "GitCommands" that has all those methods... or maybe i will create a lot of domain objects (Repository, Branch, Commit, Tag, etc.) that has the logic built-in (CreateBranch, AddLocalChanges, ResetCommit, etc.)
7 replies
CC#
Created by Davaaron on 6/26/2024 in #help
Why do i need to pass in the generics here?
Sorry for the late response. Yes, it is. Well I thought it could infer it because I write Author author = ..., of course it cannot when I write var author = .... My final design idea was to have a lot of git command classes that takes a specific input parameter and produces an output, so i could use it like Author author = await gitCommandHandler.ExecuteAsync(new GitGetAuthorCommandInput()) or await gitCommandHandler.ExecuteAsync(new GitSetAuthorCommandInput{ Name = "ChangedName" });
7 replies
CC#
Created by Davaaron on 6/26/2024 in #help
Why do i need to pass in the generics here?
The error message is
Error (active) CS0411 The type arguments for method 'IGitCommandHandler.ExecuteAsync<TOutput, TInput>(TInput)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Error (active) CS0411 The type arguments for method 'IGitCommandHandler.ExecuteAsync<TOutput, TInput>(TInput)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
7 replies
CC#
Created by Sagar viradiya on 5/30/2024 in #help
How to write Testcases with ServiceProvider.GetKeyedService method in .Net 8?
How about mocking the IServiceProvider?
7 replies
CC#
Created by stevon8ter on 5/30/2024 in #help
EF Entity 'required' property
How do you setup the "required" on your models? With the "keyword identifier" like public required string Name { get; set; } or like a data annotation [Required]? I'd try the latter one, because the required keyword tells the compiler that the properties need to be set in order to initialize the value, a readonly non-nullable value that needs be set before the object leaves the constructor. However, having ".IsRequired" in the configuration isn't a bad thing though, this way you have all the configurations in one place. I hate to jump around between configurations and models in suchs projects. More convenient to have everything configured the same way. Good luck!
9 replies
CC#
Created by AlgorithMage Ω(n) Θ(n×p) on 5/30/2024 in #help
Switching to C# and curious if there's anything I could improve on in this very basic math script.
What's your level of programming? You could take this to the next level ... I would consider the SOLID principles as well as other principles. That means I would try separate the responsibilities the best way I could.. try to put together what's common and only specify what's different, finding a good "mechanism" to be opened for alterations ... for example
using System;

class Program
{
static void Main()
{
MathOperation.Execute(new Addition(2, 5));
MathOperation.Execute(new Subtraction(2, 5));
MathOperation.Execute(new Multiplication(2, 5));
MathOperation.Execute(new Division(2, 5));
}
}

abstract class Operation
{
public abstract string OperatorSymbol { get; }
public abstract int Perform(int x, int y);
}

class Addition : Operation
{
public override string OperatorSymbol => "+";

public override int Perform(int x, int y)
{
return x + y;
}
}

class Subtraction : Operation
{
public override string OperatorSymbol => "-";

public override int Perform(int x, int y)
{
return x - y;
}
}

class Multiplication : Operation
{
public override string OperatorSymbol => "*";

public override int Perform(int x, int y)
{
return x * y;
}
}

class Division : Operation
{
public override string OperatorSymbol => "/";

public override int Perform(int x, int y)
{
if (y == 0)
{
throw new ArgumentException("Division by zero is not allowed.");
}

return x / y;
}
}

class MathOperation
{
public static void Execute(Operation operation)
{
int result = operation.Perform(operation.X, operation.Y);
Console.WriteLine($"Result of {operation.X} {operation.OperatorSymbol} {operation.Y} is {result}");
}
}
using System;

class Program
{
static void Main()
{
MathOperation.Execute(new Addition(2, 5));
MathOperation.Execute(new Subtraction(2, 5));
MathOperation.Execute(new Multiplication(2, 5));
MathOperation.Execute(new Division(2, 5));
}
}

abstract class Operation
{
public abstract string OperatorSymbol { get; }
public abstract int Perform(int x, int y);
}

class Addition : Operation
{
public override string OperatorSymbol => "+";

public override int Perform(int x, int y)
{
return x + y;
}
}

class Subtraction : Operation
{
public override string OperatorSymbol => "-";

public override int Perform(int x, int y)
{
return x - y;
}
}

class Multiplication : Operation
{
public override string OperatorSymbol => "*";

public override int Perform(int x, int y)
{
return x * y;
}
}

class Division : Operation
{
public override string OperatorSymbol => "/";

public override int Perform(int x, int y)
{
if (y == 0)
{
throw new ArgumentException("Division by zero is not allowed.");
}

return x / y;
}
}

class MathOperation
{
public static void Execute(Operation operation)
{
int result = operation.Perform(operation.X, operation.Y);
Console.WriteLine($"Result of {operation.X} {operation.OperatorSymbol} {operation.Y} is {result}");
}
}
20 replies
CC#
Created by AlgorithMage Ω(n) Θ(n×p) on 5/30/2024 in #help
Switching to C# and curious if there's anything I could improve on in this very basic math script.
Depends what you want to do... However, I would assign the results of the methods to variables. You could also create an Enum for the "CalculationMethods".
20 replies
CC#
Created by Davaaron on 5/31/2023 in #help
❔ WPF - Use command of viewmodel instead of item on click
Thank you very much, that worked!! 🙂
11 replies
CC#
Created by Davaaron on 5/31/2023 in #help
❔ WPF - Use command of viewmodel instead of item on click
Oh okay.. so I have to add some kind of event to the items (buttons) and then listen in the NotificationDialogViewModel.. alright
11 replies
CC#
Created by Davaaron on 5/31/2023 in #help
❔ WPF - Use command of viewmodel instead of item on click
The error is: System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Davaaron.BankOverview.ViewModels.Dialogs.NotificationDialogViewModel', AncestorLevel='1''. BindingExpression:Path=CloseDialogCommand; DataItem=null; target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')
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?
Got it
3 replies
CC#
Created by Davaaron on 3/30/2023 in #help
❔ E2E Test - Start MVC project
I followed the IntegrationTest docs, as there was no E2E docs. I already tried the WebApplicationFactory but with the same results. The issue might be in my understanding of how it works, as it does not startup the whole MVC project, but I thought it would. We use Playwright in C# with XUnit. Unfortunately, there is no real documentation about that. Our idea was that the test could do start/shutdown the whole MVC project, so we dont have to start and shutdown the MVC project separately before and after all tests.
23 replies
CC#
Created by Davaaron on 3/30/2023 in #help
❔ E2E Test - Start MVC project
23 replies
CC#
Created by Davaaron on 2/17/2023 in #help
❔ Get an entity with Sql data client
IF NOT EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'User')
BEGIN
CREATE TABLE [dbo].[User]
(
Id UNIQUEIDENTIFIER NOT NULL PRIMARY KEY DEFAULT NEWID(),
LastName VARCHAR(50) NOT NULL,
ForeName VARCHAR(50) NOT NULL,
Birthday datetime NOT NULL
);
PRINT 1;
END
ELSE PRINT 0
IF NOT EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'User')
BEGIN
CREATE TABLE [dbo].[User]
(
Id UNIQUEIDENTIFIER NOT NULL PRIMARY KEY DEFAULT NEWID(),
LastName VARCHAR(50) NOT NULL,
ForeName VARCHAR(50) NOT NULL,
Birthday datetime NOT NULL
);
PRINT 1;
END
ELSE PRINT 0
3 replies
CC#
Created by Davaaron on 2/17/2023 in #help
❔ Exclude sql from build
Solved it by changing "Compile" to "None"...
4 replies
CC#
Created by Davaaron on 2/17/2023 in #help
❔ Exclude sql from build
I tried this without success (the commented lines is what was there before)
<ItemGroup>
<!--<Resource Include="Sql\Database\Create_Database.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Sql\Database\Create_Table.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Sql\Database\Delete_Database.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Sql\Database\Delete_Table.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Sql\Database\Exist_Database.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Sql\Database\Exist_Table.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>-->
<Compile Remove="Sql\Database\**" />
<Content Include="Sql\Database\**" />
</ItemGroup>
<ItemGroup>
<!--<Resource Include="Sql\Database\Create_Database.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Sql\Database\Create_Table.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Sql\Database\Delete_Database.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Sql\Database\Delete_Table.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Sql\Database\Exist_Database.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Sql\Database\Exist_Table.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>-->
<Compile Remove="Sql\Database\**" />
<Content Include="Sql\Database\**" />
</ItemGroup>
4 replies
CC#
Created by Davaaron on 2/17/2023 in #help
❔ Load *.sql files (How to handle them?)
so we have placed some sql files there
12 replies
CC#
Created by Davaaron on 2/17/2023 in #help
❔ Load *.sql files (How to handle them?)
I know but we decided to go for the other way, it has some advantages
12 replies
CC#
Created by Davaaron on 11/25/2022 in #help
Map complex object (dictionary) from appsettings.json to model
Couldnt get this to work. Changed it completely now 😄
"msal-interceptor": {
"interactionType": "popup",
"protectedResourceMap": [
{
"resource": "https://graph.microsoft.com/v1.0/me",
"permissions": [ "user.read" ]
}
]
}
"msal-interceptor": {
"interactionType": "popup",
"protectedResourceMap": [
{
"resource": "https://graph.microsoft.com/v1.0/me",
"permissions": [ "user.read" ]
}
]
}
public class MSALInterceptorConfig
{
public string? InteractionType { get; set; }

public List<MSALProtectedResourceMap> ProtectedResourceMap { get; set; }
}

public class MSALProtectedResourceMap
{
public string? Resource { get; set; }
public List<string> Permissions { get; set; }
}
public class MSALInterceptorConfig
{
public string? InteractionType { get; set; }

public List<MSALProtectedResourceMap> ProtectedResourceMap { get; set; }
}

public class MSALProtectedResourceMap
{
public string? Resource { get; set; }
public List<string> Permissions { get; set; }
}
9 replies
CC#
Created by Davaaron on 11/25/2022 in #help
Map complex object (dictionary) from appsettings.json to model
Okay, got. That's way too complicated, I guess will leave Microsofts structure there 😄 Shouldn't this work?
"msal-interceptor": {
"interactionType": "popup",
"protectedResourceMap": {
"https://graph.microsoft.com/v1.0/me": [ "user.read" ]
}
}
"msal-interceptor": {
"interactionType": "popup",
"protectedResourceMap": {
"https://graph.microsoft.com/v1.0/me": [ "user.read" ]
}
}
public class MSALInterceptorConfig
{
public string? InteractionType { get; set; }
public Dictionary<string, List<string>>? ProtectedResourceMap { get; set; }
}
public class MSALInterceptorConfig
{
public string? InteractionType { get; set; }
public Dictionary<string, List<string>>? ProtectedResourceMap { get; set; }
}
The key is now "http" and value is empty
9 replies