Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

GrumpyDoctor posted:

You mean pulling information off the GUI? I've never had a problem with it before, and usually problems with that kind of thing cause crashes, not mystery no-ops.

If I'm not mistaken, you still shouldn't reference UI elements in a background worker (or in any non-UI thread, really). I forget if it just outright blows up or behaves in an unpredictable fashion, though.

You can specify an object as a parameter in the DoWorkEventArgs, so just make a struct that holds the UI parameters and pass it in when running the background worker.

Adbot
ADBOT LOVES YOU

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

epswing posted:

5) Is Linq to Sql bad for an N-tier environment/application? Am I an idiot for not using Entity Framework, or something else? I've read this Linq to Sql vs Linq to Entities article, and it seems like Linq to Sql matches what we want better than EF.

I wouldn't use LINQ to SQL simply because Microsoft isn't developing it any further; it's a dead end.

I like nHibernate, but I haven't really played with EF so I can't speak to the advantages or disadvantages of one versus the other.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

epswing posted:

While I know my UI will map 1-1 with my DB (I'm designing both)...I'm starting to understand the benefits of decoupling the two.

I obviously don't know how the particular application you're working on relates to your entire business, or how much of this you already know, so I'm just going to lay it all out.

Typically, you'll end up with three tiers:

- Presentation
- Business Logic
- Data Access

There can be more tiers as necessary, but that's the three-tier baseline.

Your data access layer handles all the data retrieval, whether it's from the file system, a database, a stone tablet, whatever. This gives you the benefit of being able to swap out the data access layer later on, which is vital for unit testing. You don't use a concrete implementation of your DataAccess component, you use something that implements IDataAccess, which could be anything! If you realize that you hate nHibernate and want to use an ODBC driver to a Foxpro database, or store all your poo poo in flat files, you can do it without dicking around with anything else.

Your business logic layer does all the boring businessy poo poo. If you have a customer database and your data access layer returns a List<Customer>, but your application only needs customers that are over the age of 30, your business logic layer strips out everyone younger and returns a nice, simple list.

Then, you just tie whatever your business layer is spitting out to a UI. Your UI doesn't give a rat's rear end where the data comes from or how it was shaped, it just takes what it's given. Same goes for putting stuff back into the database. You change one of your customers? Great! Shove it through your business logic, which validates that the changes are okay and passes it along to the data layer.

There are some pretty obvious benefits to designing software like that, the biggest one (in my opinion) being testability. You can test all of your business logic until you're sure that your software behaves properly and doesn't explode the second something unexpected happens. You can also test the poo poo out of your data access layer to make sure that, given a database containing <X>, when I ask for <Y>, I get the <Z> that I'm expecting. The presentation layer is the most difficult to test, and that's why you've decoupled everything to the point where the presentation layer has practically no code in it!

Also, look into unit testing frameworks if you haven't already. I've used MSTest and Nunit, and I have no strong preference for one versus the other. Ripping out a huge chunk of business logic out for refactoring isn't anywhere near as terrifying when you know it's under test.

New Yorp New Yorp fucked around with this message at 02:32 on Nov 20, 2010

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

epswing posted:

E: Oh snap, don't get me wrong, thanks for your help/reply, I don't at all mean to downplay your post. Especially the testing bit...it's a world of difference to know the major thing you just modified hasn't broken something on the other side of the system. I should write more unit tests :(

Yeah, maybe it will enlighten someone else! At my job, we get absolutely torn apart in code reviews if we don't have decent test coverage, so writing good unit/integration tests is becoming a way of life. I've been dabbling in TDD/BDD, but it's drat hard to get your brain wrapped around it.

While I'm here, anyone have any experience with Reactive Framework? I've been messing around with writing an event-driven IRC engine in C#, and Rx looks like it would be useful.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
We're interviewing for a .Net developer position at my job right now and we encountered a woman who was doing pretty well right up until we asked her to code up a string reversal, in Visual Studio, on the spot.

20 minutes later, we had to stop her because she still hadn't gotten it. We weren't looking for cleverness; a for loop would've been fine. She just outright couldn't figure out how to reverse a string. It didn't help that the first 5 minutes were her looking at "StringBuilder str = "";" and being very confused as to why it was showing up as an error.

[edit] My solution was "new string(stringToReverse.Reverse().ToArray());" and it took me about 45 seconds to figure out; I wasn't even 100% sure that there was a LINQ Reverse method.

New Yorp New Yorp fucked around with this message at 03:15 on Jan 23, 2011

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Dromio posted:

I have given that exact answer in interviews and accepted it as an interviewer. A matter of taste I suppose. Of course if pressed I could do a loop to reverse it, but why? I'd rather spend my time using the tools I have been given to solve a problem.

And usually I'd rather hire someone with experience and knowledge of the language than someone who will stumble around trying to solve problems that have already been solved. I'm more concerned with whether my hires know what an interface is than if they can figure out how to write a sorting algorithm.

Exactly! We're interested in seeing how easily the person arrives at the solution and if they can arrive at it at all.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

PhonyMcRingRing posted:

If she couldn't figure this out, I'm curious as to what was on her resume and how she was doing well in the interview up to that point.

She was on the fence after the phone tech screening, but she was doing okay with the business logic-y in-person questions. She also had successfully completed another simple coding task in a highish but reasonable amount of time.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

JerrysMom posted:

I've been tasked with finding out why a web page is slow sometimes (yay...)

It uses about 10 POSTs to HTTP handlers (.ASHX) to get JSON data back. Every now and then a few of the "heavier" calls take up to a minute or so, which is way off.

Disregarding the flaws in the architecture (we're going to improve this integration later on), where should I start to look? I'm using Firebug and the Net panel, that's how I found the culprits, but the next step isn't so obvious for me. I'm not sure the code can be improved that much (again - apart from rebuilding the whole thing) since this has been working OK before, but if it could, where do I start to look?

I've tried googling "ashx performance troubleshooting" but I mostly found pages about how ashx is a lot faster than asmx. Any ideas or suggestions for tools would be appreciated.

Easy question: You're hitting a database. Are the database tables you're hitting properly indexed? How big is the dataset you're retrieving?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Scaramouche posted:

The second part is, do you feel it's better to maintain existing web forms projects than just rewriting them?

It's never better to rewrite just for the sake of rewriting. You rewrite when you have a pressing need to do so. If you have a bunch of pages that work perfectly well and have no glaring problems, why tempt fate? Leave them the hell alone! If you need to add a huge swath of new features, then you weigh the pros and cons and possibly rewrite it.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Horse Cock Johnson posted:

Can anyone recommend an alternative drawing API to System.Drawing? What I need to be able to do is load up an image from disk, resize it, and draw rectangles on it - kind of like Facebook's tagging functionality. We currently do this just fine using System.Drawing but the whole thing will periodically poo poo itself with errors from GDI+ like "out of memory" or "a generic error occurred in GDI+".

I know the System.Windows.Media.Imaging namespace has some classes that I can work with but I'm just wondering if there's something better out there.

You can check out Leadtools, although the licensing is fairly pricey.

I hate the "generic error occurred in GDI+" message. It's so loving useless.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Jethro posted:

Because you really shouldn't depend upon your customers (or employer) installing a test version of C# that could be buggy as hell, may change without warning, and isn't even legal to use in a non-faffing about environment.

There's no "could be" about it (as evidenced above). When I saw it demoed at Codemash back in January, I was duly impressed, and I've played with the CTP in my spare time. The new async stuff is awesome, but it's not ready for production quite yet.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

fankey posted:

I need to persist what's effectively a Dictionary<string,byte[]>. My naive implementation was to create a class and then use the BinaryFormatter to persist
code:
class Data
{
  public string Name;
  public byte[] Foo;
}

byte[] GetFoo(string name)
{
  using (FileStream fs = new FileStream(LayoutFile)
  {
    BinaryFormatter bf = new BinaryFormatter();
    List<Data> datas = bf.Deserialize(fs) as List<Data>;
    return datas.FirstOrDefault(l => l.Name == name);
  }
}
Obviously this totally sucks once the list of objects gets to be any appreciable length. Is there something 'databasey' built into .NET 3.5 that I can use to persist/restore this sort of data? The data ends up being an XML file which represents the window layout when a particular design file is loaded. I know I could save each file individually but I'd rather stick it all in one file, as long as it can be done relatively efficiently from a save and restore speed standpoint.

EDIT: I should note that I know absolutely nothing about databases and whatnot so if that's the solution explain it like you might to a small retarded monkey.

I don't see any problem with your current approach. Why does it "suck"? Performance?

You could look into a nosql database, but I'm not going to recommend any because I have very little practical experience with them, and that seems like a pretty heavy solution to your problem.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Peao posted:

2) Can you name a few things which you would expect a junior dev to be able to do from memory, without looking up the correct syntax or .NET classes and methods? It would help me rate myself.

I'd expect a junior dev to be conversant with the language. Knowing abstract classes vs interfaces, virtual methods, boxing and unboxing, is all good. Brush up on LINQ/lambdas, too. It's pretty awesome stuff.

Mega bonus points (to me, at least) for being familiar with unit testing and dependency injection.

Knowing minutae about every language feature is not necessary, and no one is going to care that you don't know that a using() block translates to a try{} finally{} in IL (although they might be impressed that you do!).

Oh, and don't try to bullshit an interviewer. We know. We're not asking the question because we're not sure what the answer is.

quote:

3) In development teams, is a junior given time to bed in with the project, or is he expected to be productive immediately? If he's eased in, what sort of tasks is he given at first?

For me, it's pretty much the same no matter what your skill level... when you come in, you're lobbed a few easy tasks to get you familiar with our codebase, database schema, source control organization, and all that little stuff that comes with getting settled in. After that, it's "here's a non-critical but reasonably-sized task that needs to be done: ___. Here's how I'd approach it: _____. Go nuts, ask me if you have any questions."

It's critical to ask questions when you're not sure about something. If you don't, you're going to gently caress something up, guaranteed. And then during code review, someone is going to tear you a new rear end in a top hat, and then you'll feel bad and they'll feel bad and everyone will feel bad.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Here's my weirdness for today, with a solution even! I was trying make a generic version of an existing method that acts on one specific object that implements an interface.

Here's the problem condensed down to some classes and interfaces.

Given a setup like this:
code:
    public interface IFoo
    {
        string bar { get; set; }
    }

    public class Foo : IFoo
    {
        public string bar { get; set; }
    }

    public class FooHolder
    {
        public IFoo[] FooArray { get; set; }
    }
Doing the following gives a compiler error:
code:
    public class FooManipulator
    {
        public void DoSomethingWithFoo<T>() where T: IFoo
        {
            var holder = new FooHolder();
            T[] fooArray = new T[5];
            holder.FooArray = fooArray;
            
        }
It doesn't like the statement holder.FooArray = fooArray;, because "Cannot convert source type T[] to target type IFoo[]"

Here's a solution that looks like it works (with due credit to one of my co-workers):
code:
    public class FooManipulator
    {
        public void DoSomethingWithFoo<T>() where T: IFoo
        {
            var holder = new FooHolder();
            T[] fooArray = new T[5];
            var fooList = new List<T>(fooArray);
            holder.FooArray = fooList.ConvertAll(x => x as IFoo).ToArray();
            
        }
    }
I just wanted to share that. I'm still not 100% clear on why the original code was an issue, so if anyone wants to weigh in while I'm reading up on generics, enlighten away!

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Thanks npe, that was very enlightening!

rolleyes posted:

Funnily enough I've just been digging a bit further into covariance (and contravariance), in particular the use of the "in" and "out" keywords when defining a generic interface. In summary, it made my head hurt for a bit but once you understand the reasons behind it (and can remember which is which :v:) it is indeed cool.

Yeah, that's on my increasingly long list of things to really study.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

brainwrinkle posted:

I'm working on a new ASP MVC 3 website for analyzing data from an existing MySQL database. I've been working on getting Entity Framework 4 and LINQ to SQL to play nicely, but it seems there's a pretty bad bug in the MySQL connector that breaks group statements. Are there any good alternatives? Preferably I would like to use EF and/or LINQ, but if there are other good practices I'm not aware of (I'm new to .NET) I'd love to hear about them.

Oh, and apparently our DBA won't let us use stored procedures and alternate connectors don't really work either.

nHibernate is an option, but I've never done nHibernate to MySQL. There's also SubSonic, but I've never even used it and I have no clue about getting it to work with MySQL, so I'm leaving it up to you to evaluate it.

Also, what the gently caress is wrong with your DBA that he won't let you use stored procedures? Are you supposed to use inline SQL if you can't get an ORM to work?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

brainwrinkle posted:

Fortunately, there was a patch that worked with some tweaking, and I recompiled the connector and got around the problem. Thanks for the suggestions. I might still check those out because I'm having some difficulty translating these moderately complex SQL queries to LINQ.

At least with nHibernate, I've had good experiences with making a view that returns the exact data I'm looking for and working with that. Keep in mind, the ultimate goal here is to have the actual SQL be as simple as possible and let your code handle the logic.

The thing I like about nHibernate is that it operates on plain C# classes without any need for attributes or anything nHibernate-specific. I could decide "gently caress nHibernate!" tomorrow and re-implement the data access part, and nothing else in my codebase would have to change.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
I'm going to take the sane, rational approach and not flip the gently caress out over a demo showing one aspect of one of the new things they have planned for Windows 8.

I strongly doubt .NET as a platform is going anywhere. At worst, they'll start really pushing WPF/Silverlight.

[edit] And that's a "worst" that's not even really a bad thing. The little I've done with WPF, I've liked.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

boo_radley posted:

Hey, take a look at this Visual Studio Extension: Debugger Canvas.


edit: All I need now is a Kinekt API into this thing.

Fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuck, that's awesome. I have VS2010 Ultimate at home, but not at work. It's going to spoil me. :(

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Hoborg posted:

I must apologise for refusing to stop living in 2005 (.NET 2.0 forever!) but can someone explain, very quickly, what Rx is and what it enables/allows developers to do that they couldn't do before?

I'm perfectly happy with using Threads and pools, Mutexes, Wait Handles, and Semaphores directly. In GUI work I'm fine with Invoke/BeginInvoke and that works perfectly fine for me.

About 18 months ago, a friend spoke of how some concurrency platform Microsoft built (the same thing?) provided stuff that automagically broke down massively-parallel tasks down for multicore systems (like a single-system map-reduce). Is that what this is for?

Today I'm finding myself doing LoB applications and stateless web-services. How will Rx help me? Am I in the target audience?

What your friend is probably talking about is the Parallel task library, which is new in .NET 4 and is awesome. I mean, what's going to be easier to maintain and debug? Writing a shitload of concurrency code, or doing Parallel.ForEach()?

Rx is for doing work asynchronously without starting up a new thread.

Also, I hope you're kidding. .NET 3.5 and 4.0 have some awesome, awesome features and if you're not familiar with them, you should be.

New Yorp New Yorp fucked around with this message at 22:51 on Jul 1, 2011

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Milotic posted:

nHibernate ... It's also beginning to feel like an amazingly crufty piece of poo poo nowadays.

How so? I'm not disagreeing, just curious. I've recently realized that although I've been using nHibernate for a year or so, I've barely scratched the surface of what it can do.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Scaramouche posted:

I know exam-chat has already passed, but thought I'd share. Back in the late 90s they had basically what is MCITP now but I forget what it was called then (think it was just generically MCSE with a desktop specialization). One of the questions was "How many floppy disks are used for the standard Windows 95 installation?", which totally sucked because it could be either 15 or 31 at the time.

And of course it's absolutely vital to know that. :rolleyes:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Monkeyseesaw posted:

^^ oh yeah and dynamic which is pretty cool but like the generic covariance etc only comes up if you really need it.


If I recall correctly the main addition in C# 4 was optional parameters and named parameters which go hand-in-hand and you can wrap your head around in about 10 seconds. They also added generic covariance and contravariance but nobody wraps their head around that unless they have to.

There's also the parallel task library and about a million other things of varying levels of usefulness.

In general, if you have the option to go with .NET 4 in a new project, do it! Obviously, for learning the language, 3.5 vs 4.0 isn't going to make too much of an impact.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Rocko Bonaparte posted:

I have another GUI question. I'm still trying to write some unit tests for a GUI. I was hoping to find out a way to tell if the GUI has finished starting, so I can start sending events to it. Currently I can let it sleep 5 seconds and get lucky, but that means at least 5 seconds per test that spawns a new GUI. I was wondering if there's a standard way to tell if a GUI is up and finally responsive. If it helps, the main control I test is a text box.

You don't want to write tests for your GUI, you want to write tests for the underlying logic. Optimally, as little code as possible is in your GUI. If you want to test GUI interaction, look into something like Coded UI.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Orzo posted:

I disagree, GUI code should be tested just like everything else. Agree that it should be kept thin, but real things happen in a GUI that need to be tested. Even if you're using the best possible abstractions and a really clean model-driven UI, you should still be testing that the model and the UI are properly wired, i.e. clicking this button should trigger some service and also trigger a model refresh.

Fair enough. That's where tools like Coded UI come in!

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
I'm playing around with EF4.1 tonight, and I've got to admit that it's pretty slick. My only other ORM experience is with nHibernate, and EF feels like a lot less effort to get up and running.

Of course, I won't be getting my current employer to move to an ORM anytime soon. I'm fighting an uphill battle to get them on board with unit testing.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

mik posted:

I've noticed that while doing some performance profiling, the first linq query takes 5 times longer than the equivalent loop, but if I run the query again, it takes essentially an identical amount of time. Are Linq queries cached?

In my experience, LINQ performs worse than a non-LINQ equivalent, but it really shines for making readable code.

For example,

code:
            int sum=0;
            foreach (int itemToSum in shitToSum)
            {
                sum += itemToSum;
            }
versus

code:
            int sum = shitToSum.Sum();
The first performs better (I checked!), but the second is instantly readable.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gariig posted:

Can you post the timings? From what I've seen the difference is pretty small

It is a tiny difference, and I was wrong, anyway. My last test was with Enumerable.Sum(x=>x) instead of Enumerable.Sum(). Turns out Enumerable.Sum() is way faster, which probably shouldn't have surprised me but did.

I generated a list of 50,000 random numbers and summed them 10,000 times with LINQ and 10,000 times with a foreach. I don't do much in the way of measuring performance on a regular basis, so I can't speak to whether this is actually accurate!

Total run times are:

LINQ: 33 seconds (33071 ms)
Foreach: 34 seconds (34606 ms)

And here's my code so someone can tell me how I'm measuring performance all retarded-like and educate me. I also took this as a chance to play around with Actions and Funcs!

code:
    class Program
    {
        private static readonly Random _rand = new Random();
        public static void Main()
        {
            var shitToSum = 50000.Times(()=>_rand.Next(1000));
            Action linqSum = () => SumWithLINQ(shitToSum);
            Action foreachSum = () => SumWithForeach(shitToSum);

            var s1 = new Stopwatch();
            var s2 = new Stopwatch();

            s1.Start();
            10000.Times(linqSum);
            s1.Stop();

            s2.Start();
            10000.Times(foreachSum);
            s2.Stop();

            Console.WriteLine(s1.ElapsedMilliseconds);
            Console.WriteLine(s2.ElapsedMilliseconds);
            Console.ReadLine();
        }

        private static long SumWithLINQ(IEnumerable<long> shitToSum)
        {
            return shitToSum.Sum(x=>x);
        }

        private static long SumWithForeach(IEnumerable<long> shitToSum)
        {
            long sum2 = 0;
            foreach (var itemToSum in shitToSum)
            {
                sum2 += itemToSum;
            }
            return sum2;
        }
    }

    public static class Extensions
    {
        public static IEnumerable<long> Times(this int timesToExecute, Func<long> actionToRun)
        {
            for (int i = 0; i < timesToExecute; i++)
            {
                yield return actionToRun.Invoke();
            }
        }

        public static void Times(this int timesToExecute, Action actionToRun)
        {
            for (int i = 0; i < timesToExecute; i++)
            {
                actionToRun.Invoke();
            }
        }
    }

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Fiend posted:

http://msdn.microsoft.com/en-us/library/3det53xh.aspx#Y57

Thats the best way I found to quickly transfer a collection of lines to a file. You could also investigate "singleton pattern" to make it thread safe.

But be aware that if you want to write unit tests, using a singleton makes it a big pain in the rear end. There are other ways to make an operation thread safe.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

rolleyes posted:


How do I keep my memorystream 'alive'?

Try this:
code:
        static void Main(string[] args)
        {
            
            string inFolder = @"F:\data\";
            string outFile = @"F:\data\output\output.txt";

            using (var msOutput = new MemoryStream())
            {
                using (var sw = new StreamWriter(msOutput))
                {
                    foreach (string file in Directory.GetFiles(inFolder))
                    {
                        //process files
                        sw.WriteLine(file);
                    }

                    using (var fs = new FileStream(outFile, FileMode.Create))
                    {
                        sw.Flush();
                        msOutput.WriteTo(fs);
                    }
                }
            } 
        }
What you're doing here is wrapping the memorystream in a stream writer, and while both streams are still in scope, writing the contents to a third stream.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

rolleyes posted:

Ah, so it does come down to a lot of nesting then. I was hoping there was some way to 'bracket' different types of object within the same using scope but I guess not.

I could see this getting hard to read very quickly if you have more levels (which thankfully I don't). I guess the alternative is to skip 'using' and write your own try/finally instead?

You can do
code:
using (var x = new MemoryStream)
using (var y = new StreamWriter(x)) 
{
//code
}
I put all of the curly braces in for clarity.

If you want some more fun, look at doing the file processing in parallel!

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

rolleyes posted:

I think I'll save the combination of unmanaged resources and thread safety for another day thanks!

Quick followup question - what are the implications of passing unmanaged resources to other methods? Does the 'using' in the parent maintain resource safety or would the target method need to do use it too? Or does it depend on the way exceptions are handled within the target method?

Stream.Synchronized() will give you a thread-safe stream.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Nurbs posted:

switch to project references and use visual studio to get the latest version from tfs?

This.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Milotic posted:

Whether you should just propagate the classes created by Entity Frameworks right up the stack to your presentation layer is an interesting one. On the one hand it makes development a lot faster. On the other hand you could argue the Database isn't always structured quite right for Business objects.

I've seen both sides, and I prefer the latter option. I'd rather retrieve a database-shaped representation of my data and then mold it into a presentation model / business object that contains exactly the information I need, structured exactly the way it's needed for the task at hand. You still have to be careful, of course, lest you end up with half a dozen slightly different models of the same data.

Milotic posted:

One thing I would suggest is some sort of repository pattern or interface for routing the bit where you actually hit the database - even if you just pass the objects returned straight through.

Oh god yes, do this.

New Yorp New Yorp fucked around with this message at 03:51 on Oct 1, 2011

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Nurbs posted:

Use the task parallel library in .net 4, I believe it will manage the work better than simply queueing the items directly on the threadpool

Well, the TPL uses the threadpool behind the scenes if I'm not mistaken, but yes for the love of god use the TPL. It makes life so much better.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gariig posted:

Ok I have a Visual Studio solution question. We are in the process of rewriting an application that a framework. We will have about 75 projects that use the framework. Should the projects that use the framework live within the framework solution? If it does live in the framework solution should it use a project or file reference?

My company buys public data from counties around the U.S. and they generally send it in a proprietary format. So one parsing project per county.

Your framework should have its own solution. Anything that uses your framework should include necessary project files from the framework.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Kreeblah posted:

If there are any WCF gurus out there who have seen this, I'd very much appreciate some help.

Long story short, I got roped into writing a script to pull stats from Microsoft's new IIS Transform Manager for service monitoring and doing some checking, I found it uses WCF for its endpoints. I got something working that reads credentials in from the config file and uses them to run queries against the TMs we have set up, but when I deployed it to a test IIS server in our datacenter, it's throwing these every time it tries to connect: System.ServiceModel.Security.SecurityNegotiationException: Either the target name is incorrect or the server has rejected the client credentials.

I know it's using the credentials from the config file because I'm having it log the user and domain, which are correct. I have no idea, though, why it would be succeeding locally on my machine, but failing on a server over there.

I'm not a .NET guy (we're mostly a FOSS operation, but we needed to use the Transform Manager for a few things), so I'm pretty lost with this. The whole WCF thing seems way overcomplicated to me and after some Googling, I realized I'm really not sure where to even start looking to track this down.

Post the app.configs from both the client/service end, obviously with any sensitive information (server names, credentials) redacted. WCF is awesome, but getting the endpoints set up properly can be a real pain in the rear end.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

GrumpyDoctor posted:

I have a C application that receives a FILE * and writes stuff to it, and I want to use this functionality from .NET (4.0). I know how to do basic platform invoke, but I can't figure out what to use for the FILE * in the call into the native application. I tried using the unsafe handle from an anonymous PipeStream but I'm not receiving any data (even after I turned buffering off on the C side - I couldn't see how to try that on the C# side). I feel like I should be using an UnmanagedMemoryStream but I can't figure out how to set it up.

As icing on the cake, this needs to be asynchronous.

Any reason why you can't just run a completely separate C# application that reads the file?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Paul MaudDib posted:

I want to make a property do something, then return its wrapped value. i.e. i want to replace
code:
int thing{get;set;}
with
code:
int thing{
  get{dostuff(); return value;} 
  set;}
but I don't think value is the magic word. Anyone know what it might be?

Be careful with having a property call a method like that, especially since it seems like "DoStuff()" has a side-effect of mutating the value of "value".

Read this and then reconsider your design.

Adbot
ADBOT LOVES YOU

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Sedro posted:

VS without R# is like using notepad to me now. Here's some stuff I use all the time:
* browse source code by decompiling on the fly or downloading from msdn reference source (using ctrl+click or "Go to definition")
* menu options "Find usages" and "Go to implementation"
* menu option to move a class to its own file based on its class name (I often create a few classes in one file and break them apart into separate files when I'm done)
* code analysis in xaml, compile-time checking for binding paths
* customizable templates/snippets which are far better than the ones built into VS
* code analysis uses attributes ie. [NotNull] which is the closest thing I've found to safe, non-nullable reference types. Includes refactoring options to turn this:
code:
void DoSomething(string str)
{
}
into this with a couple keystrokes:
code:
void DoSomething([NotNull] String str)
{
    if (str == null)
        throw new ArgumentNullException("str");
}

Also, the Extract Method feature is amazing. Highlight a chunk of code, click "Extract Method", and bam! It figures out what needs to be passed in as an argument and what to return.

Extract Interface is similarly rad.

I just love that it has a lot of really great features that work right out of the box with no research, configuration, or digging through menus, but also has a ton of depth and usefulness beyond that.

Lack of enthusiasm about ReSharper is one of the things that made me realize the team I just joined sucks. They won't even install the trial version.

  • Locked thread