|
Put the code for the logic you want to implement (if param, set header) in the controller action you want to implement it in (or intercept it in a middleware/filter component or whatnot). I assume there is some obstacle in this for you in your scenario - where exactly?
|
# ? Jan 2, 2018 15:16 |
|
|
# ? Jun 8, 2024 06:40 |
|
EssOEss posted:Put the code for the logic you want to implement (if param, set header) in the controller action you want to implement it in (or intercept it in a middleware/filter component or whatnot). I assume there is some obstacle in this for you in your scenario - where exactly? Sorry, I should've mentioned this approach in my question. There's no particular obstacle, but this feels like a scenario that might have been supported using the built-in API, and that I just wasn't seeing it. I try to avoid dealing with headers manually whenever possible, but it looks like I'll have to make an exception here. LOOK I AM A TURTLE fucked around with this message at 16:25 on Jan 2, 2018 |
# ? Jan 2, 2018 16:16 |
|
LongSack posted:Yeah, but you have to compose the document with controls like grids, borders, list boxes/views, textblocks, etc., and if you want good looking output you have to do things like keep track of how high each line is so you know where to put the next one. It is drearily time consuming, thus my quest for something that would make it easier. Do they need to look "nice", and include things like auto-width and text wrapping? Or can your reports use monospace font, and fixed width columns?
|
# ? Jan 2, 2018 17:28 |
|
EssOEss posted:I would just fake it with a worker thread - your main code thinks it is some async operation going on but really, all that happens is that a new thread is started and the work done on that thread in parallel. I'm not sure why I couldn't get this to work before I went on the xmas break, but I'm back at work this morning and got it working in no time, so thank you. Here's a simplified example what I did: code:
|
# ? Jan 2, 2018 20:38 |
|
epalm posted:Do they need to look "nice", and include things like auto-width and text wrapping? Or can your reports use monospace font, and fixed width columns? A monospace font would solve a number of problems, but I must confess that it would irritate me looking at pages of Courier New and I'd end up rewriting it anyway.
|
# ? Jan 2, 2018 22:29 |
|
LongSack posted:A monospace font would solve a number of problems, but I must confess that it would irritate me looking at pages of Courier New and I'd end up rewriting it anyway. I suggest using Envy Code R then. Font is gorgeous.
|
# ? Jan 3, 2018 01:46 |
|
Nth Doctor posted:I suggest using Envy Code R then. Font is gorgeous. Fira Code with Ligatures support.
|
# ? Jan 3, 2018 15:12 |
|
So I've been treating F# DUs as Enums because it is very handy. An example: Let's say I have a type of Foo and it has a list of capabilities. I just fill the list with DUs like [canBar;canFoo] and just check if the list contains the DU. This works because of F#s structural comparison, I mean the DUs are different instances right? Is this dumb?
|
# ? Jan 4, 2018 22:21 |
|
Mr Shiny Pants posted:So I've been treating F# DUs as Enums because it is very handy. Yes and no. Empty DU tags (with no objects attached, e.g. the A in type T = A | B of int) get compiled to singletons as an optimization, so in fact they are the same instance, you can check it by explicily calling System.Object.ReferenceEquals(x, y). So technically, A = A would work even if the discriminated unions did not get structural comparison; in the example above, the structural .Equals() implementations are what allows B 0 = B 0 to work. quote:Is this dumb? No, it's totally fine. Argu works like that, for example.
|
# ? Jan 6, 2018 01:04 |
|
NihilCredo posted:Yes and no. Empty DU tags (with no objects attached, e.g. the A in type T = A | B of int) get compiled to singletons as an optimization, so in fact they are the same instance, you can check it by explicily calling System.Object.ReferenceEquals(x, y). So technically, A = A would work even if the discriminated unions did not get structural comparison; in the example above, the structural .Equals() implementations are what allows B 0 = B 0 to work. Thanks man, that is good to know. They work wonderfully for describing stuff. I had an epiphany today, I finally figured out partial application and "Functions as values". I knew about them before, but never had a use for them and the concept never "clicked". Now I needed something and wrote it using functions that are partially applied and sent to a Mailboxprocessor for further execution. I wrote a DU in the style of code:
That was a bit of an eureka moment. BTW you were right about the interfaces, I got it to work but it was too much of a hassle, now I just decorate my MailboxProcessors with lists of DUs to describe their capabilities.
|
# ? Jan 6, 2018 02:15 |
|
Am I correct in assuming that do! reuses the current thread and starts an Async Workflow, while Async.Start fires off a new thread on the threadpool?
|
# ? Jan 7, 2018 10:48 |
|
I'm doing a thing in C# where I want to have a user submit a c# code fragment that I insert into an otherwise mostly blank function, compile, and evaluate. So a user might put in something like int x = 2 + 2; Logger.Write("2 + 2 = {x}"); and I'd want to inject that into the below functionC# code:
Firstly, do I have the right idea? Second, does anyone know of any tutorializing that might help? I flailed around a bit last week and while I got both syntax trees, my attempts to combine them kept failing.
|
# ? Jan 8, 2018 19:28 |
|
Ciaphas posted:I'm doing a thing in C# where I want to have a user submit a c# code fragment that I insert into an otherwise mostly blank function, compile, and evaluate. So a user might put in something like int x = 2 + 2; Logger.Write("2 + 2 = {x}"); and I'd want to inject that into the below function Can we take a step back? What is the requirement that has resulted in the conclusion that this is the best solution?
|
# ? Jan 8, 2018 20:02 |
|
Ciaphas posted:I'm doing a thing in C# where I want to have a user submit a c# code fragment that I insert into an otherwise mostly blank function, compile, and evaluate. The right way to do this would be to use the Roslyn API. Start with the user's code as a string. Ask Roslyn to parse+compile it. Provide a compilation context in which you provide bindings for "input" and "output" and "Logger". code:
|
# ? Jan 8, 2018 20:13 |
|
New Yorp New Yorp posted:Can we take a step back? What is the requirement that has resulted in the conclusion that this is the best solution? Legacy, mostly, along with what I like to term "math poo poo I don't understand at all". Some 30 years ago the more advanced stat analyst customers at the end wanted to be able to write short scripts to make a final modification of their data before it was saved and sent along to the next user/process. It was given to them in PL1 syntax. Some 10 years ago it was updated to use VB through some insane COM shenanigans I don't have any hope of understanding. Flash forward to today, where they're rewriting the entire software package, and one of the requirements is to allow any .NET language script to be used to modify records at various points in processing. ljw1004 posted:The right way to do this would be to use the Roslyn API. Start with the user's code as a string. Ask Roslyn to parse+compile it. Provide a compilation context in which you provide bindings for "input" and "output" and "Logger". Yeah Roslyn stuff is what I was looking at but my examples and code (from memory) look very very different from this. I learned to take a full code string and call CSharpSyntaxTree.ParseText(string) to get a SyntaxTree, then emit that into an Assembly in memory using a MemoryStream, then use reflection to invoke the method in that assembly. This was the first example I followed: Compiling C# Code into Memory and Executing It with Roslyn. The rabbit hole I've been trying to address, after getting that to work, is modifying that syntax tree before compilation, by adding in the user's code. (I realize I could simply modify the code strings and put the user's code in there that way but this seemed the more "correct" way to proceed. Happy to be told I'm wrong, though.) Ciaphas fucked around with this message at 21:18 on Jan 8, 2018 |
# ? Jan 8, 2018 21:13 |
|
Ciaphas posted:Legacy, mostly, along with what I like to term "math poo poo I don't understand at all". Some 30 years ago the more advanced stat analyst customers at the end wanted to be able to write short scripts to make a final modification of their data before it was saved and sent along to the next user/process. It was given to them in PL1 syntax. Some 10 years ago it was updated to use VB through some insane COM shenanigans I don't have any hope of understanding. Flash forward to today, where they're rewriting the entire software package, and one of the requirements is to allow any .NET language script to be used to modify records at various points in processing. Sounds like you want plugins. Have you looked at MEF?
|
# ? Jan 8, 2018 22:30 |
|
Never heard of it, and I'll look into it, but doesn't writing a plugin imply the author having a VS development environment? Because that's never going to happen in this case. (Also another requirement I just remembered is that the software be able to read, automatically update/translate, and run VB scripts written for the old software. Yeah )
|
# ? Jan 8, 2018 22:48 |
|
Actually now I notice there's a Microsoft.CodeAnalysis.CSharp.Scripting nuget package that appears at first blush (no devenv on this machine) to do exactly what I want so lol at me for overthinking things as usual
|
# ? Jan 9, 2018 01:33 |
|
update: i was right and now I'm annoyed at myself for trying to reinvent the wheelCiaphas posted:it's equal parts amusing and frustrating that i've been working on learning roslyn stuff so i could do a C# REPL for like a week--messing with syntax trees, emitting assemblies, reflecting on them, walking aforesaid trees, etc--when i realized yesterday there's a NuGet package that does it in like a dozen lines
|
# ? Jan 10, 2018 01:35 |
|
So I've been stuck maintaining ASP.Net Webforms for 8 years (I know......). Finally got a chance to work with this new hot Core 2.0 MVC and just wanting to make sure I'm not doing anything too crazy/stupid. Does the below sound correct or am I on the wrong track? This is for a login system, and I want to extend the default template for account management. I'm hoping to stick with the boilerplate Identity classes and not roll my own Cookie Authentication. Most of this will be done by UserClaimsPrincipalFactory.GenerateClaimsAsync, and adding additional claims when the user logs in. Password expiry/force change after X days I was going to store a Password_Expiry_UTC as a claim via UserClaimsPrincipalFactory. Then, setup a Authorization Policy or ActionFilterAttribute to check the value of this claim, and if it's expired, redirect the user to the Change Password page. This would enforce password changing across all actions. (rather than just doing after the Login action). The reason I'm thinking filter instead of policy is a filter will let me redirect the user to a change password page, rather than just a generic "Unauthorised" page. IP address whitelisting I was going to implement IP Address whitelisting at a user level (feature requirement). To do this, I was going to store the IP as a claim when they login, and then detect if this every changes in the CookieAuthenticationEvents.OnValidatePrincipal event. If it changes and is still valid, I will re-check against the list of IPs. If it's valid, then call context.ReplacePrincipal. This will update the claim IP and won't log the user out. But if it's invalid, it'll destroy the session and user won't be able to login again. Custom sliding expiration Client wants custom sliding expiration per user (e.g. some will be 30 mins, some 2 weeks). I was going to add an event handler to CookieAuthenticationEvents.onSigningIn and modify the CookieSigningInContext.Propertie.ExpiresUtc property. Is that acceptable? or am i stuffing around with the boilerplate too much? Force relogin every X days Edit - looks like the SecurityStampValidator exposes OnRefreshingPrincipal which would allow me to access both old and new contexts, and copy the AbsoluteExpirationDate claim over. Are there any other instances a principal would get recreated? or is it just on login / security stamp expiry? Two factor The latest starter template has done away with the old SMS two factor code and are trying to push the Authenticator app. Client requires SMS though, not app. I have just copied from the ASP.Net MVC (classic, not core) template which still uses GenerateTwoFactorTokenAsync to send via SMS, and then TwoFactorSignInAsync to log them in. The old SendCode/VerifyCode actions from the last template. Is this still acceptable? Claim storage So my understanding is all claims are serialised to a cookie, encrypted, and stored client side? They're then decrypted on each request and then converted to a ClaimsPrincipal. (The magic of the CookieAuthentiation middleware). This is secure, right? There's no chance a client can view or change their claims? Is there any other best practice instead? (i.e. send a "Session ID" for the cookie, and persist the claims server side via redis cache or similar) Context usage and DI I'm still stuck in the webforms mindset of wrapping all DB context operations in a single Using block. But now the new hotness is to have one context per request via DI? So in my model I have the standard ApplicationUser. But I've extended this and added other entities (i.e. organisation) These other entities are not eagerly loaded, and EF doesn't do lazy loading - what is the best way to load them? I have registered a ApplicationDbContext (which the UserManager and SigninManager uses). Am I okay to just grab this context via DI, and call context.Entry.Load? Or is there a risk these Managers might be using a different instance of the context? Final edit - Security Stamp Validation interval This system is going to be very low usage. So I was thinking of setting the validation interval to something low like 30 seconds or 1 minute. This way if a user changes a password on another PC, other sessions will be invalidated. But I can also use it to update the security stamp when I add/remove IPs to the whitelist, change the re-login interval, change the sliding expiry interval, etc. Is that usable for a low-usage site, or is there a lot of overhead in regenerating a validating a security stamp, or regenerating a claims identity? Thanks for the sanity check! roflsaurus fucked around with this message at 08:40 on Jan 10, 2018 |
# ? Jan 10, 2018 08:14 |
|
quote:Claim storage This depends on how you have it configured. You could have a reference token stored in a cookie which then calls to an IDP to retrieve claims on every request.
|
# ? Jan 10, 2018 10:55 |
|
I think I’m missing something with EF. I have a Title class which has a foreign key into the Genres table, so the the Title class has a navigation property of type Genre. If I add a new Title, and then without disposing the context, try to delete it I get an exception “Adding a relationship with an entity which is in the Deleted State is not allowed”. If I exit the “Titles” window and come back I can delete it without a problem, so it seems like I’m missing something creating the new entity. The only reliable fix I’ve found is - after adding the new title - to Dispose the context, create a new one, and to reload my ObservableCollection<Title>. This seems horribly inefficient. I have verified that after the SaveChanges() call the Genre navigation property is set correctly, so I’m not sure what’s going on. For reference, the classes look like this (I’ve left out a bunch of extraneous stuff, for example all of the properties are observable, but that doesn’t seem relevant): C# code:
|
# ? Jan 11, 2018 03:36 |
|
LongSack posted:I think I’m missing something with EF. I have a Title class which has a foreign key into the Genres table, so the the Title class has a navigation property of type Genre. Hrmm, I would always create a new context for a new operation, but you seem to have a different problem. You shouldn't need to reload everything, you have it already, just add the new entry to the Observable when SaveChanges is successful, dispose the context. If you need to delete, create a new context and on success, remove it from the Observable. You need decouple your Observable from the DBContext. your ViewModel should probably be a simple POCO, not an EF Entity. This should also make it easy to test
|
# ? Jan 11, 2018 10:57 |
|
Mr Shiny Pants posted:Am I correct in assuming that do! reuses the current thread and starts an Async Workflow, while Async.Start fires off a new thread on the threadpool? I'm not sure about the threading behaviour (which is mostly an implementation detail - the main time it matters is when doing GUI programming, and for that specific case you have `Async.StartImmediate` which exists to force the async operation to run on the GUI thread), but a much bigger difference between the two is that do! waits for the operation to complete before continuing the expression, while Async.Start does not. E.g. https://dotnetfiddle.net/lwaW2R code:
code:
NihilCredo fucked around with this message at 16:03 on Jan 11, 2018 |
# ? Jan 11, 2018 15:29 |
|
NihilCredo posted:I'm not sure about the threading behaviour (which is mostly an implementation detail - the main time it matters is when doing GUI programming, and for that specific case you have `Async.StartImmediate` which exists to force the async operation to run on the GUI thread), but a much bigger difference between the two is that do! waits for the operation to complete before continuing the expression This is what I was seeing, I thought Async.Start kicked it off on another thread, but it does not wait and do! does. Thanks for the clarification.
|
# ? Jan 11, 2018 17:28 |
|
Funking Giblet posted:Hrmm, I would always create a new context for a new operation, but you seem to have a different problem. You shouldn't need to reload everything, you have it already, just add the new entry to the Observable when SaveChanges is successful, dispose the context. If you need to delete, create a new context and on success, remove it from the Observable. You need decouple your Observable from the DBContext. your ViewModel should probably be a simple POCO, not an EF Entity. This should also make it easy to test My VMs are separate from the EF entities. I tried just disposing and recreating the context after SaveChanges(), but then got a different error message: "The object cannot be deleted because it was not found in the ObjectStateManager". That error is corrected by re-loading the ObservableCollection. I don't have any problems with entities that consist only of scalar properties, only on ones with navigation properties. Here is one of the simplest ViewModels, used for managing Genders (i hope ~150 lines isn't too long). Note that the Gender class is the EF entity for the Genders table: C# code:
|
# ? Jan 11, 2018 19:46 |
|
Ok, this is what I was talking about, your view model is capturing a context, this is not correct at all and is going to cause a lot of issues (as it is already). You are also relying on a destructor to dispose your context, this may never be called. Let's try something small to give you an idea of how first to fix this. In each of your methods, create a new context. code:
Remove the _context variable. Figure out a different way to Populate your observable, and maybe, try not using an EF entity, but a DTO of some sort. This is not the way to do it, but should show some improvements, and show you the way a context should be used (short lived as possible) (I haven't much time now, but we can drill into a proper method of doing it)
|
# ? Jan 12, 2018 13:23 |
|
Funking Giblet posted:stuff OK i'll play around with it, also thanks for the note about the destructor - i was not aware that they might not be called. Edit: it seems to work well even using the Entity classes in my observables as long as i do something like this: C# code:
LongSack fucked around with this message at 21:41 on Jan 12, 2018 |
# ? Jan 12, 2018 19:38 |
|
This is probably a dumb question, but I'm pretty new to mvc\web work in general, and there is something I don't quite get. I'm using a devexpress extension, their gridview. It supports paging, so I bind it to a list of a 1000 records and it happily pages them out for me. I also have to give it a callback actionresult. Now, in all the tutorials and samples they just bind it to something on the model like 'model.GetEmployees()' and the callback also returns model.GetEmployees(); Is that actually happening the way it looks like it's happening or is there some smarter logic? Like, when I click the page 2 link, is the controller pulling the same 1000 records again and sending them back to the view or is there some sort of logic I'm not seeing that's only checking for new records or something? https://documentation.devexpress.com/AspNet/8998/ASP-NET-MVC-Extensions/Grid-View/Overview/Overview-GridView <--control in question
|
# ? Jan 12, 2018 19:40 |
|
Has anybody used Npgsql's LISTEN/NOTIFY support? Am I supposed to only be able to handle notifications raised from the same connection? Because that cripples the feature, at least the way I wanted to use it (I had planned on having a background worker that did things whenever a row was added to a particular table, regardless of who or what added those rows). But the event doesn't seem to fire except when I manually call NOTIFY from the same connection where I called LISTEN.
|
# ? Jan 12, 2018 20:13 |
|
NihilCredo posted:Has anybody used Npgsql's LISTEN/NOTIFY support? No, you can use a different connection, just keep one open that will listen for events. This worked for me: code:
The last part is broken I think, but you should send a keep alive to the server once in awhile. Mr Shiny Pants fucked around with this message at 21:12 on Jan 12, 2018 |
# ? Jan 12, 2018 21:05 |
|
Thanks. Turns out the problem was dead-simple, as usual: channel names are case sensitive. For the 'keep connection alive' requirement, I just enabled the KeepAlive option in the connection string, seems to work.
|
# ? Jan 12, 2018 22:52 |
|
NihilCredo posted:Thanks. Turns out the problem was dead-simple, as usual: channel names are case sensitive. Ah, Unix DB server of course. There was some talk on the Npgsql github about the keepalive not working as it should when set in the connection string, maybe something to keep in mind. Question for you, is Async Sleep with an Infinite timeout dumb to keep a thread running? I have a websocket server which I need to keep running and a client also.
|
# ? Jan 12, 2018 22:57 |
|
Mr Shiny Pants posted:Ah, Unix DB server of course. I'd look for a cleaner solution, to be honest. Whatever library you're using for websockets, if it doesn't totally suck, should provide an async method call to fetch the next message, so just await that. Kinda like an inbox.Receive when using a mailbox processor. Or if you're balling hard and writing your own server, you could check out Suaves' implementation for ideas.
|
# ? Jan 13, 2018 00:34 |
|
LongSack posted:OK i'll play around with it, also thanks for the note about the destructor - i was not aware that they might not be called. C# doesn't have destructors, it has finalizers. If you need deterministic disposal of unmanaged resources, use the IDisposable interface and wrap things in using blocks.
|
# ? Jan 13, 2018 05:45 |
|
NihilCredo posted:I'd look for a cleaner solution, to be honest. Whatever library you're using for websockets, if it doesn't totally suck, should provide an async method call to fetch the next message, so just await that. Kinda like an inbox.Receive when using a mailbox processor. I am using socketsharp, I'll take a look at Suave. Thanks.
|
# ? Jan 13, 2018 09:25 |
|
Maybe you guys know this, I haven't found a definitive answer. The Windows 10 IoT stuff has speech recognition, does this one need a network connection? I don't want Cortana or any other cloud based stuff, just the regular Microsoft.Speech namespace would suffice.
|
# ? Jan 13, 2018 16:15 |
|
So I just installed, what I think was a Netstandard library from Nuget, and it installed a whole shitload of stuff. System.IO and other stuff. Why would it need those when I am using the full runtime?
|
# ? Jan 14, 2018 20:02 |
|
The reality of modern .NET packaging is a shitshow with many complications and design flaws. Every time I think I understand it and try to apply my knowledge, I find yet another stupid way for it to break. I think those packages are mostly empty or just have placeholder assemblies if you just target the full framework but I am not even sure. Would love to read a thorough explanation but I have never seen one that manages to cover even a decent portion of the angles. What exactly was the package in question? Let's explore the data.
|
# ? Jan 14, 2018 21:24 |
|
|
# ? Jun 8, 2024 06:40 |
|
EssOEss posted:The reality of modern .NET packaging is a shitshow with many complications and design flaws. Every time I think I understand it and try to apply my knowledge, I find yet another stupid way for it to break. I think those packages are mostly empty or just have placeholder assemblies if you just target the full framework but I am not even sure. Would love to read a thorough explanation but I have never seen one that manages to cover even a decent portion of the angles. Well, I got it figured out, I had to set the dependency resolution in Nuget to "Ignore dependencies"..... yeah. It works though. It is this one: https://github.com/Q42/Q42.HueApi Edit: Seems like someone else was wondering the same: https://github.com/Q42/Q42.HueApi/issues/123 It looks like something from 1.0 netstandard what I gathered from SO link, should be fixed in 2.0. I am really not starting to like the fragmentation....... Edit 2: Now FSI works again with the DLL, it would error out because some System.Threading library would be missing if it installed all the dependencies. Yay. Mr Shiny Pants fucked around with this message at 22:34 on Jan 14, 2018 |
# ? Jan 14, 2018 22:10 |