Omnissiah
Omnissiah
CC#
Created by Omnissiah on 6/21/2024 in #help
✅ object composition: a database perspective
composition vs inheritance is abundantly discussed, but there are issues when it gets to store composited objects i can't really seem to find many discussions about this, so maybe this is an unsolved problem (even considering implementation depends on the requisites) or i am trying to do the wrong thing (eventually not too unsurprising) there are discussions about what structure to use for writing trees in databases, but this is kinda a specialized one: it's not really deep, but it can be pretty wide, there can be 5, 10, 20 fields for a single object and some of them, even the most of them, could be collections
class MainObject {
public SomeType1 SomeTypeField1 { get; set; }
2
3
...
public ICollection<AnotherType1> BunchOfData1 { get; set; }
2
3
...
}
class MainObject {
public SomeType1 SomeTypeField1 { get; set; }
2
3
...
public ICollection<AnotherType1> BunchOfData1 { get; set; }
2
3
...
}
so writing every field as a table means a join for everyone, and having a query with 20 joins for an object will never happen there are other options, for example some of those could be owned objects, but this may bring the table to have hundreds of columns, and still would not solve the collections situation one could even think of writing both MainObject and contained data in the same table, or use a table for each, two tables could be better than 20 tables, but then maybe the models can get pretty different between db and business logic, and you always have to translate structure back and forth... i don't know, maybe i'm too worried, maybe there are better dbs than relational ones for this (but tbh a graph db doesn't seem appropriate either) , maybe hard crafting the domains and the queries for a specific case is the only way, but still this would need to have a decent performance and a decent understandabilty, and something is off you could have a (denormalized) field in MainObject to tell which composition has stuff, maybe it could help in sparse matrix cases, but maybe not really; atm using a single table intuitively would seem to work best, because again the issue are the joins
16 replies
CC#
Created by Omnissiah on 2/25/2024 in #help
✅ Reengineering repository layer
I'm trying to bring a code base that was left to me to a more modern architecture. I'm at the point where I need to deal with the repositories because they are becoming a problem. Creating new classes for manipulating data and re-reouting the flow of the code in the current architecture shouldn't be that much of a problem, but I have some difficulties in understading how to organize code for some common operations. What I mean is: currently models have some common logic, let's take auditing for example. When a model is created or updated I need to set who did it and when. Stuff like:
[Serializable]
public abstract class AuditedEntity : OtherAuditing
{
/// <inheritdoc />
public virtual DateTime? LastModificationTime { get; set; }

/// <inheritdoc />
public virtual Guid? LastModifierId { get; set; }
}
public class SomeModel : AuditedEntity { }
public class OtherModel : AuditedEntity { }
[Serializable]
public abstract class AuditedEntity : OtherAuditing
{
/// <inheritdoc />
public virtual DateTime? LastModificationTime { get; set; }

/// <inheritdoc />
public virtual Guid? LastModifierId { get; set; }
}
public class SomeModel : AuditedEntity { }
public class OtherModel : AuditedEntity { }
I would set these fields once per operation (or say unit of work), seems the reasonable thing to do, but what would be a way to do it? The only thing I could think of is having a class with specifically an isolated method for this that I call manually every time I touch a model that is audited. Maybe I could get all the tracked models in the current context from ef and if any inherits from AuditedEntity I update its fields, but that's a little ugly. The other stuff I could come up with would be even uglier. Am I looking at this the wrong way? The solutions I found searching around are either too old or for bigger projects (this is in the 100_000s of lines) and it would be probably too much to maintain,
6 replies
CC#
Created by Omnissiah on 11/30/2023 in #help
✅ how do logging settings work
i'm trying to change logging settings for another issue, but they doesn't seem to be intuitive or really not even to work like the docs say shouldn't this filter almost everything?
{
"Logging": {
"Serilog": {
"IncludeScopes": true
},
"LogLevel": {
"Default": "Warning"
}
},
"Serilog": {
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level:u3}] {Message:lj}{NewLine}{Exception}"
}
}
]
},
}
{
"Logging": {
"Serilog": {
"IncludeScopes": true
},
"LogLevel": {
"Default": "Warning"
}
},
"Serilog": {
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {Level:u3}] {Message:lj}{NewLine}{Exception}"
}
}
]
},
}
instead i see even debug logs there are no other settings (like other appsettings or environment variables) it would be really nice if for once i didn't have to look at the source code to understand how it works
9 replies
CC#
Created by Omnissiah on 1/25/2023 in #help
✅ powershell post MultipartContent weird behavior
simply put, i'm making a request and content is serialized with type name instead of real content
Add-Type -assemblyname System.Net.Http

function Create-Multipart-Settings($section_data) {
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()

$uploadStringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new('form-data')
$uploadStringHeader.Name = "set_params"

$uploadStringContent = [System.Net.Http.StringContent]::new('upload');
$uploadStringContent.Headers.ContentDisposition = $uploadStringHeader;

$multipartContent.Add($uploadStringContent, 'set_params')

$contentStringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new('form-data')
$contentStringHeader.Name = "user_file"

$fileStringContent = [System.Net.Http.StringContent]::new($section_data);
$fileStringContent.Headers.ContentDisposition = $contentStringHeader

$multipartContent.Add($fileStringContent, 'user_file', 'set_params.dat')
return $multipartContent
}

$mc = Create-Multipart-Settings 'data'
$headers = @{}
$headers.Add(...) # authorization stuff
$headers.Add('Content-Type', 'application/x-www-form-urlencoded')
Invoke-WebRequest -Body $mc -Method 'POST' -Uri 'http://...' -headers $headers -TimeoutSec 1800
Add-Type -assemblyname System.Net.Http

function Create-Multipart-Settings($section_data) {
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()

$uploadStringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new('form-data')
$uploadStringHeader.Name = "set_params"

$uploadStringContent = [System.Net.Http.StringContent]::new('upload');
$uploadStringContent.Headers.ContentDisposition = $uploadStringHeader;

$multipartContent.Add($uploadStringContent, 'set_params')

$contentStringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new('form-data')
$contentStringHeader.Name = "user_file"

$fileStringContent = [System.Net.Http.StringContent]::new($section_data);
$fileStringContent.Headers.ContentDisposition = $contentStringHeader

$multipartContent.Add($fileStringContent, 'user_file', 'set_params.dat')
return $multipartContent
}

$mc = Create-Multipart-Settings 'data'
$headers = @{}
$headers.Add(...) # authorization stuff
$headers.Add('Content-Type', 'application/x-www-form-urlencoded')
Invoke-WebRequest -Body $mc -Method 'POST' -Uri 'http://...' -headers $headers -TimeoutSec 1800
with wireshark i see in the request this is sending that content is serialized as System.Net.Http.StringContent System.Net.Http.StringContent and i've got no clue on how to solve this maybe remove everything and just send the body as string powershell is 5.1 on my machine it works™️, on the one i need to execute the script it doesn't edit apparently it doesn't work on my machine either? im pretty sure it used to work
11 replies