Tandy
Tandy
Explore posts from servers
DTDrizzle Team
Created by Tandy on 10/24/2024 in #help
Change drizzle connection string at runtime
I have an existing drizzle instance that's exported from a module that many other modules import. I'd like to modify that instance at runtime to change the connection string. I thought maybe I could set the $client like so:
db.$client = new Pool({
connectionString: createConnectionString({
user: inject('DATABASE_USER'),
password: inject('DATABASE_PASSWORD'),
host: inject('DATABASE_HOST'),
port: inject('DATABASE_PORT'),
database: databaseName,
})
})

await db.$client.connect()
db.$client = new Pool({
connectionString: createConnectionString({
user: inject('DATABASE_USER'),
password: inject('DATABASE_PASSWORD'),
host: inject('DATABASE_HOST'),
port: inject('DATABASE_PORT'),
database: databaseName,
})
})

await db.$client.connect()
But it just hangs.. I know this seems odd but I need to be able to swap out the db connection for each integration test.. I don't know how to accomplish that without actually modifying the singleton db connection
1 replies
CC#
Created by Tandy on 7/9/2024 in #help
Regex negative lookahead not working
I am trying to use regular expressions to detect URLs in dynamic text (I know). I have a pretty good working example, but I'm struggling to filter out certain HTML codes that could be present in the dynamic text. For example, the current regex is capturing google.com&#160 as the URL for the following text: visit us at google.com for more information. I'd like to prevent that and only match on google.com. I tried to add a negative lookahead to remove matches on &#160, but it's not working. Can anyone help? https://regex101.com/r/WJ6y2x/2
5 replies
CC#
Created by Tandy on 6/27/2024 in #help
Fill in missing dates in list?
For simplicity, suppose I have a list of nullable dates, and I need to reverse engineer the dates that are missing. The tricky thing is that it's not simply filling in between the first date and the last date, but the data can be monthly, quarterly, etc, and so the list of dates is not consistent. so something like [2022-10-03, null, null, 2022-12-31, null, null, 2023-03-31] should be filled in with monthly data like [2022-10-03, 2022-10-31, 2022-11-30, 2022-12-30, 2023-01-31, 2023-02-28, 2023-03-31] but there could be cases where the first few items in the array are empty, or the gaps between data is smaller, etc. I don't need an answer just need a nudge in the right direction. There's currently a solution in place for this but it's difficult to follow and there are a few bugs that would probably be fixed by an alternative, more robust solution
3 replies
CC#
Created by Tandy on 2/6/2024 in #help
Convert EPS file to SVG?
Is there a way to convert EPS to SVG using dotnet 8? I've found references to inkscape, which requires some server dependencies. I'm open to that, but wondering if there are any simpler solutions that I'm overlooking?
5 replies
CC#
Created by Tandy on 1/2/2024 in #help
Validate PDF Accessibility via dotnet?
Are there any dotnet libraries or tools to validate a PDF file for accessibility compliance (WCAG)? Alternatively, is there a tool outside the dotnet ecosystem that you've used? Given a PDF, I need to create a list of accessibility issues (color contrast, tags missing, etc). Ideally, it would be MIT or other permissive license, but also open to paid options
2 replies
CC#
Created by Tandy on 5/30/2023 in #help
❔ WYSIWYG model storage - hierarchy table(s) vs JSON column
Using EF + SQL Server, I need to support saving a Template which consists of Pages and Elements maintained via a WYSIWYG editor. Element is an abstract class with derived classes like Section (which corresponds to a div), Text, Image, and Chart, each with their own unique properties. A Section can contain another Section, for example, so the data model needs to be hierarchical. Initially, I considered using a hierarchy table where an Element had an optional parent - public abstract class Element { public int? ParentElementId { get; set; }. It's easy enough to query and hydrate into a read model suitable for consumption, but my assumption is that it would be rather complex to persist changes for the whole disconnected graph since users can add/remove pages, add/remove elements, move an element from one section to another (even across pages), update all style properties of a given element, etc. I was considering using a JSON column for the whole hierarchy instead since it's very unlikely we'll need to query any of that info (and we can use SQL Server JSON support if absolutely necessary) and it would be incredibly easy to save the whole hierarchy, just re-assign a single variable to the hierarchy constructed from the WYSIWYG editor. I've considered the performance/storage implications of JSON, and the discipline required to maintain a backward compatible model (since we'd be giving up migrations in favor of JSON). I'm fine with both of those tradeoffs. Is there anything I'm overlooking? Anything about working with that disconnected graph with EF Core that could make a relational model easier? Has anyone solved this problem before with JSON columns?
7 replies
CC#
Created by Tandy on 5/4/2023 in #help
❔ Multi-tenancy - database per tenant - which database(s) to store Users?
We're using Auth0 for authentication. A given User could have access to multiple tenants. I'm envisioning a Catalog database with Tenants table and Users table, as well as a UserTenants table that links the two. However, I imagine that the tenant databases will require user information, like first name, last name, email, etc, for business logic. So does it make sense to have a Users table in both the Catalog database but also in each tenant database?
15 replies
CC#
Created by Tandy on 4/19/2023 in #help
❔ Playwright dotnet - Duplicate 'Content' items were included.
A colleague has installed Playwright dotnet in our dotnet API project and now Omnisharp is throwing the following error (and failing to provide any intellisense in the whole solution):
Duplicate 'Content' items were included. The .NET SDK includes 'Content' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultContentItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: '/Users/me/.nuget/packages/microsoft.playwright/1.32.0/buildTransitive/../.playwright/node/LICENSE'
I may be dense, but from the options provided, it's not clear what exact csproj changes I should be making. It seems like I need to exclude any content provided from Playwright, but it's not clear how to do that, especially considering this Nuget package is outside the context of my project. Any suggestions?
4 replies
CC#
Created by Tandy on 11/28/2022 in #help
❔ Troubleshooting large ASP NET Core cookie?
2 replies
CC#
Created by Tandy on 11/28/2022 in #help
❔ Does BlockingCollection TryTake free the consuming thread to do other things?
I'm not too knowledgeable about multi-threading. But I'm trying to use BlockingCollection.TryTake to consume messages like so:
Task.Run(async () =>
{
while (!_queue.IsCompleted)
{
_queue.TryTake(out var command, Timeout.Infinite);
}
});
Task.Run(async () =>
{
while (!_queue.IsCompleted)
{
_queue.TryTake(out var command, Timeout.Infinite);
}
});
While _queue.TryTake is waiting for an item - is it occupying the thread such that other API functions will be impacted? My fear is that I have to create n number of these collections. If each one is permanently blocking a thread, then the server will run out of resources. But if the thread is freed to do other things - like process incoming HTTP requests - before being signaled then I should be safe. The documentation is a little confusing, but I'm hopeful that the "blocked thread" is free to do other work:
The thread is then free to do some other useful work before trying again to access the collection.
https://learn.microsoft.com/en-us/dotnet/standard/collections/thread-safe/blockingcollection-overview#timed-blocking-operations
2 replies
CC#
Created by Tandy on 11/12/2022 in #help
❔ How to pause BlockingCollection consumption?
I'm currently enumerating through a BlockingCollection (with an underlying ConcurrentQueue backing class) using GetConsumingEnumerable(). But I have to pause execution based on some logic, leaving items on the queue, until some other business logic resumes execution. Anyone know the best practice for that? Do I have to bypass GetConsumingEnumerable() and instead write something like below, but adding pause logic?
while (!IsCompleted)
{
if (TryTake(out var item, Timeout.Infinite))
yield return item;
}
while (!IsCompleted)
{
if (TryTake(out var item, Timeout.Infinite))
yield return item;
}
3 replies
CC#
Created by Tandy on 8/28/2022 in #help
Remote robot state and commands - best patterns, practices?
I have a use case where I'm able to remotely control a robot via a SPA frontend and dotnet API + robot API. The UI can dispatch actions like undock, dock, power off, sit, stand, move, rotate (with joysticks). But commands require state and state transitions to occur before they're valid. The UI should be aware of these state transitions so buttons can be disabled, the user can be notified that something is happening, etc. I can access the robot state by polling an API or I can embed C# code on the robot that runs every tick and pushes updates to our API when things change. I was considering putting a singleton class which holds the current state and owns state transitions using state pattern on the robot C# payload. Then all our API calls would go through that class, which would then broadcast events back to our API when things changed. But I have almost no experience in this domain. Is there some framework or design pattern that's standard for this pattern? Just some things to Google is fine if anyone knows!
1 replies