Mekasu0124
Mekasu0124
Explore posts from servers
CC#
Created by Mekasu0124 on 9/25/2024 in #help
✅ Assistance with CMD Commands (if not allowed, please delete)
ah it's
C:Get-Command <program name>
C:Get-Command <program name>
2 replies
CC#
Created by Mekasu0124 on 8/14/2024 in #help
✅ FileZilla Server & Client - How To
so I've gotten the server started and used the network configuration wizard to get that connection working and fixed. Through the wizard, I chose to use my IPv4 address for the public connections and my local ip for local connections. Now i'm having issues connecting the image #1 to image #2
3 replies
CC#
Created by Mekasu0124 on 8/14/2024 in #help
✅ FileZilla Server & Client - How To
also, apologies if this isn't an appropriate question as I know this is a discord server for c#
3 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
ok I appreciate iti ❤️
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
public class AppServer
{
private readonly HttpClient _httpClient;

public AppServer()
{
_httpClient = new HttpClient
{
BaseAddress = new Uri("http://10.0.0.246:8000/")
};
}

public async Task<string> ReadRootAsync()
{
try
{
HttpResponseMessage response = await _httpClient.GetAsync("/");
response.EnsureSuccessStatusCode();

string content = await response.Content.ReadAsStringAsync();
return content;
}
catch (Exception ex)
{
return $"Error: {ex.Message}";
}
}
}
public class AppServer
{
private readonly HttpClient _httpClient;

public AppServer()
{
_httpClient = new HttpClient
{
BaseAddress = new Uri("http://10.0.0.246:8000/")
};
}

public async Task<string> ReadRootAsync()
{
try
{
HttpResponseMessage response = await _httpClient.GetAsync("/");
response.EnsureSuccessStatusCode();

string content = await response.Content.ReadAsStringAsync();
return content;
}
catch (Exception ex)
{
return $"Error: {ex.Message}";
}
}
}
that's my AppServer that I'm using to connect tot he fast api
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
public partial class MainWindowViewModel : ViewModelBase
{
private readonly AppServer _appServer;

[ObservableProperty]
private string _greeting = "Hello, Avalonia!";

public IRelayCommand FetchGreetingCommand { get; }

public MainWindowViewModel()
{
_appServer = new AppServer();
FetchGreetingCommand = new AsyncRelayCommand(FetchGreetingAsync);
}

private async Task FetchGreetingAsync()
{
Greeting = await _appServer.ReadRootAsync();
}
}
public partial class MainWindowViewModel : ViewModelBase
{
private readonly AppServer _appServer;

[ObservableProperty]
private string _greeting = "Hello, Avalonia!";

public IRelayCommand FetchGreetingCommand { get; }

public MainWindowViewModel()
{
_appServer = new AppServer();
FetchGreetingCommand = new AsyncRelayCommand(FetchGreetingAsync);
}

private async Task FetchGreetingAsync()
{
Greeting = await _appServer.ReadRootAsync();
}
}
this doesn't work either. "Hello, Avalonia!" displays on the screen instead of "Hello, World!" from the server
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
I don't have a command written in though? Unless I should make the greeting change on a button click?
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
yea I'm trying to figure that part out with you guys. I'm just not that good at it
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
it's making the query. The console on the fastapi server shows that root is being accessed with code 200. It' just getting the frontend to do right lol
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
public partial class MainWindowViewModel : ViewModelBase
{
private AppServer _server = new();

[ObservableProperty]
private string _greeting = "";

public MainWindowViewModel()
{
Greeting = GetRoot().Result;
}

public async Task<string> GetRoot()
{
var result = await _server.GetRootAsync();
return result;
}
}
public partial class MainWindowViewModel : ViewModelBase
{
private AppServer _server = new();

[ObservableProperty]
private string _greeting = "";

public MainWindowViewModel()
{
Greeting = GetRoot().Result;
}

public async Task<string> GetRoot()
{
var result = await _server.GetRootAsync();
return result;
}
}
so I had an idea, but it failed. I changed my code to this, however, when I run the application, it doesn't launch the app. It just sits there
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
CommunityToolkit
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
I'm honestly not too sure. I don't normally practice my avalonia with asynch writing. and this is my first time not only doign that but using fastapi as a backend instead of a relative database that the application uses right there in the client folder inside of a root/Services folder
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
right. let me look back at my todo app
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
public partial class MainWindowViewModel : ViewModelBase
{
private AppServer _server = new();

public string Greeting = "";

public MainWindowViewModel()
{

}

public async Task<string> MainWindowViewModel()
{
Greeting = await _server.GetRootAsync();
}
}
public partial class MainWindowViewModel : ViewModelBase
{
private AppServer _server = new();

public string Greeting = "";

public MainWindowViewModel()
{

}

public async Task<string> MainWindowViewModel()
{
Greeting = await _server.GetRootAsync();
}
}
something like this
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
I'm dumb
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
oh wait
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
I do await the call inside of the try/catch
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
I thought it was. I wasn't entirely sure what to put there to get the value back
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
@get_routes.get("/")
async def read_root():
return { "message": "Hello, World!" }
@get_routes.get("/")
async def read_root():
return { "message": "Hello, World!" }
52 replies
CC#
Created by Mekasu0124 on 8/2/2024 in #help
✅ How To Use C# To Access FastAPI Server?
// MainWindowViewModel.cs
using MathGame.Services;

namespace MathGame.ViewModels;

public partial class MainWindowViewModel : ViewModelBase
{
private AppServer _server = new();

public string Greeting => _server.GetRootAsync().Result;
}
// MainWindowViewModel.cs
using MathGame.Services;

namespace MathGame.ViewModels;

public partial class MainWindowViewModel : ViewModelBase
{
private AppServer _server = new();

public string Greeting => _server.GetRootAsync().Result;
}
// ./Services/AppServer.cs
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace MathGame.Services;
public class AppServer
{
private const string _apiUrl = "http://10.0.0.246:8000/";
private static HttpClient _client = new();

public async Task<string> GetRootAsync()
{
_client.DefaultRequestHeaders.UserAgent.TryParseAdd("request");

try
{
var response = await _client.GetStringAsync(_apiUrl);
return response;
}
catch (Exception)
{
throw;
}
}
}
// ./Services/AppServer.cs
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace MathGame.Services;
public class AppServer
{
private const string _apiUrl = "http://10.0.0.246:8000/";
private static HttpClient _client = new();

public async Task<string> GetRootAsync()
{
_client.DefaultRequestHeaders.UserAgent.TryParseAdd("request");

try
{
var response = await _client.GetStringAsync(_apiUrl);
return response;
}
catch (Exception)
{
throw;
}
}
}
I'm created a default avalonia application using CommunityToolkit.MVVM. I'm just trying to change the greeting to the "Hello, World!" message that the frontend calls to get from the backend
52 replies