With Blue Horns
With Blue Horns
CC#
Created by With Blue Horns on 11/23/2023 in #help
Asp.net rate limiting
As the title says, tried to rate limit api (for each IP, instead of global, to not cause issues), but it doesn't seem to work. Current code from Program.cs
using System.Threading.RateLimiting;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

builder.Services.AddRateLimiter(options =>
{
options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
options.AddPolicy("fixed", httpContext => RateLimitPartition.GetFixedWindowLimiter(
partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
factory: partition => new FixedWindowRateLimiterOptions
{
PermitLimit = 1,
Window = TimeSpan.FromSeconds(10)
}));
});

var app = builder.Build();

app.UseRateLimiter();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});

app.Run();
using System.Threading.RateLimiting;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

builder.Services.AddRateLimiter(options =>
{
options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
options.AddPolicy("fixed", httpContext => RateLimitPartition.GetFixedWindowLimiter(
partitionKey: httpContext.Connection.RemoteIpAddress?.ToString(),
factory: partition => new FixedWindowRateLimiterOptions
{
PermitLimit = 1,
Window = TimeSpan.FromSeconds(10)
}));
});

var app = builder.Build();

app.UseRateLimiter();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});

app.Run();
6 replies
CC#
Created by With Blue Horns on 9/2/2023 in #help
❔ Failing in breaking for loop
I cannot break out of for loop, somehow
bool StopMoving = false;

public void Event1(int hp)
{
StopMoving = true;
MoveForm(0, 0, 1);
//This void is called when user clicked let's say a button
//Because of that, it can be called anytime
//Change the StopMoving to true to stop for loop, then call the function?
}

private void MovementManager()
{
MoveForm(600, 200, 4);
//This void is called upon start of the program
}

private void MoveForm(int targetX, int targetY, int time)
{
int framerate = 60;

int newTime = time * framerate;
int DistanceX = this.DesktopLocation.X - targetX;
int DistanceY = this.DesktopLocation.Y - targetY;

//Per Time Unit
int PTUX = DistanceX / (int)newTime;
int PTUY = DistanceY / (int)newTime;

Debug.Print($"Pos: {targetX}X {targetY}Y; Dis: {DistanceX}X {DistanceY}Y");

for (int i = newTime; i > 0; i--)
{
Thread.Sleep(1000 / framerate);
if (StopMoving)
{
StopMoving = false;
break; // This should exit the for loop, but doesn't?
}
Point tempPoint = new Point(this.DesktopLocation.X + PTUX, this.DesktopLocation.Y + PTUY);
this.Invoke((MethodInvoker)delegate
{
this.DesktopLocation = tempPoint;
});
}
}
bool StopMoving = false;

public void Event1(int hp)
{
StopMoving = true;
MoveForm(0, 0, 1);
//This void is called when user clicked let's say a button
//Because of that, it can be called anytime
//Change the StopMoving to true to stop for loop, then call the function?
}

private void MovementManager()
{
MoveForm(600, 200, 4);
//This void is called upon start of the program
}

private void MoveForm(int targetX, int targetY, int time)
{
int framerate = 60;

int newTime = time * framerate;
int DistanceX = this.DesktopLocation.X - targetX;
int DistanceY = this.DesktopLocation.Y - targetY;

//Per Time Unit
int PTUX = DistanceX / (int)newTime;
int PTUY = DistanceY / (int)newTime;

Debug.Print($"Pos: {targetX}X {targetY}Y; Dis: {DistanceX}X {DistanceY}Y");

for (int i = newTime; i > 0; i--)
{
Thread.Sleep(1000 / framerate);
if (StopMoving)
{
StopMoving = false;
break; // This should exit the for loop, but doesn't?
}
Point tempPoint = new Point(this.DesktopLocation.X + PTUX, this.DesktopLocation.Y + PTUY);
this.Invoke((MethodInvoker)delegate
{
this.DesktopLocation = tempPoint;
});
}
}
So, since moment of calling Event1 is unknown, it might interfere with MovementManager, so, I need it to break the for loop if needed, and then proceed to call MoveForm that is in Event1. Any suggestions how to fix this? Any idea why break doesn't work here?
26 replies
CC#
Created by With Blue Horns on 7/20/2023 in #help
✅ Dynamic settings .net core
As title says, I need to somehow achieve dynamic settings, where I can through script create a new setting in Properties.Settings.Default, under name, be able to access int that it's going to hold and increase the value by 1. I'm trying to create a way to track hours spent in versions (ex. v1.0 has been used for 10h, v1.1 has been used for 3h and v1.5 which has been used for 37h) of application, I was thinking that this is the best idea to store data since user won't be able to change the value in an easy way. Any suggestions how to even start? Or maybe is there any easier way to do it?
10 replies
CC#
Created by With Blue Horns on 5/19/2023 in #help
✅ Adding panel to table layout
2 replies