TJacken
TJacken
CC#
Created by TJacken on 10/26/2024 in #help
Avalonia UI what I need to learn?
Hi I want to create desktop app using Avalonia I'm having experience with WinForms. I need to create application which fetch categories (simple list of Category objects class contains prop Name and IsSelected) using api and render list of categories, categories are dynamically shown (not hardcoded list). Add button which will run operation to process selected categories. Also I need to show loading indicator when I'm waiting to fetch data, when data are presented hide loader indicator. Is it good to set api call in modelview constructor? How should I handle this? If I have boolean value IsLoading how view should be triggered? Can you recommand some resouces with above questions? So I can create simple app using Avalonia πŸ™‚
17 replies
CC#
Created by TJacken on 10/25/2024 in #help
Is having two DbContext on same base antipattern or bad approach?
In company (so there is no much freedom to do with other tools I need to solve this using EF Core), we are using CQRS with MediatR, and every command handler is wrapped in a transaction. So if something fails, we roll back the transaction. Here’s the issue: I need to save certain data even if an exception occurs. The main data should be rolled back, but part of the data needs to be saved in the database. I know I can use two separate DB contexts to solve this issue, but is this a good approach? Is there a better way to partially commit data to the database?
3 replies
CC#
Created by TJacken on 7/20/2024 in #help
Custom HttpMessageHandler to save http request and response in DB
Hi, is it good idea to overide SendAsync method from DelegateHandler and save request and response in DB? https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpmessagehandler?view=net-8.0 I made custom HttpMessageHandler and inject repository in it, but when I call SaveChanges I got concurrency exception over db context when I run multiple http requests in parallel, everything is registered in DI correctly. So my question where is best place to save http request and http response in db?
42 replies
CC#
Created by TJacken on 4/24/2024 in #help
Seed data from migration
Just need opinion about seeding data from migration. Lets start, I have some data on DEV env and I want to migrate data to TEST env. I can generate SQL script from data on DEV env and put generated script in new migration under Up() method. How can I handle future delete/update data generate new migration again? Should I have delete script in Down() method? Or should I manually delete data if new migration has new data.
13 replies
CC#
Created by TJacken on 3/11/2024 in #help
CQRS command with complex structure
Is it okay to have command like this, is it bad approach for CQRS to have DTO inside Command?
public class CreateTemplateCommand : IRequest<int>
{
public string Name { get; set; } = default!;

public string ChatSystemPrompt { get; set; } = default!;

public string Definition { get; set; } = default!;

public double Temperature { get; set; }

public double TopP { get; set; }

public List<TagDto> TagDtos { get; set; } = default!;
}
public class CreateTemplateCommand : IRequest<int>
{
public string Name { get; set; } = default!;

public string ChatSystemPrompt { get; set; } = default!;

public string Definition { get; set; } = default!;

public double Temperature { get; set; }

public double TopP { get; set; }

public List<TagDto> TagDtos { get; set; } = default!;
}
2 replies
CC#
Created by TJacken on 3/8/2024 in #help
Template system for chat gpt ASP.NET Core
No description
11 replies
CC#
Created by TJacken on 2/28/2024 in #help
Load files from azure at startup and add new files in memory and azure storage
No description
1 replies
CC#
Created by TJacken on 2/20/2024 in #help
SemanticKernel WebAPI proper DI
Have you ever worked with SemanticKernel in combination with WebAPI? Didn't found on github or ms docs examples there is only console applications like example. Do you have any example or github code how to proper use SemnaticKernel in DI?
3 replies
CC#
Created by TJacken on 2/19/2024 in #help
MathPlugin in skprompt.txt file [Semantic kernel]
What is proper way to set params in skprompt.txt file to call MathPlugin.Add function:
Console.WriteLine("Enter numbers: ");

var input1 = Console.ReadLine();
var input2 = Console.ReadLine();

var result = await kernel.InvokeAsync(prompts["math"], new()
{
{ "input1", input1 },
{ "input2", input2 }
});
Console.WriteLine("Enter numbers: ");

var input1 = Console.ReadLine();
var input2 = Console.ReadLine();

var result = await kernel.InvokeAsync(prompts["math"], new()
{
{ "input1", input1 },
{ "input2", input2 }
});
skprompt.txt file:
Get me the sum of passed numbers:

{{ MathPlugin.Add value=$input1 amount=$input2 }}

Assistant:
Get me the sum of passed numbers:

{{ MathPlugin.Add value=$input1 amount=$input2 }}

Assistant:
I got this answer when I enter 1 and 5 for example:
You've only provided one number, which is 6. In order to calculate a sum, I'll need at least two numbers. Can you provide another number?
1 replies
CC#
Created by TJacken on 2/18/2024 in #help
WinForms DataGridView complex binding
No description
3 replies
CC#
Created by TJacken on 2/8/2024 in #help
Azure Open AI preserve history and load instruction files
Hi all, need advice I'm working AI chatbot and want to preserve chat history per user. What would be best way to implement this without using database. Is there better way than creating service which holds all chat history in list and registering this service as singleton? Also my plan is to have storage account on Azure where I would put my instruction files on blob container and when creating initial message download this files from Azure and load them as user messages for open ai service. Is there better way to load files instead of loading them in constructor of AzureOpenAIService?
4 replies
CC#
Created by TJacken on 10/10/2023 in #help
❔ How can I copy a Chart from Excel to Word with OpenXml SDK?
Lost whole day on this without any result. Is this possible to do with OpenXml SDK? Anyone had similar use case?
8 replies
CC#
Created by TJacken on 9/15/2023 in #help
❔ How to code cover lambda expression with NSubstitute and FluentValidation on line 26?
No description
13 replies
CC#
Created by TJacken on 9/12/2023 in #help
❔ Unit testing xUnit, NSubstitute and FluentAssertion.
Hello to everybody, do you know any good blog or some resource which describe unit testing principles with xUnit and NSubstitute. Additional questions, what is best approach to mock database? I have DbContext should I mock what fetching data from DbContext return or I need to populate context with fake data before running test (setup).
2 replies
CC#
Created by TJacken on 9/8/2023 in #help
βœ… Mask data when solft delete is applied
Hi, is there any nuget package or EF Core feature which I can configure to mask data in database when I apply solft delete? When user request delete his data in database, due to the GDPR regulative I need to leave user data in database because of statistics data, but mask user sensitive data like first name, last name, e-mail, gender... Do you know any nuget for this or have idea how I can do this? I know I can manually do this to update every property I need. I suppose if nuget exists it should had custom attribute to mark data for mask after soft delete.
16 replies
CC#
Created by TJacken on 8/30/2023 in #help
❔ βœ… How do you structure AzureFunctionApp project?
I have azure function app project with few functions, logic and models are contained in folder with non meaningful name. Do you organize your folder like clean arhitecture (application, domain, infrastructure) or you create folder per function and all logic related to function is contained in files from folder?
4 replies
CC#
Created by TJacken on 8/14/2023 in #help
❔ Validate list of objects after reading excel file
Hi all, how would you validate data from excel file with fluent validation? I have method which will read data from excel file and return me list of person objects. After read I call validator to validate data from excel file. Person email must be unique, so it shouldn't exist in database when I read data and it shouldn't be duplicated in excel file. Is it good approach to inject repository in validator or just collect all emails as list and pass it to validator? If I use that approach what if someone else insert person with email in parallel with my operation? Person class:
public class Person
{
public string FullName { get; set; }

public string Email { get; set; }

public string City { get; set; }
}
public class Person
{
public string FullName { get; set; }

public string Email { get; set; }

public string City { get; set; }
}
Person validator class:
public class PersonValidator : AbstractValidator<Person>
{
private readonly IPersonRepository _personRepository;
private readonly List<Person> _peopleFromExcelFile;

public PersonValidator(IPersonRepository personRepository, List<Person> peopleFromExcelFile)
{
_personRepository = personRepository;
_peopleFromExcelFile = peopleFromExcelFile;

RuleFor(x => x.FullName)
.NotEmpty()
.WithMessage("Full name is empty!");

RuleFor(x => x.Email)
.NotEmpty()
.WithMessage("Email is empty");

RuleFor(x => x.Email)
.Must(PersonMailDoNotExistInRepository)
.WithMessage("Email already exists in database");

RuleFor(x => x.Email)
.Must(EmailIsNotDuplicateInExcelFile)
.WithMessage("Email is duplicated in excel file");
}

private bool PersonMailDoNotExistInRepository(string email)
{
return _personRepository.GetByEmail(email) == null;
}

private bool EmailIsNotDuplicateInExcelFile(string email)
{
return _peopleFromExcelFile.Count(x => x.Email == email) == 1;
}
}
public class PersonValidator : AbstractValidator<Person>
{
private readonly IPersonRepository _personRepository;
private readonly List<Person> _peopleFromExcelFile;

public PersonValidator(IPersonRepository personRepository, List<Person> peopleFromExcelFile)
{
_personRepository = personRepository;
_peopleFromExcelFile = peopleFromExcelFile;

RuleFor(x => x.FullName)
.NotEmpty()
.WithMessage("Full name is empty!");

RuleFor(x => x.Email)
.NotEmpty()
.WithMessage("Email is empty");

RuleFor(x => x.Email)
.Must(PersonMailDoNotExistInRepository)
.WithMessage("Email already exists in database");

RuleFor(x => x.Email)
.Must(EmailIsNotDuplicateInExcelFile)
.WithMessage("Email is duplicated in excel file");
}

private bool PersonMailDoNotExistInRepository(string email)
{
return _personRepository.GetByEmail(email) == null;
}

private bool EmailIsNotDuplicateInExcelFile(string email)
{
return _peopleFromExcelFile.Count(x => x.Email == email) == 1;
}
}
8 replies
CC#
Created by TJacken on 8/4/2023 in #help
βœ… Blob trigger and save blob information in database
Hi all, first time to ask here. How would you approach to this problem, I have endpoint in aspnet core where I send file. When file get to controller I need to upload file on Azure blob storage and save file data in database (file name, description,...). When file get at blob container it will trigger blob azure function which need to read data from database. So flow is this: 1) - controller get file - file is sent to blob storage - save file information to database 2) - blob trigger is activated - read file information from database How to solve this from 1), file is uploaded to blob storage and database throw exception, so I have blob file which will trigger azure function but don't have record in database?
9 replies