kurumi
kurumi
CC#
Created by kurumi on 11/10/2024 in #help
smart AI search application (research)
Hey, mates 👋 I wanna create smart endpoint search which integrates smart AI assistant (llama 3). So, I have some questions related to AI: 1) which libraries should I use (I heard of preview of semantic kernel for .NET 9, is it good and how soon it will 1st release?) 2) how can I tell smart AI assistant about my web api endpoints, so it knows they are existing? Also I would like to tell my AI assistant about related information on endpoint. So if endpoint have any documentation in code (xml docs), AI can read and learn from it I am pretty noob on any AI stuff, so appreciate of any help on my research
2 replies
CC#
Created by kurumi on 4/18/2024 in #help
✅ API Gateway with Aspire .NET
No description
6 replies
CC#
Created by kurumi on 4/11/2024 in #help
✅ XmlReader generic Mapper
Hello 👋 . I am trying to create generic mapper for my project, that is using XmlReader. All my XML files have same structure, i.e.:
<ROOT>
<OBJECT ID="52022696" OBJECTID="1456218" NAME="Abaya" TYPENAME="street" ISACTUAL="1" ISACTIVE="0"/>
...
</ROOT>
<ROOT>
<OBJECT ID="52022696" OBJECTID="1456218" NAME="Abaya" TYPENAME="street" ISACTUAL="1" ISACTIVE="0"/>
...
</ROOT>
For model:
public class AddressObject
{
public int Id { get; set; }

public int ObjectId { get; set; }

public string FullName { get; set; }
}
public class AddressObject
{
public int Id { get; set; }

public int ObjectId { get; set; }

public string FullName { get; set; }
}
So, I want to use Mapper this way:
public XmlReaderCopyHelper<AddressObject> Addresses =>
new XmlReaderCopyHelper<AddressObject>("OBJECT")
.WithCondition("ISACTUAL", src => src == "1") // ! only if ISACTUAL is "1" map, otherwise skip
.WithCondition("ISACTIVE", src => src == "1") // ! second condition
.Map("ID", ao => ao.Id)
.Map("OBJECTID", ao => ao.ObjectId)
.Map(..., ao => ao.FullName); // ! it should map to $"{TYPENAME} {NAME}"
public XmlReaderCopyHelper<AddressObject> Addresses =>
new XmlReaderCopyHelper<AddressObject>("OBJECT")
.WithCondition("ISACTUAL", src => src == "1") // ! only if ISACTUAL is "1" map, otherwise skip
.WithCondition("ISACTIVE", src => src == "1") // ! second condition
.Map("ID", ao => ao.Id)
.Map("OBJECTID", ao => ao.ObjectId)
.Map(..., ao => ao.FullName); // ! it should map to $"{TYPENAME} {NAME}"
17 replies
CC#
Created by kurumi on 3/6/2024 in #help
Reading large xml file from archive by using XmlReader in Parallel mode
Hello 👋. I am looking for how can I read data from archive xml file in Parallel mode. I have archive someFiles.zip with my needed data and it has largeXmlFile.xml file inside. This file is 40gb. It looks kinda of it (but has thousands of objects :Ok:):
<root>
<OBJECT data1="123" data2="456" />
<OBJECT data1="321" data2="654" />
</root>
<root>
<OBJECT data1="123" data2="456" />
<OBJECT data1="321" data2="654" />
</root>
Now I am opening this file from archive and get Stream
using var zipFile = ZipFile.OpenRead(@"someFiles.zip");
var myFile = zipFile.Entries.FirstOrDefault(file => file.Name is "largeXmlFile.xml");
var myFileStream = myFile.Open();
using var zipFile = ZipFile.OpenRead(@"someFiles.zip");
var myFile = zipFile.Entries.FirstOrDefault(file => file.Name is "largeXmlFile.xml");
var myFileStream = myFile.Open();
then putting this Stream into XmlReader:
using var xmlReader = XmlReader.Create(myFileStream , new() { Async = true });
using var xmlReader = XmlReader.Create(myFileStream , new() { Async = true });
And I am simply reading it:
var objects = new List<MyObject>();
while (await xmlReader.ReadAsync())
{
if (xmlReader is { NodeType: XmlNodeType.Element, Name: "OBJECT" })
{
objects.Add(ReadMyObject(xmlReader));
}
}
var objects = new List<MyObject>();
while (await xmlReader.ReadAsync())
{
if (xmlReader is { NodeType: XmlNodeType.Element, Name: "OBJECT" })
{
objects.Add(ReadMyObject(xmlReader));
}
}
It takes ages for reading this file, so my question is: How can I change my code so I will read this XML in Parallel mode?
35 replies
CC#
Created by kurumi on 2/28/2024 in #help
HttpListener implements IDisposable but there is not Dispose() method, why and how can I dispose it?
No description
7 replies
CC#
Created by kurumi on 2/26/2024 in #help
✅ AutoMapper record to class problems
I need to create map from
public record MessageModel(
int MessageId,
int AuthorId,
string Text,
IEnumerable<int> Likes,
DateTime SendDate);
public record MessageModel(
int MessageId,
int AuthorId,
string Text,
IEnumerable<int> Likes,
DateTime SendDate);
to:
public class MessageEntity
{
public int Id { get; set; }
public int AuthorId { get; set; }
public UserEntity? Author { get; set; }
public string Text { get; set; } = string.Empty;
public DateTime SendDate { get; set; }
public List<MessageLikeEntity> Likes { get; set; } = new List<MessageLikeEntity>();
}
public class MessageEntity
{
public int Id { get; set; }
public int AuthorId { get; set; }
public UserEntity? Author { get; set; }
public string Text { get; set; } = string.Empty;
public DateTime SendDate { get; set; }
public List<MessageLikeEntity> Likes { get; set; } = new List<MessageLikeEntity>();
}
I quickly made it:
CreateMap<MessageModel, MessageEntity>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.MessageId));
CreateMap<MessageModel, MessageEntity>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.MessageId));
So I want keep Id, AuthorId, Text and SendDate be mapped But it throws exception: AutoMapper.AutoMapperMappingException Message=Error mapping types. Source=AutoMapper Inner Exception 1: AutoMapperMappingException: Missing type map configuration or unsupported mapping. So what I did wrong? Surprising, this maps fine:
public record UserModel(
int UserId,
string Name,
UserGender Gender,
DateTime DateOfBirth,
DateTime LastVisit,
bool Online);

public class UserEntity
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public UserGender Gender { get; set; }
public DateTime DateOfBirth { get; set; }
public DateTime LastVisit { get; set; }
public bool Online { get; set; }
public List<FriendRequestEntity> SendFriendRequests { get; set; } = new List<FriendRequestEntity>();
public List<FriendRequestEntity> ReceivedFriendRequests { get; set; } = new List<FriendRequestEntity>();
public List<MessageEntity> Messages { get; set; } = new List<MessageEntity>();
public List<MessageLikeEntity> MessageLikes { get; set; } = new List<MessageLikeEntity>();
}

CreateMap<UserModel, UserEntity>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.UserId));
public record UserModel(
int UserId,
string Name,
UserGender Gender,
DateTime DateOfBirth,
DateTime LastVisit,
bool Online);

public class UserEntity
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public UserGender Gender { get; set; }
public DateTime DateOfBirth { get; set; }
public DateTime LastVisit { get; set; }
public bool Online { get; set; }
public List<FriendRequestEntity> SendFriendRequests { get; set; } = new List<FriendRequestEntity>();
public List<FriendRequestEntity> ReceivedFriendRequests { get; set; } = new List<FriendRequestEntity>();
public List<MessageEntity> Messages { get; set; } = new List<MessageEntity>();
public List<MessageLikeEntity> MessageLikes { get; set; } = new List<MessageLikeEntity>();
}

CreateMap<UserModel, UserEntity>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.UserId));
12 replies
CC#
Created by kurumi on 1/30/2024 in #help
✅ Aspire .NET deploy into k8s
No description
20 replies
CC#
Created by kurumi on 10/23/2023 in #help
✅ async .NET MAUI binding
Hello, on Xamarin channel I found this code how to update UI with threads and async stuff. https://youtu.be/-LY4ATA8Bgw?si=cRmPMFNjL9-zTxui&t=1212 But in .NET MAUI it says Warning CS0618 'Device.BeginInvokeOnMainThread(Action)' is obsolete: 'Use BindableObject.Dispatcher.Dispatch() instead'. So how can I bind some async data from my API by using it? Leave an example please 😄
using CommunityToolkit.Mvvm.ComponentModel;
using MRSUMobile.MVVM.Model;
using MRSUMobile.Services;

namespace MRSUMobile.MVVM.ViewModel
{
public partial class AppShellViewModel : ObservableObject
{
IMrsuApiService mrsuApi;

[ObservableProperty]
User user = new User();

public AppShellViewModel(IMrsuApiService mrsuApiService)
{
mrsuApi = mrsuApiService;

// async binding of user ?
// user = await mrsuApi.GetMyProfile();
}
}
}
using CommunityToolkit.Mvvm.ComponentModel;
using MRSUMobile.MVVM.Model;
using MRSUMobile.Services;

namespace MRSUMobile.MVVM.ViewModel
{
public partial class AppShellViewModel : ObservableObject
{
IMrsuApiService mrsuApi;

[ObservableProperty]
User user = new User();

public AppShellViewModel(IMrsuApiService mrsuApiService)
{
mrsuApi = mrsuApiService;

// async binding of user ?
// user = await mrsuApi.GetMyProfile();
}
}
}
5 replies
CC#
Created by kurumi on 10/13/2023 in #help
❔ REST API but it is HttpListener only available
Hello there, I got a challenge to write good scalable C# REST API app by using only .NET 7 (instead of ASP .NET) with HttpListener. So I have some questions: 1) As I understood, it will only one HttpListener instance that catch all requests on different endpoints - not dedicated HttpListener to dedicated endpoint? 2) After I catch connection, I should do httpListenerInstance.GetContextAsync() and then transfer it to ThreadPool.QueueUserWorkItem? 3) How to execute some logic on needed endpoint? I found an answer by notifying all endpoints like hey my dudes, it is new connection to /endpoint can all of you handle it and execute if needed by checking itself context by using Observer pattern. But I see it may slower my system, is it any way to notify only 1 needed endpoint class? 4) ThreadPool.QueueUserWorkItem or it is better to create custom class which will store ConcurrentQueue<HttpListenerContext> with all my connections and then run another Task which will peak and notify endpoint func (see p.2 and p.3)? Please leave good advices - I can not use sweety ASP .NET.
30 replies