surwren
surwren
Explore posts from servers
CC#
Created by surwren on 11/8/2024 in #help
Refactoring Similar Network Requests
I have 3 async methods with a great deal of similarities but some differences (some use Authorization token, some have Json payload, some return Task<bool>, others Task) but all make network requests in a similar flow. What is an approach I could use to refactor them?
93 replies
CC#
Created by surwren on 11/8/2024 in #help
Making Concurrent API calls Asynchronously (Is this Correct?)
Apologies for the long code, need to split it up into 2 posts because it's really long:
async Task SendUserInfoRequestAsync() {
if (string.IsNullOrEmpty(sessionCache.loginToken)) {
Debug.LogError("No login token found.....");
return;
}
Uri userInfoUri = new Uri(new Uri(baseUrl), userInfoRoute);
Uri getUserInfoUri = new Uri(new Uri(baseUrl), getUserInfoRoute);

using (HttpClient client = new HttpClient()) {
try {
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", sessionCache.loginToken);

Task<HttpResponseMessage> task1 = client.PostAsync(userInfoUri, null);
Task<HttpResponseMessage> task2 = client.PostAsync(getUserInfoUri, null);

HttpResponseMessage response1 = await task1;
HttpResponseMessage response2 = await task2;

if (!response1.IsSuccessStatusCode || !response2.IsSuccessStatusCode) {
string errorMessage = "Request from SendUserInfoRequestAsync() failed. ";
if (!response1.IsSuccessStatusCode) {
lastHttpResponseError = response1;
errorMessage += $"First request failed";
}
if (!response2.IsSuccessStatusCode) {
lastHttpResponseError = response2;
errorMessage += $"Second request failed.";
}
Debug.LogError(errorMessage);
}
async Task SendUserInfoRequestAsync() {
if (string.IsNullOrEmpty(sessionCache.loginToken)) {
Debug.LogError("No login token found.....");
return;
}
Uri userInfoUri = new Uri(new Uri(baseUrl), userInfoRoute);
Uri getUserInfoUri = new Uri(new Uri(baseUrl), getUserInfoRoute);

using (HttpClient client = new HttpClient()) {
try {
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", sessionCache.loginToken);

Task<HttpResponseMessage> task1 = client.PostAsync(userInfoUri, null);
Task<HttpResponseMessage> task2 = client.PostAsync(getUserInfoUri, null);

HttpResponseMessage response1 = await task1;
HttpResponseMessage response2 = await task2;

if (!response1.IsSuccessStatusCode || !response2.IsSuccessStatusCode) {
string errorMessage = "Request from SendUserInfoRequestAsync() failed. ";
if (!response1.IsSuccessStatusCode) {
lastHttpResponseError = response1;
errorMessage += $"First request failed";
}
if (!response2.IsSuccessStatusCode) {
lastHttpResponseError = response2;
errorMessage += $"Second request failed.";
}
Debug.LogError(errorMessage);
}
12 replies
CC#
Created by surwren on 11/8/2024 in #help
What is the quickest way to copy API structures (headers, payload, response) from browser inspector?
No description
9 replies
CC#
Created by surwren on 11/7/2024 in #help
Can't Refactor Or Save this Class File (Lazily Loaded Singleton)
using System;

public sealed class SessionCache {
private static readonly Lazy<SessionCache> lazy =
new Lazy<SessionCache>(() => new SessionCache());

public static SessionCache Instance { get { return lazy.Value; } }
public UserData userData { get; set; }

private SessionCache() {
}
}
using System;

public sealed class SessionCache {
private static readonly Lazy<SessionCache> lazy =
new Lazy<SessionCache>(() => new SessionCache());

public static SessionCache Instance { get { return lazy.Value; } }
public UserData userData { get; set; }

private SessionCache() {
}
}
Am I doing something wrong in the syntax? .NET CORE 2.1
4 replies
CC#
Created by surwren on 5/15/2024 in #help
Deployment vs production environments
I am preparing for a .NET role and am wondering what some configurations/setups/tools I can look up or prepare for? For context: The company is using .NET and Azure. Development is done via login to a VMware portal (IDE and environment are setup inside said VM) and there are a series of CICD tools facilitating any code pushes within said VMware portal. What deployment/production configurations or tools should I look into?
3 replies
CC#
Created by surwren on 4/26/2024 in #help
What are some tools or methods for debugging microservices?
I am considering a microservices developer role and was wondering what some tools or strategies to debugging microservices are. My friends told me to 'just do monolithic', but there has to be a way right? Not everyone uses monolithic and microservices are good job experience?
13 replies
CC#
Created by surwren on 4/7/2024 in #help
✅ "Legacy Versions" of C# or .NET?
As per title, I was wondering what would be considered legacy stacks when looking up companies. I am aware of what the Java equivalent tends to be (Java 6-8, JSP, etc) but I am unfamiliar with what indicators there are for legacy C# or .NET stacks in the industry. Is anyone able to provide some insight?
17 replies
CC#
Created by surwren on 3/30/2024 in #help
Using SQL with C# or ASP.NET, without an ORM
I have a question about using SQL with C# or ASP.NET, without an ORM What are the most common ways this is done? What advantages would manual queries have over ORM generated ones
14 replies
CC#
Created by surwren on 2/6/2024 in #help
Application Architecture Question
No description
16 replies
CC#
Created by surwren on 1/12/2024 in #help
How to check bandwidth of websocket connection?
As per title. I'm currently using websocket-sharp, but I'm wondering if there is a universal way to do it. I am thinking of sending 5 * 30 fps data (so basically 150 fps) and don't know if my websocket connection can handle it.
4 replies