Wrenpo
Wrenpo
CC#
Created by Wrenpo on 11/5/2024 in #help
Safely getting a result from a async method within a sync method
Sorry, was busy at work and didn't get back to this. Thank you for all the responses! I am aware of the deadlocking possibilities and have read up on some of Stephen Cleary's articles about this including his SO answers to similar questions. I have since converted my async method into a synchronous one. I am running into a situation now where the remote server is closing the request early. I am working with Azure AD B2C and .NET Framwork 4.8. Inside our middleware (OWIN), a synchronous method is establishing the initial connection with Azure AD B2C to identify a user and allow them into the app. However, what this does not handle is giving back the refresh token. It was assumed that it did this automatically. It does not. It disposes it and does not store it anywhere. So, I have been manually trying to do this from what was originally my async method. I can take my authorization code that I get from B2C and with a request body, send a GET over to the token endpoint on Postman and get what I want. I am going a bit crazy trying to get this working from the app.
37 replies
CC#
Created by maja on 10/6/2024 in #help
How to start coding C# in vs code??
3 replies
CC#
Created by Wrenpo on 10/6/2024 in #help
Studying singly linked lists and need help understanding pointer functionality
Thanks. Everytime I have come across pass by reference or pass by value or stack vs heap, I feel like a novice all over again. It's like one hurdle I never conquered.
18 replies
CC#
Created by Wrenpo on 10/6/2024 in #help
Studying singly linked lists and need help understanding pointer functionality
aka:
int x = 5; // x is a local variable and is stored on the stack

// y is a reference to an object and is stored on the stack
// the object itself is stored on the heap
string y = new string("hello");

// z is a reference to the same object as y
// both y and z are stored on the stack, but the object is only stored once on the heap
string z = y;

// the object referenced by y and z is no longer needed, so the garbage collector will deallocate the memory on the heap
y = null;
z = null;
int x = 5; // x is a local variable and is stored on the stack

// y is a reference to an object and is stored on the stack
// the object itself is stored on the heap
string y = new string("hello");

// z is a reference to the same object as y
// both y and z are stored on the stack, but the object is only stored once on the heap
string z = y;

// the object referenced by y and z is no longer needed, so the garbage collector will deallocate the memory on the heap
y = null;
z = null;
18 replies
CC#
Created by Wrenpo on 10/6/2024 in #help
Studying singly linked lists and need help understanding pointer functionality
Car and ListNode are objects and go on the heap, including their properties. The local variables myCar, newCar, dummy, and current are on the stack. When I code current.next or myCar.IsRunning, I am referring to the heap object and not the local variable?
18 replies
CC#
Created by Wrenpo on 10/6/2024 in #help
Studying singly linked lists and need help understanding pointer functionality
So I guess the following would be true if my understanding is correct:
Car myCar = new ();
Car newCar = myCar; // references the same memory as myCar
newCar.IsRunning = true // myCar and newCar's .IsRunning property change to true
newCar = null // or if set to a new object, only newCar changes but not the myCar object
Car myCar = new ();
Car newCar = myCar; // references the same memory as myCar
newCar.IsRunning = true // myCar and newCar's .IsRunning property change to true
newCar = null // or if set to a new object, only newCar changes but not the myCar object
Basically, if I change the new object that references the previous object to a new object or null, only the new object changes. However, in the original code block, during the while loop, current.Next still updates the links between the nodes. Is this because the property is the same as the object?
18 replies
CC#
Created by Wrenpo on 10/6/2024 in #help
Studying singly linked lists and need help understanding pointer functionality
What documentation can I look up to learn more about this? When doing searches around variables, pass-by-value, pointers, addresses, I get thrown a lot of info about pointers in the literal sense like int* ptr.
18 replies
CC#
Created by Wrenpo on 10/6/2024 in #help
Studying singly linked lists and need help understanding pointer functionality
I think I am following. I am guessing that current and dummy are stored in different memory and that's why changing one does not overwrite the other. With dummy being initialized to a val = 0 from the ListNode constructor, why does dummy not keep that val when creating the chained nodes?
18 replies
CC#
Created by Wrenpo on 10/6/2024 in #help
Studying singly linked lists and need help understanding pointer functionality
I guess what is breaking my brain is the following: - I set current = dummy (current is now the object dummy instead of just a copy) - I set current.next = temp (dummy.next now equals temp and so does current.next) - I set current = temp (why does temp not replace dummy as a whole since setting current.next changes dummy.next?)
18 replies
CC#
Created by greg/Ryhor on 9/10/2024 in #help
Not sure what Senior Dev expect me to do
I am just wondering... have you talked to your senior dev yet about this directly? Share your thoughts and maybe he can expand on his. Open that communication channel! That's most of the job anyhow.
17 replies
CC#
Created by Wrenpo on 6/3/2023 in #help
✅ MVC Core: Model Properties Not Passing to Controller Method
Disregard. I've figured out several issues. The main one being an AutoMapper issue.
6 replies
CC#
Created by Wrenpo on 6/3/2023 in #help
✅ MVC Core: Model Properties Not Passing to Controller Method
[HttpPost]
[Authorize]
public async Task<IActionResult> TrainingSessionRosterReview(int id, TrainingSessionRosterReview model, CancellationToken cancellationToken = default)
{
List<CourseSessionRegistration> courseSessionRegistrations = await this.DbContext.CourseSessionRegistrations.Where(x => x.CourseSessionId == id).ToListAsync(cancellationToken);

foreach (CourseSessionRegistration courseSessionRegistration in courseSessionRegistrations)
{
TrainingSessionRosterRegistrant? currentRegistrant = model.Registrants.FirstOrDefault(reg => reg.RegistrantId == courseSessionRegistration.RegistrantId);

if (currentRegistrant != null)
{
courseSessionRegistration.Attended = currentRegistrant.IsAttendanceConfirmed;
courseSessionRegistration.AttendanceConfirmationDate = currentRegistrant.IsAttendanceConfirmed ? DateTime.Now : null;
}
}

await this.DbContext.SaveChangesAsync(cancellationToken);

return this.RedirectToAction(nameof(AdminController.TrainingSessionRoster));
}
[HttpPost]
[Authorize]
public async Task<IActionResult> TrainingSessionRosterReview(int id, TrainingSessionRosterReview model, CancellationToken cancellationToken = default)
{
List<CourseSessionRegistration> courseSessionRegistrations = await this.DbContext.CourseSessionRegistrations.Where(x => x.CourseSessionId == id).ToListAsync(cancellationToken);

foreach (CourseSessionRegistration courseSessionRegistration in courseSessionRegistrations)
{
TrainingSessionRosterRegistrant? currentRegistrant = model.Registrants.FirstOrDefault(reg => reg.RegistrantId == courseSessionRegistration.RegistrantId);

if (currentRegistrant != null)
{
courseSessionRegistration.Attended = currentRegistrant.IsAttendanceConfirmed;
courseSessionRegistration.AttendanceConfirmationDate = currentRegistrant.IsAttendanceConfirmed ? DateTime.Now : null;
}
}

await this.DbContext.SaveChangesAsync(cancellationToken);

return this.RedirectToAction(nameof(AdminController.TrainingSessionRoster));
}
6 replies
CC#
Created by matuda. on 6/3/2023 in #help
❔ Smaller number in a Loop
I learned from books at first and asking friends that already knew how to code. I played with the code until I created something I wanted. Lots of trial and error. Still is.
37 replies
CC#
Created by matuda. on 6/3/2023 in #help
❔ Smaller number in a Loop
Also, once you figure out the baseline of how to get this functional... Try to think from a user's shoes. Can they input anything else besides numbers? How can I break this?
37 replies
CC#
Created by matuda. on 6/3/2023 in #help
❔ Smaller number in a Loop
- read input - check/compare input to validation (that 0 is key here) - store the inputs somehow to compare for minimum number - print back to user
37 replies