Kosta
Kosta
CC#
Created by Kosta on 3/14/2023 in #help
✅ Mvvm toolkit - messenger not working? Recive messege not invoked
Hey there im trying to recieve a simple messege using messenger Got this code:
if (Result == 1) {
SendToDbSave();
}

}

[RelayCommand]
public void SendToDbSave()
{
WeakReferenceMessenger.Default.Send(new SaveMessege(Result.ToString()));

}
if (Result == 1) {
SendToDbSave();
}

}

[RelayCommand]
public void SendToDbSave()
{
WeakReferenceMessenger.Default.Send(new SaveMessege(Result.ToString()));

}
public class MainVM : ObservableRecipient, IRecipient<SaveMessege>
{
public void Receive(SaveMessege message)
{
Console.WriteLine(message.Value);
}
}
public class MainVM : ObservableRecipient, IRecipient<SaveMessege>
{
public void Receive(SaveMessege message)
{
Console.WriteLine(message.Value);
}
}
So why dont i ever go into the recive messege? i do send the messege, but debug point wont go into recive method
4 replies
CC#
Created by Kosta on 3/13/2023 in #help
❔ Source Gen fails- Im guessing smth is wrong with my setup? simplest code
I have no idea whats going on actually, check out the View Model. using mvvm toolkit. Code: https://github.com/KostaKing/CW
3 replies
CC#
Created by Kosta on 3/8/2023 in #help
❔ Why do we need to provide values for base class we are inheriting from?
For example i have this:
public class Answer:Entity<Guid>
{

protected Answer()
{

}
public Answer(Guid id) : base(id)
{

}
}
public class Answer:Entity<Guid>
{

protected Answer()
{

}
public Answer(Guid id) : base(id)
{

}
}
Why do i need to base the Id back to the base class? what does it even do? How does the flow work? How does it know to set the id of the answer class because we are passing it to the base class?
5 replies
CC#
Created by Kosta on 3/7/2023 in #help
❔ Why do my source generated properties are unreacheable in code? using mvvm toolkit
Hello i got the following code:
public partial class CalculatorVM : ObservableObject
{
[ObservableProperty]
private int buttonOne = 1;

[ObservableProperty]
private int buttonTwo = 2;

[ObservableProperty]
private int buttonThree = 3;

[ObservableProperty]
private int buttonFour = 4;

[ObservableProperty]
private int buttonFive = 5;

[ObservableProperty]
private int buttonSix = 6;

[ObservableProperty]
private int buttonSeven = 7;

[ObservableProperty]
private int buttonEight = 8;

[ObservableProperty]
private int buttonNine = 9;

[ObservableProperty]
private double result, lastNumber;

[ObservableProperty]
SelectedOperator selectedOperator;

[ObservableProperty]
private int clickedNumber;

[ObservableProperty]
private Label resultLabel;



[RelayCommand]
public void NumbercClicked(int number)
{
var selectedNumber = number switch
{
1 => ButtonOne,
2 => ButtonTwo,
3 => ButtonThree,
4 => ButtonFour,
5 => ButtonFive,
6 => ButtonSix,
7 => ButtonSeven,
8 => ButtonEight,
9 => ButtonNine,

};
ClickedNumber = selectedNumber;
if (ClickedNumber == 0) Result = 0;
else Result = Result + selectedNumber;


}
public partial class CalculatorVM : ObservableObject
{
[ObservableProperty]
private int buttonOne = 1;

[ObservableProperty]
private int buttonTwo = 2;

[ObservableProperty]
private int buttonThree = 3;

[ObservableProperty]
private int buttonFour = 4;

[ObservableProperty]
private int buttonFive = 5;

[ObservableProperty]
private int buttonSix = 6;

[ObservableProperty]
private int buttonSeven = 7;

[ObservableProperty]
private int buttonEight = 8;

[ObservableProperty]
private int buttonNine = 9;

[ObservableProperty]
private double result, lastNumber;

[ObservableProperty]
SelectedOperator selectedOperator;

[ObservableProperty]
private int clickedNumber;

[ObservableProperty]
private Label resultLabel;



[RelayCommand]
public void NumbercClicked(int number)
{
var selectedNumber = number switch
{
1 => ButtonOne,
2 => ButtonTwo,
3 => ButtonThree,
4 => ButtonFour,
5 => ButtonFive,
6 => ButtonSix,
7 => ButtonSeven,
8 => ButtonEight,
9 => ButtonNine,

};
ClickedNumber = selectedNumber;
if (ClickedNumber == 0) Result = 0;
else Result = Result + selectedNumber;


}
I cant compile, tells me buttonOne etc dont exsist in the current context, The Repo: https://github.com/KostaKing/Calculator/tree/master/Calculator/ViewModels Anybody has any idea?
242 replies
CC#
Created by Kosta on 2/21/2023 in #help
❔ Azure Blob storage and multi tenancy, how to get a list of blobs with a specific key?
I've got an application based on the abp framework that gets a sentence from a user and is returning an audio file, I want to save that with a string like UserId-SessonID-CreationTime on the blob storage in azure, problem is i only have a method to get 1 blob, like GetBlob(key) I cannot get a list, no such method exsist. What basically im asking is how do i structure it? maybe blob storage aint the way? Perhaps another sql server that contains the key and the userID associated with it, and then query the blob storage in a foreach? The application is configured to use multi tenancy if it helps at all, The document i've been reading: https://docs.abp.io/en/abp/latest/Blob-Storing
2 replies
CC#
Created by Kosta on 2/14/2023 in #help
❔ How to map dateonly and timeonly?
Getting this error when trying to do a migration:
The property 'UserData.CreatedDate' could not be mapped because it is of type 'DateOnly', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
The property 'UserData.CreatedDate' could not be mapped because it is of type 'DateOnly', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
5 replies
CC#
Created by Kosta on 2/12/2023 in #help
❔ How does the execution pipeline works with interfaces that implement methods?
Lets say we have the icommand interfact, it has to methods : canExcute and Excute, When i bind said command to a button and click it, How does it know to go into the execute method? whats going on behind? Who is responsible for telling the code to go into that methode and where can i find it?
5 replies
CC#
Created by Kosta on 11/23/2022 in #help
❔ How do i enumarate this?
Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var sales = JsonSerializer.DeserializeAsyncEnumerable<Sales>(
responseStream,
new JsonSerializerOptions
{
DefaultBufferSize = 16384

});
Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var sales = JsonSerializer.DeserializeAsyncEnumerable<Sales>(
responseStream,
new JsonSerializerOptions
{
DefaultBufferSize = 16384

});
No foreeach possible
7 replies
CC#
Created by Kosta on 11/22/2022 in #help
❔ Why is my grpc so much slower then my minimal api? Need The Csharp Gods
Hey there a bit of an odd question I've downloaded the code for this : https://medium.com/geekculture/build-high-performant-microservices-using-grpc-and-net-6-adde158c5ac basically is streams 1 line at a time to a client~---takes about 1 min to stream 1.5 mil lines, Tried replicating the same behavior with Minimal Api and not sure how, But it takes 13 seconds to read and stream all 5 million records, Shouldnt it be slower? I think my code is badly messed up and probably rotter logic all over the place 😄 Any Help would be swell My Ui Code: using HttpClient client = new();
using HttpResponseMessage response = await client.GetAsync(
"http://localhost:5247/test",
HttpCompletionOption.ResponseHeadersRead
).ConfigureAwait(false);
IAsyncEnumerable<Sales> Sales= await response.Content.ReadFromJsonAsync<IAsyncEnumerable<Sales>>().ConfigureAwait(false);
var count = 0;
var watch = System.Diagnostics.Stopwatch.StartNew();

await foreach (var each in Sales)
{
Console.WriteLine(String.Format("New Order Receieved from {0}-{1},Order ID = {2}, Unit Price ={3}, Ship Date={4}", each.Country, each.Region, each.OrderID, each.UnitPrice, each.TotalRevenue));

}



The Backend:
using HttpResponseMessage response = await client.GetAsync(
"http://localhost:5247/test",
HttpCompletionOption.ResponseHeadersRead
).ConfigureAwait(false);
IAsyncEnumerable<Sales> Sales= await response.Content.ReadFromJsonAsync<IAsyncEnumerable<Sales>>().ConfigureAwait(false);
var count = 0;
var watch = System.Diagnostics.Stopwatch.StartNew();

await foreach (var each in Sales)
{
Console.WriteLine(String.Format("New Order Receieved from {0}-{1},Order ID = {2}, Unit Price ={3}, Ship Date={4}", each.Country, each.Region, each.OrderID, each.UnitPrice, each.TotalRevenue));

}



The Backend:
app.MapGet("/test", async () => { return MakeHttpCall(); });
``` async IAsyncEnumerable<Sales> MakeHttpCall()
{
var watch = System.Diagnostics.Stopwatch.StartNew();
int Count = 0;

using (var reader = new StreamReader("path"))
{
while (watch.Elapsed < TimeSpan.FromSeconds(60) && !reader.EndOfStream)
{
var line = reader.ReadLine();
var pieces = line.Split(',');
var _model = new Sales();

_model.Region = pieces[0];
_model.Country = pieces[1];

yield return _model;

}

}


}
``` async IAsyncEnumerable<Sales> MakeHttpCall()
{
var watch = System.Diagnostics.Stopwatch.StartNew();
int Count = 0;

using (var reader = new StreamReader("path"))
{
while (watch.Elapsed < TimeSpan.FromSeconds(60) && !reader.EndOfStream)
{
var line = reader.ReadLine();
var pieces = line.Split(',');
var _model = new Sales();

_model.Region = pieces[0];
_model.Country = pieces[1];

yield return _model;

}

}


}
Also the ui seems to start prining the text only when its all done, meaning not rly streaming.. (removed all the code regarding watch and count) Save me C# Gods
2 replies
CC#
Created by Kosta on 11/22/2022 in #help
❔ Explain This Speed Difference to me (Grpc vs Rest)
So i got two projects, each ones reads 5mil lines from a csv and stream to client. MinimalApi approach much faster-Unsure why. The miminalApi one streams all the 5 million records in a min or so. Maybe becuase its all local? The Code: ```
2 replies
CC#
Created by Kosta on 11/22/2022 in #help
Why cant i go into the methode? Seems to skip it entirely
20 replies
CC#
Created by Kosta on 11/22/2022 in #help
Trying to compare grpc to minimal api performence- minimal much faster, Logic probably rotten
So i got this grpc client that streams data from a csv to a console and just prints it, in 1 minute it can do about 1.5mil records. On the other hand i got this minimal api, Now here begins the problem Im guessing I need to use httpclient to make the call inorder to compare? Because before i had this:
var client = new HttpClient()
; await foreach (var line in MakeHttpCall())
{
Console.WriteLine(line);
}
var client = new HttpClient()
; await foreach (var line in MakeHttpCall())
{
Console.WriteLine(line);
}
And this was twice as fast , 3 million records in a minute then i figured out im testing it wrong, However how do i use a client and what methode i need to invoke in the foreach?
async IAsyncEnumerable<string> MakeHttpCall()
{
var watch = System.Diagnostics.Stopwatch.StartNew();
int Count = 0;

using (var reader = new StreamReader(@"C:\Users\kosta\source\repos\gRPCDemoUsingNET6\gRPCDemoUsingNET6\Data\sales_records.csv"))
{
while (watch.Elapsed < TimeSpan.FromSeconds(60) && !reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');
yield return line;
Count++;
}

}
watch.Stop();
Console.WriteLine($"Stream ended: Total Records:{Count.ToString()} in {watch.Elapsed.TotalMinutes} minutes and {watch.Elapsed.TotalSeconds} seconds.");
}
async IAsyncEnumerable<string> MakeHttpCall()
{
var watch = System.Diagnostics.Stopwatch.StartNew();
int Count = 0;

using (var reader = new StreamReader(@"C:\Users\kosta\source\repos\gRPCDemoUsingNET6\gRPCDemoUsingNET6\Data\sales_records.csv"))
{
while (watch.Elapsed < TimeSpan.FromSeconds(60) && !reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');
yield return line;
Count++;
}

}
watch.Stop();
Console.WriteLine($"Stream ended: Total Records:{Count.ToString()} in {watch.Elapsed.TotalMinutes} minutes and {watch.Elapsed.TotalSeconds} seconds.");
}
How do i procced? obviously im doing smth/multiple things wrong. If i try to do smth like this
await foreach (var line in client.GetAsync(""))
await foreach (var line in client.GetAsync(""))
I get a "does not contain extension defenition for getasyncenumarator
7 replies
CC#
Created by Kosta on 11/20/2022 in #help
Streaming a csv file to a console app with minimal api-How?
Hey Guys got this methode:
public string MakeHttpCall()
{
var watch = new Stopwatch();
Stopwatch.StartNew();
using (var reader = new StreamReader(@"C:\Users\kosta\source\repos\gRPCDemoUsingNET6\gRPCDemoUsingNET6\Data"))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');

}
return string.Empty;
}
}
}
public string MakeHttpCall()
{
var watch = new Stopwatch();
Stopwatch.StartNew();
using (var reader = new StreamReader(@"C:\Users\kosta\source\repos\gRPCDemoUsingNET6\gRPCDemoUsingNET6\Data"))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');

}
return string.Empty;
}
}
}
And this one in the Ui:
var client = new HttpClient();
await using Stream stream =
await client.GetStreamAsync("http://localhost:5276");
var lines =
await JsonSerializer.DeserializeAsync<List<string>>(stream);
foreach (var line in lines)
{
Console.WriteLine(line);

}
var client = new HttpClient();
await using Stream stream =
await client.GetStreamAsync("http://localhost:5276");
var lines =
await JsonSerializer.DeserializeAsync<List<string>>(stream);
foreach (var line in lines)
{
Console.WriteLine(line);

}
I want to stream the csv file to the ui, which happens here
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');

}
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');

}
Unsure how to do that
3 replies
CC#
Created by Kosta on 11/6/2022 in #help
Silly Question -How do I clone these grpc examples?
https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/tutorials/grpc/grpc-start/sample6 Offical Ms repo, wanna clone both but cant, No Code button or anything, what am i missing?
3 replies