|
RICHUNCLEPENNYBAGS posted:Yeah but the XML schema is stupid as hell if you actually look at files. And really really complicated. My colleague tried to create documents using Word ML. drat..... He got it working in the end but it feels really over-engineered.
|
# ? Oct 31, 2014 12:14 |
|
|
# ? May 15, 2024 20:51 |
|
Mr Shiny Pants posted:And really really complicated. My colleague tried to create documents using Word ML. drat..... He got it working in the end but it feels really over-engineered. That's still probably easier than trying to read arbitrary Word files. Ugh. The worst part of it is mail merge stuff is mostly just text and not part of the XML schema and can even end up being split by the various tags (I mean besides the field code markers, which are always an XML element unto themselves). I'm sure the stuff other than Word is even more of a nightmare though.
|
# ? Oct 31, 2014 12:21 |
|
I want to try out some C# code parsing/manipulation/generation and I'm trying to decide between using NRefactory or Roslyn. They both seem to largely lack documentation at the moment (or maybe I'm looking in the wrong places?), plus Roslyn's API seems to be in a flux so most examples I can find no longer work, and its pre-release license is kind of weird and restrictive. On the other hand it's supported by Microsoft so it's likely going to be more complete and stable once it's out. Any thoughts?
|
# ? Oct 31, 2014 12:27 |
|
Forgall posted:I want to try out some C# code parsing/manipulation/generation and I'm trying to decide between using NRefactory or Roslyn. They both seem to largely lack documentation at the moment (or maybe I'm looking in the wrong places?), plus Roslyn's API seems to be in a flux so most examples I can find no longer work, and its pre-release license is kind of weird and restrictive. On the other hand it's supported by Microsoft so it's likely going to be more complete and stable once it's out. Any thoughts? Well, depends what your horizon is like but I imagine Roslyn will end up with more robust support. There are a number of other techniques you can use for metaprogramming (reflection is obvious, but also dynamic proxies, IL emission, LINQ expressions, etc.).
|
# ? Oct 31, 2014 12:47 |
|
idontcare posted:Regardless if it's a terrible idea or not, I need to do it. Is it possible? It is a terrible idea. But users authenticated via basic auth do appear in a http header and you should be able to do url rewrites based on that. But this is loving retarded and you are probably solving a problem in an rear end-backwards way.
|
# ? Oct 31, 2014 15:17 |
|
Bognar posted:You might be able to do it with a custom HTTP handler. However, can you explain why you need to it? So we license software from another company and the license expires at the end of the year. It generates an XML feed that we use to provide content to our clients. We wrote a new system that will take the place of this software and generates an identical XML feed. Our clients use importers that access the feed and pull in the content. The importers are all pointing at the servers with the old software on it. I have access to the servers, I don't have access to the code. The url of the client's feeds are in the form http://username:pass(at)ourserver.com/folder. There are no unique identifiers in the url other than the username/pass. The username/pass are keys generated by the old system that I have access to and won't change and the client's aren't able to change. My boss wants to slowly transition clients from the old system to our new system, and wants to do it one client at a time. He wants the transition to be smooth and not have the client's need to do anything on their end. What I posted about before - redirecting the request to http://username:pass to http://username:pass based on username - was the proposed solution to the problem. It's a temporary solution so not all client's are switched over at once. sausage king of Chicago fucked around with this message at 16:02 on Oct 31, 2014 |
# ? Oct 31, 2014 15:58 |
|
Ok, still a bit of a retarded architecture but you should be able to do url rewrites based on the HTTP_REMOTE_USER server variable (that you should not be trusting). Perhaps a better way would be to send everyone to the new URL and then have that redirect folks to the old or new system based on some data lookups -- maintaining that url rewrite file will be a bitch.
|
# ? Oct 31, 2014 18:54 |
|
Mr Shiny Pants posted:Reading it back I don't know what I meant This stuff is all new to me. F# will cache the values of functions with no parameters. That's the closest thing I can think of to what you might be talking about. I don't know what "a let binding executes all the functions that comprise it during execution without needing to be called explicitly in program flow" means.
|
# ? Oct 31, 2014 19:01 |
|
wwb posted:Ok, still a bit of a retarded architecture but you should be able to do url rewrites based on the HTTP_REMOTE_USER server variable (that you should not be trusting). Nice, that's a good idea that I hadn't thought of. I'll bring it up. Thanks a lot.
|
# ? Oct 31, 2014 19:06 |
|
GrumpyDoctor posted:F# will cache the values of functions with no parameters. That's the closest thing I can think of to what you might be talking about. I don't know what "a let binding executes all the functions that comprise it during execution without needing to be called explicitly in program flow" means. That is what I meant. I am used to instantiating classes and the like with C# before you can use them. F# will evaluate let bindings and instantiate stuff during program start. Just a different way of programming I guess. At least for me, a different way of thinking about things. Thanks for clearing up the caching.
|
# ? Nov 2, 2014 22:04 |
|
Mr Shiny Pants posted:That is what I meant. I am used to instantiating classes and the like with C# before you can use them. F# will evaluate let bindings and instantiate stuff during program start. Just a different way of programming I guess. Well, I still really don't have any idea what you're talking about, but I guess it's working for you.
|
# ? Nov 2, 2014 23:07 |
|
Mr Shiny Pants posted:That is what I meant. I am used to instantiating classes and the like with C# before you can use them. F# will evaluate let bindings and instantiate stuff during program start. Just a different way of programming I guess. That sounds kind of odd... CLASSES code:
GLOBALS code:
It's good that you have a new way of thinking about program structure. Just be aware that this style of program structure is equally well achievable in both C#/VB and F#.
|
# ? Nov 2, 2014 23:30 |
|
GrumpyDoctor posted:Well, I still really don't have any idea what you're talking about, but I guess it's working for you. Nevermind, I guess I suck at explaining. The Access Violation cleared itself up BTW. No clue why. Mr Shiny Pants fucked around with this message at 06:39 on Nov 3, 2014 |
# ? Nov 3, 2014 06:29 |
|
Honestly I'm mostly just interested in seeing the good parts of F# make it to C#-- pattern matching, discriminated unions and all that jazz.
|
# ? Nov 3, 2014 06:40 |
|
Here I am patiently waiting for a connection to my HttpListener:C# code:
C# code:
code:
|
# ? Nov 3, 2014 23:18 |
|
GrumpyDoctor posted:Here I am patiently waiting for a connection to my HttpListener: You're not running this in a console project are you? I've forgotten to Console.Readkey or whatever before when awaiting in a quick POC project and seen similar results.
|
# ? Nov 4, 2014 02:26 |
|
GrumpyDoctor posted:Here I am patiently waiting for a connection to my HttpListener: var conn = await httpListener.GetContextAsync(); I don't understand. What you wrote seems fine. What actually is the problem? Is it that you don't want someone to shut the listener down? (if so you'll have to figure out why the Stop routine is being called and no one here can help you...)
|
# ? Nov 4, 2014 07:22 |
|
kingcrimbud posted:You're not running this in a console project are you? I've forgotten to Console.Readkey or whatever before when awaiting in a quick POC project and seen similar results. Nope. ljw1004 posted:I don't understand. What you wrote seems fine. What actually is the problem? Is it that you don't want someone to shut the listener down? (if so you'll have to figure out why the Stop routine is being called and no one here can help you...) Is there really no way to shut a listener down without having it throw an exception?
|
# ? Nov 4, 2014 07:45 |
|
Shutting it down without throwing an exception would be very bad design - you are using an object that has been shut down in the middle of an operation! This is most definitely an exceptional situation. Everything is as it should be. I do understand that the code using HttpListener might find such situations uncomfrotable to handle. If this causes issues in your business logic, I recommend you ensure that all asynchronous work is complete before shutting it down. This may require you to implement custom synchronization logic. If anything is wrong in this picture, it is the fact that you are shutting down something you are still using.
|
# ? Nov 4, 2014 10:49 |
|
GrumpyDoctor posted:Nope. Nope, not that one. I've run into the same issue. The guys from Nancy seem to have fixed it, might want to check their code.
|
# ? Nov 4, 2014 16:32 |
|
GrumpyDoctor posted:Is there really no way to shut a listener down without having it throw an exception? You could call Stop(), wait for the current requests to complete, then call Close(). Inevitably, though, you will want to Close() after a certain amount of time anyway (if a request takes too long to complete) and an exception will be thrown regardless.
|
# ? Nov 4, 2014 16:41 |
|
EssOEss posted:Shutting it down without throwing an exception would be very bad design - you are using an object that has been shut down in the middle of an operation! This is most definitely an exceptional situation. Everything is as it should be. There's no work to complete. The listener is idle. Bognar posted:You could call Stop(), wait for the current requests to complete, then call Close(). Inevitably, though, you will want to Close() after a certain amount of time anyway (if a request takes too long to complete) and an exception will be thrown regardless. There are no current requests. I can understand that tearing down a listener that's actually connected to something is exceptional, but this one is just sitting there waiting. The reason I'm confused about this is that it seems like I can do what I want in F# (this code is not useful for anything other than illustrating what I don't get): code:
raminasi fucked around with this message at 17:49 on Nov 4, 2014 |
# ? Nov 4, 2014 17:45 |
|
I am not terribly knowledgeable in F#, but isn't Async.Start similar to Task.Run in that the work is being queued on the threadpool? If an exception is thrown in that case, you wouldn't be able to catch it anywhere. After a bit more research it seems that, yes, any call to GetContext() that is blocking (or awaiting GetContextAsync()) will unavoidably throw an exception on Stop() or Close().
|
# ? Nov 4, 2014 19:02 |
|
Waiting for an async call to complete *is* work that it is doing. Ideally, I would expect there to at least be some CancellationToken given to the HttpListener so you can instruct it to cancel the ongoing operation before stopping it. However, it seems that the API is not that nice - it really seems to be designed to be used strictly from one thread (even if it is thread-safe).
|
# ? Nov 4, 2014 20:28 |
|
Anyone know the best configuration approach to have both windows authentication for an MVC5 intranet project but also allow anonymous requests for web api calls in the same app?
|
# ? Nov 5, 2014 00:37 |
|
Withnail posted:Anyone know the best configuration approach to have both windows authentication for an MVC5 intranet project but also allow anonymous requests for web api calls in the same app? Currently, MVC and Web API have different setup methods (look at Global.asax.cs), so you should be able to apply a global MVC filter in FilterConfig, but not require that in Web API (which is in WebApiConfig). Alternately, you could just add the [AllowAnonymous] attribute to all of your Web API controllers. Although, my XY spidey sense is tingling. Why don't you want the API calls authenticated?
|
# ? Nov 5, 2014 02:27 |
|
GrumpyDoctor posted:The reason I'm confused about this is that it seems like I can do what I want in F# (this code is not useful for anything other than illustrating what I don't get): Is your debugger set to catch first-chance exceptions or merely unhandled exceptions? I've not used Async.Start, but from my reading of the docs it merely kicks off an async workflow without actually awaiting for the result. So it's possible that the F# code is getting the same exceptions but they're just being ignored... The design you have (with a method called "Stop()") isn't great. Cancellation tokens are always better. That's me passing on the considered conclusion of a lot of async experts Now it's true that there are a bunch of APIs which don't take cancellation tokens. That's a shame, but one that we can do something about. I wrote here http://blogs.msdn.com/b/lucian/archive/2012/12/08/await-httpclient-getstringasync-and-cancellation.aspx about another case very similar to yours - the HttpResponse.Content.ReadAsStringAsync() method doesn't accept a cancellation token, so you have to explicitly call a Stop method (actually in this case a Dispose method) and it throws an exception. quote:Again, I expected to be missing something major somewhere, but I did not expect that "Stopping an idle listener is considered exceptional" was it. Under that logic, every call to HttpListener.Stop() will throw an exception somewhere, right? Note that in .NET the pattern is that cancellation throws an exception (OperationCancelledException). So please don't feel too squeamish about having cancellation exposed as an exception! Some people will reasonably argue that "await httpListener.GetContextAsync()" should return NULL if the httpListener has already been stopped. Others will reasonably argue that it should throw an exception. Both behaviors will be fairly surprising the first time you see them but at least the exception is more informative!
|
# ? Nov 5, 2014 07:30 |
|
Quick question about cancellation tokens I hope. How do they work? I understand that you pass them to some Async job and you cancel them with CancellationToken.Cancel(). If I have multiple jobs, do I create multiple and pass them in one per job? If yes, do I need to do the bookkeeping myself of which token belongs to which job? I haven't found a satisfactory answer to this, all examples are with one job and one token.
|
# ? Nov 6, 2014 21:46 |
|
CancellationToken is basically a wrapper around a boolean. You can use the CancellationTokenSource to create a CancellationToken and cancel that token. APIs that accept a CancellationToken are expected to check the token to see whether the operation is canceled before starting or continuing the operation. For example, check out the code for Stream's ReadAsync method that takes a CancellationToken: http://referencesource.microsoft.com/#mscorlib/system/io/stream.cs,417 It checks cancellationToken.IsCancellationRequested and exits if it's true (by calling Task.FromCancellation). Do you want to cancel multiple tasks as part of one step? Use the same token. Do you want to cancel multiple tasks separately? Use different tokens. EDIT: Note that there is some additional magic that implementations can do to register callbacks when the token is canceled, but for now pay no attention to the man behind the curtain. Bognar fucked around with this message at 22:32 on Nov 6, 2014 |
# ? Nov 6, 2014 22:29 |
|
Ok, let's say I have a server that has multiple tasks in flight. I create a new cancellationsource for the tasks I spin up. These might be different tasks. Do I create a cancellationsource per Task? Or does cancellationsource.token create a new one each time it is called? Do I put all these tokens in an array so I know what tasks are in flight and in the event of a shutdown I need to signal to cancel?
|
# ? Nov 6, 2014 22:36 |
|
Treat each CancellationTokenSource as one "logical" cancellation action. Depending on how you want to cancel all of your tasks, you might have one or many CancellationTokenSources. If you want to cancel them all at once, you can use one source. If you want to cancel different tasks at different times, use different sources. It really depends on how you want to do it. Calling CancellationTokenSource.Token returns a new token each time, however each CancellationToken has a reference to its CancellationTokenSource (where you call Cancel) so you can treat them as effectively the same. Checking if a CancellationToken is canceled simply defers to checking if its source is canceled. Regarding knowing what tasks are executing, you should know that the CancellationToken can outlast the tasks that run on it and are no indication of whether a task is running - only if it was told to be canceled or not. If you want to keep track of tasks, just hold onto the Task objects themselves.
|
# ? Nov 6, 2014 22:58 |
|
Thanks, much appreciated.
|
# ? Nov 6, 2014 23:01 |
|
That word document analyzer I was talking about before is done. I was having this weird issue where comments would be out of order if I tried to look into tables. I tried a bunch of different approaches, but they'd always wind up out of order. In exasperation I looked in the .xml file for comments and noticed every comment had an ID of 0. No wonder. Thing is, I didn't write the code that was handling finding the next comment id to use. I copied it from here: http://msdn.microsoft.com/en-us/library/office/cc850832%28v=office.15%29.aspx The offending bit appears to be this: code:
|
# ? Nov 7, 2014 00:44 |
|
Mr Shiny Pants posted:Thanks, much appreciated. You should also be aware of CancellationTokenSource.CreateLinkedTokenSource Scenario: you have one main CancellationTokenSource that is the one that will be fired when the user hits the Cancel button. Then you want to start a subsidiary task with its own timeout. So you do code:
I might also have done code:
Note: the difference between CancellationTokenSource and CancellationToken? the first is how you can send a request to cancel; the latter only has the power to listen for such requests.
|
# ? Nov 7, 2014 01:39 |
|
If you look at the comments collection in the debugger, do they have the right IDs? The code, from my understanding, should work.
|
# ? Nov 7, 2014 09:04 |
|
ljw1004 posted:You should also be aware of CancellationTokenSource.CreateLinkedTokenSource Thanks for the detailed explanation. One remark: Should this: code:
code:
|
# ? Nov 7, 2014 09:15 |
|
The "help file" that ships with our software is a directory containing html files, which comes from an MS Word document -> Save As Web Page Part of the reason why our documentation isn't great is because one guy here "owns" that word document. It would be way better if it was public (within the company), and a group of people could edit it, and it would have edit versioning, and so on. Sounds like a wiki to me. IIS is a dependency of our software, so I'm looking into .NET wikis and CMSs. Anyone have any suggestions? Something like http://userguide.tomecms.org/ looks like it might fit the bill, but I have no idea what's "good". How do you provide Documentation / User Guides to your clients via the .NET stack?
|
# ? Nov 7, 2014 17:15 |
|
Mr Shiny Pants posted:If you look at the comments collection in the debugger, do they have the right IDs? The code, from my understanding, should work. Nope. If I look in the debugger for a document that started with no comments, they all have an ID of 0. If I go with a document that already had a comment, they all have whatever ID the comment had. Here's the entire method that actually appends comments: A couple notes: I use a separate method to actually check if a comments part already exists and create it if necessary. That method runs once at the beginning of the file analysis. This method is called at the end of analyzing each paragraph to append the comment to the paragraph. code:
|
# ? Nov 7, 2014 17:24 |
|
LeftistMuslimObama posted:Nope. If I look in the debugger for a document that started with no comments, they all have an ID of 0. If I go with a document that already had a comment, they all have whatever ID the comment had. So you take largest of existing IDs, which is zero, and you add a new comment with same ID which is still zero? I don't see any code to increment ID.
|
# ? Nov 7, 2014 17:28 |
|
|
# ? May 15, 2024 20:51 |
|
Forgall posted:So you take largest of existing IDs, which is zero, and you add a new comment with same ID which is still zero? I don't see any code to increment ID. :facepalm: Added this to the method and fixed it: id = Convert.ToString(Convert.ToInt32(id) + 1); As usual, I assumed the complicated thing was the problem and didn't see the obvious thing right in front of my face. Although that still makes MS's example bad because their code basically just grabs the first paragraph and sticks a new comment on it. They don't increment the ID either so their example would screw up a document that was already commented.
|
# ? Nov 7, 2014 18:14 |