Ole (ping please)
Ole (ping please)
CC#
Created by Ole (ping please) on 6/6/2024 in #help
Unable to determine reason for publish error
No description
10 replies
CC#
Created by Ole (ping please) on 11/15/2023 in #help
Deserializing binary data
I have the following structures:
Root:
int32 nameLength
byte[nameLength] name
int32 numItems
Item[numItems] Items

Item:
int32 itemNameLength
byte[itemNameLength] itemName
int32 VertexLength
Vertex[ArrayLength] VertexList

Vertex:
float X
float Y
float z
Root:
int32 nameLength
byte[nameLength] name
int32 numItems
Item[numItems] Items

Item:
int32 itemNameLength
byte[itemNameLength] itemName
int32 VertexLength
Vertex[ArrayLength] VertexList

Vertex:
float X
float Y
float z
I am curious, what is the best way to serialize this? Currently I simply read it into a stream and reads one attribute at the time. Coming from a c++ background this feels highly inefficent. When I try to google the problem I dont get a lot of new results, but I suspect there might be some changes to the language in the last 10 years which have improved tasks like this?
16 replies
CC#
Created by Ole (ping please) on 9/7/2023 in #help
❔ Selecting child tables using EF Core
I have the following class hierarchy Enterprise => Company => Site => Department => Container What would be the most efficent way of selecting a container with a given ID using ef core. In my DbContext I only have a reference to the root object, Enterprise Currently I have this mess:
return await _dbContext.Enterprise
.AsNoTracking()
.Include(x => x.Companies)
.ThenInclude(x => x.Sites)
.ThenInclude(x => x.Departments)
.ThenInclude(x => x.Containers)
.SelectMany(x => x.Companies)
.SelectMany(x => x.Sites)
.SelectMany(x => x.Departments)
.SelectMany(x => x.Containers)
.FirstOrDefaultAsync(x => x.Id == id);
return await _dbContext.Enterprise
.AsNoTracking()
.Include(x => x.Companies)
.ThenInclude(x => x.Sites)
.ThenInclude(x => x.Departments)
.ThenInclude(x => x.Containers)
.SelectMany(x => x.Companies)
.SelectMany(x => x.Sites)
.SelectMany(x => x.Departments)
.SelectMany(x => x.Containers)
.FirstOrDefaultAsync(x => x.Id == id);
10 replies
CC#
Created by Ole (ping please) on 7/30/2023 in #help
❔ Getting all instances from a IServiceScope
I have a callback system that I want to ensure all subscribers are removed from when a dependency scope is destroyed. To achive this I want to itterate over all instanciated class and unregister them. But I am struggeling with getting all created instances from the IServiceScope. I cant cast to ServiceProviderEngineScope, as that is a sealed internal class. How does one normally access this information?
29 replies
CC#
Created by Ole (ping please) on 7/3/2023 in #help
❔ Help with Action syntax for event handler system
I am trying to add a basic event system to my program and would like the syntax to be something like this:
RegisterEventHandler<EventHandler, MyEvent>(x.Process);
RegisterEventHandler<EventHandler, MyEvent>(x.Process);
Ideally there is no need for a baseclass or interface. All that should be needed is for the function passed as an action to take the event type as an argument. I have the following implmentation for the registration:
void RegisterEventHandler<THandler, TEvent>(Action<THandler, TEvent> action)
void RegisterEventHandler<THandler, TEvent>(Action<THandler, TEvent> action)
I would very much like the register syntax to be like this:
RegisterEventHandler<EventHandler, MyEvent>(x.Process);
RegisterEventHandler<EventHandler, MyEvent>(x.Process);
but I struggle with how to achive this, and I am not entirely sure if its possible?
7 replies
CC#
Created by Ole (ping please) on 6/27/2023 in #help
❔ Setting tab name dynamically
I am trying to set the header for a tab in a tabcontroll based on the content, but struggle to make it work. I have the following wpf layout:
<TabControl Grid.Row="1" Grid.Column="2"
ItemsSource="{Binding CurrentEditorsList, UpdateSourceTrigger=PropertyChanged}"
SelectedIndex = "{Binding SelectedEditorIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Name="EditorsTabControl">
<TabControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="0" Text="{Binding DisplayName.Value, UpdateSourceTrigger=PropertyChanged}">
</TextBlock>
<Button Grid.Column="1"
Command="{Binding DataContext.CloseToolCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=TabControl}}"
CommandParameter="{Binding}"
HorizontalContentAlignment="Right">
</Button>
</Grid>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
<TabControl Grid.Row="1" Grid.Column="2"
ItemsSource="{Binding CurrentEditorsList, UpdateSourceTrigger=PropertyChanged}"
SelectedIndex = "{Binding SelectedEditorIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Name="EditorsTabControl">
<TabControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="0" Text="{Binding DisplayName.Value, UpdateSourceTrigger=PropertyChanged}">
</TextBlock>
<Button Grid.Column="1"
Command="{Binding DataContext.CloseToolCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=TabControl}}"
CommandParameter="{Binding}"
HorizontalContentAlignment="Right">
</Button>
</Grid>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
CurrentEditorsList is a UserControl where the DataContext is set to an object which has an object DisplayName.Value. I have also tried DataContext.DisplayName.Value, but it also does not work. How do I reference the content of the user control in this context?
2 replies
CC#
Created by Ole (ping please) on 6/17/2023 in #help
❔ Getting the last data registration time for multiple locations
I have the following Sql table, which I access using ef core.
Id | Location | DataValue | RegistrationDate
Id | Location | DataValue | RegistrationDate
I need to find the last registration date for each different location. Currenetly I do the following:
var locations = _dbContext.Table.Select(x=>x.Location).Distinct().ToList();
foreach(var location in locations)
{
var date = _dbContext.Table.Where(x=>x.location = location).OrderBy(x=>x.RegistrationDate).Top(1);
}
var locations = _dbContext.Table.Select(x=>x.Location).Distinct().ToList();
foreach(var location in locations)
{
var date = _dbContext.Table.Where(x=>x.location = location).OrderBy(x=>x.RegistrationDate).Top(1);
}
This is obviously not great. What would be the propper way to do this?
15 replies
CC#
Created by Ole (ping please) on 5/16/2023 in #help
❔ Sorting a list of objects into a tree structure
I have a set of objects that looks roughly like this: class Item { public uint Id; public uint ParentId; } To visualize the data I want to sort the data into a graph. Is there a built in way of doing this in C#? For the actual visualisation I am happy with just viewing it in the debugger. The reason for asking the question instead of just doing it is that I want to get better at using built in functionality. I string.Join(", ", array) was a game changer for example
8 replies
CC#
Created by Ole (ping please) on 4/5/2023 in #help
❔ How to handle migration with column changes in Ef Core code first?
I need to change a table which is already in production. Specifically I need to change a field which is currently an integer which represents a week number. I now need to change it to a proper datatime. Ideally I would like to do something like this: 1. Add a new column to the table - StartDate 2. Add some code to the migration Up file which runs through all the instances of that table and reads the StartWeek column and writes to the StartDate 3. Remove the StartWeek column What is the best practice for handling this?
7 replies
CC#
Created by Ole (ping please) on 3/7/2023 in #help
❔ Infer the second generic type from input data
I am wondering if its possible to write the following code in some way that it works like I want it to. My goal is to specify a class and an argument. The function should then create the class and pass the argument to it.
Execute<MyValidator0>(someData0); // Does not work, any way to change it so I can call it like this?
Execute<MyValidator1, MyDataType>(someData1); // Works


void Execute<V, Arg>(Arg argument) where V:IValidator<Arg>, new()
{
var instance = new V();
instance.ValidateAndThrow(argument);
}
Execute<MyValidator0>(someData0); // Does not work, any way to change it so I can call it like this?
Execute<MyValidator1, MyDataType>(someData1); // Works


void Execute<V, Arg>(Arg argument) where V:IValidator<Arg>, new()
{
var instance = new V();
instance.ValidateAndThrow(argument);
}
8 replies
CC#
Created by Ole (ping please) on 8/19/2022 in #help
JsonSerializer.Serialize skips children
I have a somewhat complex object, but when I serialize it to json I dont get all the children serialized correctly. The arrays are empty even though they should not be,.
var hircAsString = JsonSerializer.Serialize((object)selectedNode.Item, new JsonSerializerOptions() { MaxDepth = 32, WriteIndented = true});
var hircAsString = JsonSerializer.Serialize((object)selectedNode.Item, new JsonSerializerOptions() { MaxDepth = 32, WriteIndented = true});
Output: AkPropBundle1 should contain 4 items.
{
"AkBankSourceData": {
"PluginId": 262145,
"PluginId_type": 1,
"PluginId_company": 0,
"StreamType": 0,
"akMediaInformation": {
"SourceId": 378298469,
"uInMemoryMediaSize": 12089,
"uSourceBits": 0
},
"uSize": 0
},
"NodeBaseParams": {
"NodeInitialFxParams": {
"bIsOverrideParentFX": 0,
"bitsFXBypass": 0,
"FxList": []
},
"bOverrideAttachmentParams": 0,
"OverrideBusId": 0,
"DirectParentID": 0,
"byBitVector": 0,
"NodeInitialParams": {
"AkPropBundle0": {},
"AkPropBundle1": {}
},
"PositioningParams": {
"uBitsPositioning": 0,
"uBits3d": 0,
"ePathMode": 0,
"TransitionTime": 0,
"VertexList": [],
"PlayListItems": [],
"Params": []
},
"AuxParams": {
"byBitVector": 0,
"auxID0": 0,
"auxID1": 0,
"auxID2": 0,
"auxID3": 0,
"reflectionsAuxBus": 0
},
"AdvSettingsParams": {
"byBitVector": 16,
"eVirtualQueueBehavior": 1,
"u16MaxNumInstance": 0,
"eBelowThresholdBehavior": 1,
"byBitVector2": 4
},
"StateChunk": {
"StateChunks": [],
"StateProps": []
},
"InitialRTPC": {
"RTPCList": []
},
"eGroupType": 0,
"ulGroupID": 0,
"ulDefaultSwitch": 0,
"bIsContinuousValidation": 0
},
"OwnerFile": "wwise\\audio\\simplebnkproject.bnk",
"IndexInFile": 0,
"HasError": false,
"Type": 2,
"Size": 84,
"Id": 3990607256
}
{
"AkBankSourceData": {
"PluginId": 262145,
"PluginId_type": 1,
"PluginId_company": 0,
"StreamType": 0,
"akMediaInformation": {
"SourceId": 378298469,
"uInMemoryMediaSize": 12089,
"uSourceBits": 0
},
"uSize": 0
},
"NodeBaseParams": {
"NodeInitialFxParams": {
"bIsOverrideParentFX": 0,
"bitsFXBypass": 0,
"FxList": []
},
"bOverrideAttachmentParams": 0,
"OverrideBusId": 0,
"DirectParentID": 0,
"byBitVector": 0,
"NodeInitialParams": {
"AkPropBundle0": {},
"AkPropBundle1": {}
},
"PositioningParams": {
"uBitsPositioning": 0,
"uBits3d": 0,
"ePathMode": 0,
"TransitionTime": 0,
"VertexList": [],
"PlayListItems": [],
"Params": []
},
"AuxParams": {
"byBitVector": 0,
"auxID0": 0,
"auxID1": 0,
"auxID2": 0,
"auxID3": 0,
"reflectionsAuxBus": 0
},
"AdvSettingsParams": {
"byBitVector": 16,
"eVirtualQueueBehavior": 1,
"u16MaxNumInstance": 0,
"eBelowThresholdBehavior": 1,
"byBitVector2": 4
},
"StateChunk": {
"StateChunks": [],
"StateProps": []
},
"InitialRTPC": {
"RTPCList": []
},
"eGroupType": 0,
"ulGroupID": 0,
"ulDefaultSwitch": 0,
"bIsContinuousValidation": 0
},
"OwnerFile": "wwise\\audio\\simplebnkproject.bnk",
"IndexInFile": 0,
"HasError": false,
"Type": 2,
"Size": 84,
"Id": 3990607256
}
4 replies
CC#
Created by Ole (ping please) on 8/18/2022 in #help
Getting unexpected result when trying to load resources [Answered]
14 replies