FusedQyou
FusedQyou
CC#
Created by FusedQyou on 5/15/2024 in #help
✅ How do I gracefully asynchronously exit a console application?
I am working on a console application that runs an asynchronous method until the console application exits. I want to gracefully exit this method and handle remaining work before fully closing. The code currently looks like this (only relevant code shared) Program.cs: https://gdl.space/acabuvokev.cs BotApplication.cs: https://gdl.space/tumeduveko.cs Expected: The console logs Stopped application.. Actual: The last message was Starting bot.. Is this possible at all? I want to add additional logic below before the console is exited, but I can't figure out the correct way of doing this.
55 replies
CC#
Created by FusedQyou on 4/12/2024 in #help
My socket won't send data to 600 endpoints
My application sends a packet to 600 servers in order to gather data about active players and such. My old code would use a parallel loop and this worked fine but was incredibly slow. After removing it my code is much faster, but only 58 out of the 600 servers now return data. Is there some limitation on how much data a socket can handle at once? This is the method used. The endPoints array would contain 600 endPoints. I verified the method only parsed about 58 servers by checking how many of the pending builders actually ende dup getting parsed. At the bottom you see a loop that checks for pending builders that did not get parsed and this shows the timed out servers. https://gdl.space/irafuvuvam.cs
44 replies
CC#
Created by FusedQyou on 6/16/2023 in #help
❔ Best way to set up a websocket and API to access the data?
I'm working on a website that gathers data through a websocket on the backend, using raw UDP packets. The protocol indicates that I can request data, and then immediately receive that data in batches until a special code is retreived to indicate the end of the collection. I want to display this data on the frontend by calling an API to fetch it. The big challenge here is how I set up the backend to properly contain the data. I was thinking of having a background task occasionally fetch the data in an interval, and then have it store the data in a database. The API then always has this data available, or it will wait a bit whilst the newer batch is fetched. Would this be viable, or is there a better way to fetch the data and making sure the API always retrieves the data for the frontend? How can I properly create a background task that is invoked every 5 minutes so that I can fetch the data?
33 replies
CC#
Created by FusedQyou on 3/14/2023 in #help
❔ Check if Type is static
This question is probably vague as shit, but I always do this check to ensure a type is static:
private bool IsStatic(Type type)
{
return type.IsAbstract && type.IsSealed;
}
private bool IsStatic(Type type)
{
return type.IsAbstract && type.IsSealed;
}
So, this works because static classes are declared abstract and sealed at the IL level. My question is if this is actually valid and won't fail, ever. C# doesn't exactly have a isStatic field or something.
5 replies
CC#
Created by FusedQyou on 12/22/2022 in #help
❔ Why does my response get capitalized?
13 replies
CC#
Created by FusedQyou on 12/9/2022 in #help
✅ This EntityFramework query can not be translated for SQLite
The issue lies within Intersect. The point of the query is to fetch the current user, and to populate LikedByUsers with matched users. An user is matched when he appears in LikedByUsers and LikedUsers. How can I make this work for SQLite? Error: "Translating this query requires the SQL APPLY operation, which is not supported on SQLite."
private IQueryable<DataUser> CreateGetAllMatchedUsersQuery(DataUser user, bool includeDeleted)
{
var query = this._databaseContext.Users.AsQueryable();
query = query.Where(x => x.Id == user.Id);

// Ensure no deleted users are returned if specified not to.
if (!includeDeleted)
{
query = query.Where(x => !x.Deleted);
query = query.Include(x => x.LikedByUsers.Where(y => !y.Deleted));
query = query.Include(x => x.LikedUsers.Where(y => !y.Deleted));
}
else
{
query = query.Include(x => x.LikedByUsers);
query = query.Include(x => x.LikedUsers);
}

// Select all matches
query = query.SelectMany(x => x.LikedByUsers.Intersect(x.LikedUsers));
return query;
}
private IQueryable<DataUser> CreateGetAllMatchedUsersQuery(DataUser user, bool includeDeleted)
{
var query = this._databaseContext.Users.AsQueryable();
query = query.Where(x => x.Id == user.Id);

// Ensure no deleted users are returned if specified not to.
if (!includeDeleted)
{
query = query.Where(x => !x.Deleted);
query = query.Include(x => x.LikedByUsers.Where(y => !y.Deleted));
query = query.Include(x => x.LikedUsers.Where(y => !y.Deleted));
}
else
{
query = query.Include(x => x.LikedByUsers);
query = query.Include(x => x.LikedUsers);
}

// Select all matches
query = query.SelectMany(x => x.LikedByUsers.Intersect(x.LikedUsers));
return query;
}
36 replies
CC#
Created by FusedQyou on 12/8/2022 in #help
❔ EntityFramework many-to-many relation does not work
66 replies
CC#
Created by FusedQyou on 12/3/2022 in #help
❔ Unable to get automapper's projectTo() to work properly.
I need to use ProjectTo() to properly cast a query into a DTO, but in this case my user can only contains pictures which have Deleted = false. The code below works, but all photo's are returned, including deleted ones. The commented Include() works fine, but I need the mapping to happen on query level, and not after, because of the creation of a paginatedList. If I map later, the PaginatedList misses crucial information, and I do not want to change its behaviour.
public async Task<PaginatedList<DTODataUser>> GetAllDTOPaginatedAsync(PaginatedQuery pagination, bool includeDeleted, CancellationToken cancellationToken)
{
var userQuery = this._databaseContext
.Users
.Where(x => !includeDeleted ? !x.Deleted : true)
.ProjectTo<DTODataUser>(this._mapper.ConfigurationProvider, null, (user) => user.Photos.Where(y => !includeDeleted ? !y.Deleted : true));
//.Include(x => x.Photos.Where(y => !includeDeleted ? !y.Deleted : true))

var users = await PaginatedList<DTODataUser>.CreateAsync(userQuery, pagination, cancellationToken);
return users;
}
public async Task<PaginatedList<DTODataUser>> GetAllDTOPaginatedAsync(PaginatedQuery pagination, bool includeDeleted, CancellationToken cancellationToken)
{
var userQuery = this._databaseContext
.Users
.Where(x => !includeDeleted ? !x.Deleted : true)
.ProjectTo<DTODataUser>(this._mapper.ConfigurationProvider, null, (user) => user.Photos.Where(y => !includeDeleted ? !y.Deleted : true));
//.Include(x => x.Photos.Where(y => !includeDeleted ? !y.Deleted : true))

var users = await PaginatedList<DTODataUser>.CreateAsync(userQuery, pagination, cancellationToken);
return users;
}
How can I replicate Include to work with projectTo? As said above, the current version is allowed, but deleted photo's are returned too.
28 replies