|
gariig posted:Also, Microsoft agrees with you because JSON.Net will be the JSON serializer when Web API ships
|
# ? Apr 3, 2012 23:45 |
|
|
# ? May 10, 2024 20:10 |
|
A slightly more involved alternative if you don't want to pull in JSON.NET is to write a JavaScriptConverter subclass and pass it off to the JavaScriptSerializer which is all JsonResult uses under the hood. You can customize field names via JavaScriptConverter, though if you want to support anonymous types you'd have to do some reflection to discover what the converter is being given at runtime.
|
# ? Apr 4, 2012 01:46 |
|
Because I want to test (almost) everything, I find that I have to use interfaces. A lot. For almost everything I make, I have to define an interface, and use that instead of the concrete class in other classes (or interfaces). Now this is all fine, but it's getting very annoying that every single time I add a function or a property or an event or anything, I have to update the interface as well. Is there a way so I don't have to do this manually, or am I just going to have to suffer?
|
# ? Apr 4, 2012 11:52 |
|
uXs posted:Because I want to test (almost) everything, I find that I have to use interfaces. A lot. For almost everything I make, I have to define an interface, and use that instead of the concrete class in other classes (or interfaces). ReSharper has a "pull member up" function that will add a method to an interface with like 2 clicks.
|
# ? Apr 4, 2012 13:10 |
|
uXs posted:Because I want to test (almost) everything, I find that I have to use interfaces. A lot. For almost everything I make, I have to define an interface, and use that instead of the concrete class in other classes (or interfaces). Are you only doing the interfaces specifically for mocking? You could mark members as virtual and mock it that way, too.
|
# ? Apr 4, 2012 14:03 |
|
Or just avoid mocking the poo poo out of everything -- I think that worm as swung over too far in some places. I totally appreciate mocking / stubbing out / faking external dependencies but mocking every class something interacts with is overkill. Especially when the other classes have tests to ensure they work correctly and your code is reasonably clean as to not have wacky dependencies.
|
# ? Apr 4, 2012 14:23 |
|
wwb posted:Or just avoid mocking the poo poo out of everything -- I think that worm as swung over too far in some places. I totally appreciate mocking / stubbing out / faking external dependencies but mocking every class something interacts with is overkill. Especially when the other classes have tests to ensure they work correctly and your code is reasonably clean as to not have wacky dependencies. I agree. Plus, if the code is reasonably well-written in the first place, it's generally fairly painless to refactor later on if you need to decouple further.
|
# ? Apr 4, 2012 14:29 |
|
Ithaqua posted:I agree. Plus, if the code is reasonably well-written in the first place, it's generally fairly painless to refactor later on if you need to decouple further. I also agree. At work we generally have to write every single thing to an interface "just in case we need to swap it out some day", and I'd say 99% of those interfaces only have one concrete implementation. I understand the whole technical debt thing, but worrying about potentially change a class some day is annoying.
|
# ? Apr 4, 2012 14:35 |
|
Active directory manipulation:code:
|
# ? Apr 4, 2012 17:01 |
|
boo_radley posted:Active directory manipulation: Is there no way to add a range of Users? Did you try saving after adding all of them instead of after each addition?
|
# ? Apr 4, 2012 17:36 |
|
boo_radley posted:Right now the System.DirectoryServices.AccountManagement calls in this loop are 90% of this program's execution. I'm looking for ways to speed up this set of loops. I don't know if there's a way to intelligently cache AD objects, or if there's a different API that would lend itself better to the task. I dunno if it'd add any performance benefit, never worked with ActiveDirectory, but storing the user in a dictionary might help some. code:
|
# ? Apr 4, 2012 17:36 |
|
PhonyMcRingRing posted:I dunno if it'd add any performance benefit, never worked with ActiveDirectory, but storing the user in a dictionary might help some. This is pretty much what I would suggest, as well.
|
# ? Apr 4, 2012 17:46 |
|
Ithaqua posted:ReSharper has a "pull member up" function that will add a method to an interface with like 2 clicks. Is there something similar in CodeRush? We have licences for that + I tried ReSharper too and didn't like it that much. PhonyMcRingRing posted:Are you only doing the interfaces specifically for mocking? You could mark members as virtual and mock it that way, too. Yeah, that's possible too. But then I have to make everything virtual. Apart from that being work as well, you also risk executing code that you forgot to mark as virtual. I can see it now: 'public void ClearTable() { ... }'. Oops. wwb posted:Or just avoid mocking the poo poo out of everything -- I think that worm as swung over too far in some places. I totally appreciate mocking / stubbing out / faking external dependencies but mocking every class something interacts with is overkill. Especially when the other classes have tests to ensure they work correctly and your code is reasonably clean as to not have wacky dependencies. I like mocking. It makes it easy to make sure that the code under test doesn't do anything unexpected, and you can check if the right calls and stuff were received. Besides, a lot of things you need to test ultimately depend on some database or filesystem or whatever, and you have to mock those. Anyway, I'll check again if I really need to mock everything.
|
# ? Apr 4, 2012 18:13 |
|
My C# is nearly non-existent, but it looks like you're trying to iterate through all the members of one group and add them to another group? If that's the case you can eliminate nearly all the System.DirectoryServices.AccountManagement calls by just retrieving the base directory entry of the group to start with. That way you already have the members and can add them to the child group without calling UserPrincipal.FindByIdentity every time. I don't know enough C# to write it out but here is the VB equivalent. code:
adaz fucked around with this message at 20:14 on Apr 4, 2012 |
# ? Apr 4, 2012 18:18 |
|
uXs posted:Yeah, that's possible too. But then I have to make everything virtual. Apart from that being work as well, you also risk executing code that you forgot to mark as virtual. I don't know enough C# to write it out but here is the VB equivalent. code:
What is this "new-object" and lack of Dims?
|
# ? Apr 4, 2012 19:06 |
|
powershell
|
# ? Apr 4, 2012 19:28 |
|
PhonyMcRingRing posted:
I just fixed it . So used to doing all my AD stuff in powershell that I apparently half wrote that in powershell
|
# ? Apr 4, 2012 20:15 |
|
Do you guys know of a way to embed a webkit browser in a WFP application without buying Awesomium?
|
# ? Apr 4, 2012 20:16 |
|
Once again I am having a moment. As you can see, this is ye olde threadpoole done with tasks. Start a task, it enters WorkerThread. As the domain of i is 0-1, the domain of clientId should be 1-2. So why is clientId 3 in the first line of workerThread? It produces the first task normally, it shows up as clientId = 0, but then the second task gets value clientId = 3. If I start three tasks, they get clientIds 2,4,and 4, or sometimes 2,3,4 or 4,4,4. I don't see where else it could be altering the value of i, and I'm checking the value immediately after entering WorkerThread, so it's gotta be something in the Main. The program flow looks exactly as expected, though. e: It's gotta be some weirdness I'm not understanding about tasks, everything goes as expected if I switch to an array of threads instead of tasks. e2: I bet it's somehow considered a reference when I pass the variable into the task. I figured the lambda would insulate me from the outer scope, I guess not. Paul MaudDib fucked around with this message at 21:18 on Apr 4, 2012 |
# ? Apr 4, 2012 21:06 |
|
That's how closures and loop variables work (at least, until C#5). I'll just let the good man Eric Lippert explain. Edit: looks like you figured it out in edit 2.
|
# ? Apr 4, 2012 21:17 |
|
Paul MaudDib posted:Once again I am having a moment. Your for loop is equivalent to the following: code:
If you're written the same code in VB, you'd have got an warning message: "Using the loop control variable in a lambda may lead to unexpected side effects. Consider assigning it to a temporary." In C#5/VB11 we changed the behavior of foreach (but not for) so that it allocates a fresh instance of the local variable for each iteration. Thus, the following code in C#5/VB11 will do what you want: code:
code:
|
# ? Apr 4, 2012 21:17 |
|
Your problem is that the lambdas are closing over the variable i, not the value of i at the time the Task is created. When the for loop exits i has a value of 2, and when the Task actually gets around to executing it looks at the value of i (2) and does it's work based on that value. You need to introduce a new per-loop variable like this code:
e: beaten while typing PDP-1 fucked around with this message at 21:29 on Apr 4, 2012 |
# ? Apr 4, 2012 21:19 |
|
You have an issue where your counter variable is changing within the scope of your closure. Copy "i" into a different variable within your loop and the problem should go away. Ex: code:
Super-beaten! Let me pimp ReSharper again: It warns you about problems like that.
|
# ? Apr 4, 2012 21:20 |
|
Paul MaudDib posted:Here's the problem: Closures (like that anonymous function you're passing to new Task() close over variables, not values. All your tasks are seeing the current (i.e. last) value of i, not whatever that value was when you created the task. Except sometimes they don't, because they might start executing before the loop in Main finishes.
|
# ? Apr 4, 2012 21:21 |
|
Paul MaudDib posted:
I encourage you to use Task.Run() instead! We think it's a better API. Stephen Toub wrote: "There's 0 reason to use 'new Task(...).Start()". It provides no benefit over Task.Run, is more error prone, and actually has a bit more overhead." Well, more precisely, there are just a few niche scenarios where you can't use Task.Run and have to use new Task.Start: http://blogs.msdn.com/b/pfxteam/archive/2012/01/14/10256832.aspx -- see #8.
|
# ? Apr 4, 2012 21:41 |
|
Today it is graphics....... I am writing a VB.net program that draws some interactive images to a [public] bitmap (on a module) and then displays them in a picturebox. I can put all the GDI stuff in a {Using,,,, End Using} statement so the graphics is disposed in the sub that does the drawing. Where should the bitmap be disposed? I am guessing,,, in the program's main FormClosed event? The bitmap must be used the entire time the program is running. I've already seen that if I dispose it when it is in a picturebox, that triggers a break on an invalid parameter reference. (.....I am using a bunch of public variables on the module already-- I never got the hand of encapsulating everything, and I'm just doing this for fun anyway)
|
# ? Apr 4, 2012 22:16 |
|
If its lifespan is equivalent to your process's lifespan, it doesn't matter. It's going away when your process dies whether it's disposed or not.
|
# ? Apr 4, 2012 22:34 |
|
Okay here is a vb.net graphics trivia question for y'all. It is no longer a problem because I already found the solution (which I will relate) but still a question remains: I needed to draw an image with text--so I made a picturebox, set the background to white, set up a bitmap to draw on, drew some test lines and text on the bitmap, and sent the bitmap to the picturebox. A screencap of that is below- All of the above examples were with the FontStyle set to regular, NOT bold. My PC has Win7, but the program I am writing will probably end up on computers running WinXP. I found that the "MS UI Gothic" looked just fine, but that it was not present on WinXP, so I began testing other fonts and fontfamilies that could carry over.... And they all looked like crap. I know a couple things about fonts, and it appears as though the hinting is not being used properly in all but the top one. Well I looked around and found this page- http://stackoverflow.com/questions/3418283/graphics-drawstring-looks-nice-in-picturebox-but-horrible-in-a-bitmap -where somebody else had a similar problem, and someone there put a link to this page- http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/9a66c7a2-79ad-4c9b-91cc-361ec72d13de -that gives the solution: when you try to render text onto a bitmap that has a transparent background, there is no background color for the font's hinting to dither to. So first you need to set the bitmap's background color to [something other than transparent], and then any font you use should hint properly. But one question still remains....... Why did the MS UI Gothic font look PERFECT, even when there was no background color for it to dither to? I tried a bunch of different fonts before finding out about the background color issue, and MS UI Gothic was the ONLY font that looked right against a transparent background....? I have not found any info that says the OS considers it to be any different than other fonts.... Most information I find about it only says that it is a standard Win7 kanji font. The Microsoft page even shows the example in kanji. http://www.microsoft.com/typography/fonts/font.aspx?FMID=1612
|
# ? Apr 4, 2012 23:18 |
|
aBagorn posted:This is pretty much what I would suggest, as well. These were good suggestions! The cacheing overhead has its own impact at around 7,000 users that seems to outweigh the time to do a raw query. However it seems like we're just doing too much in one monolithic process: 35,000+ users and 2 to 10 AD groups per user averaging 12s/1,000 group-users will take a bit over 8 hours to run. We're just doing too much with too many people all at once.
|
# ? Apr 4, 2012 23:22 |
|
Below is a screencap of the difference (after coloring the bitmap background white). Also by zooming in it is demonstrated that the MS UI Gothic font looks clearer, because it is acting like a bitmap font--it isn't dithering at all? (I changed the text on the last line, but none of them look like crap here. They all look like they're supposed to...)
|
# ? Apr 4, 2012 23:29 |
|
edmund745 posted:Also by zooming in it is demonstrated that the MS UI Gothic font looks clearer, because it is acting like a bitmap font--it isn't dithering at all? Because that's what MS UI Gothic is designed to do. The rest of your text looks like it isn't being grid fit. You should probably use a TextRenderingHint that includes GridFit (or stop forcing it to one that isn't).
|
# ? Apr 5, 2012 00:05 |
|
boo_radley posted:These were good suggestions! The cacheing overhead has its own impact at around 7,000 users that seems to outweigh the time to do a raw query. However it seems like we're just doing too much in one monolithic process: 35,000+ users and 2 to 10 AD groups per user averaging 12s/1,000 group-users will take a bit over 8 hours to run. We're just doing too much with too many people all at once. Could you divide the workload (by, say, first character of last name) across multiple machines and domain controllers to cut down on run time?
|
# ? Apr 5, 2012 04:14 |
|
Ok, another newbie question regarding browser compatibility with ASP WebForm controls. I posted this on StackOverflow but figured it wouldn't hurt to widen my net. have 2 radio buttons on an asp.NET Web Form that determine the way a user queries a database. The asp for them is this: code:
This all works fine in IE (7-8-9) and Firefox. However, when testing in Chrome, the radio buttons are not clickable. Is this something I should be using jquery for?
|
# ? Apr 5, 2012 15:27 |
|
aBagorn posted:Is this something I should be using jquery for? It's probably bad markup somewhere in the page. When you have a weird issue in an existing codebase, find the simplest reproduction you can. Start commenting out chunks of HTML until it works. Then start uncommenting chunks until it doesn't. You'll eventually find the chunk that's your culprit. But regardless, you should be using MVC and jQuery.
|
# ? Apr 5, 2012 15:54 |
|
Ithaqua posted:It's probably bad markup somewhere in the page. When you have a weird issue in an existing codebase, find the simplest reproduction you can. Start commenting out chunks of HTML until it works. Then start uncommenting chunks until it doesn't. You'll eventually find the chunk that's your culprit. Found the bad markup. Just some extraneous HTML. Yes I need to learn MVC, I know I know.
|
# ? Apr 5, 2012 16:12 |
|
I'm trying to figure out WPF ValidationRules and bindings and whatnot. In my project, Validations.cs contains a validation rule. In MainWindow.xaml, I have a TextBox that should use this custom validation rule. However, I can't quite figure how to get the right XAML to actually bind the two. I think it looks something like: code:
More generally, is there a good introduction to WPF bindings and whatnot? I feel I'm missing out on some major elements of WPF by not understanding bindings and what they can do.
|
# ? Apr 6, 2012 01:16 |
|
redleader posted:I'm trying to figure out WPF ValidationRules and bindings and whatnot. Validation Data binding For the record, I found both of those in about 5 seconds on Google.
|
# ? Apr 6, 2012 01:49 |
|
Ithaqua posted:Validation I had a look at those before I posted here. After some investigation, it turns out I needed to add a xmlns:foo="clr-namespace:MyShittyNamespace" bit before Intellisense could pick up my validation classes. Once I added this, I started getting a XamlParseException which has something to do with the default binding mode of a TextBox being "TwoWay". Changing the mode to "OneWay" allows the project to compile without errors, but the validation of the TextBox contents doesn't work. I think I'm going to need to do a lot more reading to get this to work.
|
# ? Apr 6, 2012 03:13 |
|
This is more of a Win32 question but my solution is in C# so this seems as good a place to put it as any. I'd like to exercise some code that can manipulate the value returned by GetUserDefaultLocaleName to test an API that calls into it. Don't really care about changing the locale in any other meaningful way. I've tried P/Invoking SetLocaleInfo but none of the parameter combinations I've tried has worked. Also tried modifying HKEY_CURRENT_USER\Control Panel\Internationa\LocaleName but no luck there either. Anyone familiar enough with these APIs to know how to do this? This is Windows 7 by the way.
|
# ? Apr 6, 2012 18:23 |
|
|
# ? May 10, 2024 20:10 |
|
I just installed .NET 4.5 but can't get it to work with VS2010 C# Express. There's no option to target 4.5 and the async/await keywords aren't recognized. Is there something else you need to do to make the IDE aware of the new libraries?
|
# ? Apr 6, 2012 19:12 |