Mastalt
Mastalt
CC#
Created by Mastalt on 2/26/2024 in #help
.NET MAUI Grid Display?
No description
5 replies
CC#
Created by Mastalt on 2/7/2024 in #help
Grouping adjacent XYZ points, no idea how to go about this
Let's assume I have an array of point: 0,0,0 0,0,1 0,1,0 1,0,0 2,2,2 5,5,5 5,5,6 Both groups of points should result in 1 XYZ coordinates each, I can't figure out for my life how to do this. (No Screenshots as I have nothing)
60 replies
CC#
Created by Mastalt on 2/5/2024 in #help
MVC App's Post request not reaching
First off, yes I already asked this last friday but couldn't follow trough due to not having the source code for the weekend. Either way, here's my problem: I have an MVC Web Api in .NET 8.0, all Get requests from all controllers work as intended, but for Post requests on the other hand, they all return an HTTP Error 405 (Method not Allowed). Here is my initialization class and one of my Post method (they are all basiaclly structured the same) (Also, all the Cors stuff are things I already tried with no avail) Initialization Class:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<SkyblockRessourcesAPIContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("SkyblockRessourcesAPIContext") ?? throw new InvalidOperationException("Connection string 'SkyblockRessourcesAPIContext' not found."), x => x.UseNetTopologySuite()));

// Add services to the container.
builder.Services.AddControllersWithViews();

builder.Services.AddCors(o => o.AddDefaultPolicy(builder =>
{
builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
}));

var app = builder.Build();

app.UseCors(builder =>
{
builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
});

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<SkyblockRessourcesAPIContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("SkyblockRessourcesAPIContext") ?? throw new InvalidOperationException("Connection string 'SkyblockRessourcesAPIContext' not found."), x => x.UseNetTopologySuite()));

// Add services to the container.
builder.Services.AddControllersWithViews();

builder.Services.AddCors(o => o.AddDefaultPolicy(builder =>
{
builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
}));

var app = builder.Build();

app.UseCors(builder =>
{
builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
});

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
Controller Example:
[Route("api/[controller]")]
[ApiController]
public class RegionsController : ControllerBase
{
private readonly SkyblockRessourcesAPIContext _context;

public RegionsController(SkyblockRessourcesAPIContext context)
{
_context = context;
}

// GET: api/Regions/Get
[HttpGet]
[Route("Get")]
public async Task<ActionResult<IEnumerable<Region>>> GetRegion()
{
return await _context.Region.ToListAsync();
}

// POST: api/Regions/Post
[EnableCors("*", "*", "*")]
[HttpPost]
[Route("Post")]
public async Task<ActionResult<Region>> PostRegion([FromBody] Region region)
{
_context.Region.Add(region);
await _context.SaveChangesAsync();

return CreatedAtAction("GetRegion", new { id = region.Id }, region);
}

// DELETE: api/Regions/Delete
[HttpDelete]
[Route("Delete/all")]
public async Task<IActionResult> DeleteAllRegion()
{
var region = await _context.Region.ToListAsync();
if (region == null)
{
return NotFound();
}

_context.Region.RemoveRange(region);

return NoContent();
}

// DELETE: api/Regions/Delete?id=5
[HttpDelete]
[Route("Delete")]
public async Task<IActionResult> DeleteRegion(int id)
{
var region = await _context.Region.FindAsync(id);
if (region == null)
{
return NotFound();
}

_context.Region.Remove(region);
await _context.SaveChangesAsync();

return NoContent();
}
[Route("api/[controller]")]
[ApiController]
public class RegionsController : ControllerBase
{
private readonly SkyblockRessourcesAPIContext _context;

public RegionsController(SkyblockRessourcesAPIContext context)
{
_context = context;
}

// GET: api/Regions/Get
[HttpGet]
[Route("Get")]
public async Task<ActionResult<IEnumerable<Region>>> GetRegion()
{
return await _context.Region.ToListAsync();
}

// POST: api/Regions/Post
[EnableCors("*", "*", "*")]
[HttpPost]
[Route("Post")]
public async Task<ActionResult<Region>> PostRegion([FromBody] Region region)
{
_context.Region.Add(region);
await _context.SaveChangesAsync();

return CreatedAtAction("GetRegion", new { id = region.Id }, region);
}

// DELETE: api/Regions/Delete
[HttpDelete]
[Route("Delete/all")]
public async Task<IActionResult> DeleteAllRegion()
{
var region = await _context.Region.ToListAsync();
if (region == null)
{
return NotFound();
}

_context.Region.RemoveRange(region);

return NoContent();
}

// DELETE: api/Regions/Delete?id=5
[HttpDelete]
[Route("Delete")]
public async Task<IActionResult> DeleteRegion(int id)
{
var region = await _context.Region.FindAsync(id);
if (region == null)
{
return NotFound();
}

_context.Region.Remove(region);
await _context.SaveChangesAsync();

return NoContent();
}
14 replies
CC#
Created by Mastalt on 2/2/2024 in #help
MVC Post Methods not reaching
I am making an API for my application, and my Get methods work fine, but when I try a Post method, it doesn't even reach and return an error 405.
5 replies
CC#
Created by Mastalt on 3/22/2023 in #help
❔ Drawing preview in Windows Form PictureBox
I am trying to draw shapes on a picturebox and I need to have a preview of the drawing (just like paint and others) before drawing it onto the picturebox. Anyone knows how to do so?
2 replies
CC#
Created by Mastalt on 3/15/2023 in #help
❔ Visual Studio Build doesn't run on other computer
So I made a Visual Studio program for a client that has a bunch of dll when built, however, when i sent it to the client, they get an error saying "System.AggregateException: One or more errors occurred. (Response status code does not indicate success: 422 ().)" x30 times. From what I can see it's because the program sill uses my local files Ex:"C:/Users/aruest/..." even on their computer when they're connected on another user. Any fixes?
6 replies
CC#
Created by Mastalt on 12/2/2022 in #help
❔ Task stuck on WaitingforActivation
My code: https://paste.mod.gg/ldxpxvzrcxpi/0 Queues up the first 250 tasks, then is stuck at Task.WaitAll()
2 replies
CC#
Created by Mastalt on 12/1/2022 in #help
❔ Help with MultiThreading
28 replies
CC#
Created by Mastalt on 11/18/2022 in #help
✅ Multi-Threading not working
My multithreading isn't working Code:
tasks.Add(
Task.Run(() =>
{
DateTimeOffset findClosestToo = new DateTimeOffset(item.date.Year, item.date.Month, item.date.Day, item.date.Hour, 0, 0, TimeSpan.Zero);
NasaPower result;
Task<NasaPower> request = null;

if ((findClosestToo - previous).Duration() > (findClosestToo - item.date).Duration())
{
request = _client.GetFromJsonAsync<NasaPower>("?start=" + start.ToString("yyyyMMdd") + "&end=" + end.AddDays(1).ToString("yyyyMMdd") + "&latitude=" + item.latitude + "&longitude=" + item.longitude + "&community=re&parameters=ALLSKY_SFC_SW_DWN&format=json&header=true&time-standard=utc");
}
else
{
request = _client.GetFromJsonAsync<NasaPower>("?start=" + start.ToString("yyyyMMdd") + "&end=" + end.AddDays(1).ToString("yyyyMMdd") + "&latitude=" + previousItem.latitude + "&longitude=" + previousItem.longitude + "&community=re&parameters=ALLSKY_SFC_SW_DWN&format=json&header=true&time-standard=utc");
}

request.Wait();
result = request.Result;

solarPotential += result.properties.parameter.ALLSKY_SFC_SW_DWN[findClosestToo.ToString("yyyyMMddHH")];
Console.WriteLine(findClosestToo + "\t\t" + result.properties.parameter.ALLSKY_SFC_SW_DWN[findClosestToo.ToString("yyyyMMddHH")] + "\t\t" + solarPotential);
lock (outputResults)
{
outputResults.Add(new object[] { findClosestToo, result.properties.parameter.ALLSKY_SFC_SW_DWN[findClosestToo.ToString("yyyyMMddHH")], solarPotential });
}
}));
tasks.Add(
Task.Run(() =>
{
DateTimeOffset findClosestToo = new DateTimeOffset(item.date.Year, item.date.Month, item.date.Day, item.date.Hour, 0, 0, TimeSpan.Zero);
NasaPower result;
Task<NasaPower> request = null;

if ((findClosestToo - previous).Duration() > (findClosestToo - item.date).Duration())
{
request = _client.GetFromJsonAsync<NasaPower>("?start=" + start.ToString("yyyyMMdd") + "&end=" + end.AddDays(1).ToString("yyyyMMdd") + "&latitude=" + item.latitude + "&longitude=" + item.longitude + "&community=re&parameters=ALLSKY_SFC_SW_DWN&format=json&header=true&time-standard=utc");
}
else
{
request = _client.GetFromJsonAsync<NasaPower>("?start=" + start.ToString("yyyyMMdd") + "&end=" + end.AddDays(1).ToString("yyyyMMdd") + "&latitude=" + previousItem.latitude + "&longitude=" + previousItem.longitude + "&community=re&parameters=ALLSKY_SFC_SW_DWN&format=json&header=true&time-standard=utc");
}

request.Wait();
result = request.Result;

solarPotential += result.properties.parameter.ALLSKY_SFC_SW_DWN[findClosestToo.ToString("yyyyMMddHH")];
Console.WriteLine(findClosestToo + "\t\t" + result.properties.parameter.ALLSKY_SFC_SW_DWN[findClosestToo.ToString("yyyyMMddHH")] + "\t\t" + solarPotential);
lock (outputResults)
{
outputResults.Add(new object[] { findClosestToo, result.properties.parameter.ALLSKY_SFC_SW_DWN[findClosestToo.ToString("yyyyMMddHH")], solarPotential });
}
}));
21 replies
CC#
Created by Mastalt on 11/18/2022 in #help
❔ Sort a list
how would sorting a list of object[] work with this:
outputResults.Sort((a, b) => a.CompareTo(b));
outputResults.Sort((a, b) => a.CompareTo(b));
5 replies
CC#
Created by Mastalt on 11/11/2022 in #help
❔ IEnumerable is empty for some reason
I want to add a filter to check if an IEnumerable is empty so i'm using IEnumerable.Any(), but my IEnumerable afterward is empty and i can't do anything with it. If i remove the check, the data is suddenly there.
6 replies