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.
 
  • Post
  • Reply
crashdome
Jun 28, 2011

Dietrich posted:

Nice op.

I just had tfs needlessly complicate things for me yet again, so allow me to re-endorse using Git flavored repos. Makes everything much better.

I've never used Git because gently caress command line. Although, I do find TFS a bit confusing at times. I thought Git would be more confusing. Is that not true? Can I seamlessly browse my projects in VS with Git? Can I type a comment in a textbox and push pending changes to Git? I'm a lone developer with a few read-only accounts to my projects.

If so, I'd try setting up a Git repo just to play with. It's just as easy to set up Git in VS online as it is to use their TFS. I just thought I would be forced to use a command line or third party tools to use it?

Adbot
ADBOT LOVES YOU

crashdome
Jun 28, 2011
OK, thanks everyone. I don't want to cause a rift but, I just never heard or saw anyone talk about how easy Git was. Only that it was "better" and then spout about command line this and command line that. I will try it out. Right now, environmentally TFS might suit me better. Although, I do want to not appear stupid when confronted with a Git repo in the future either.

Personally, TFS seems ok to me. I like having a connection to my VS online account and can see and manipulate projects and workspaces without leaving VS. Although, I do not connect to any other TFS server and do not have to split projects or work across multiple repos. The only thing that confused me about TFS was I got a new device, loaded up VS2013, and promptly got lost setting up ONE workspace in a custom located local folder for a few related projects. I managed to work it out but, the UI is confusing for server connections (and don't get me started on logging out and logging in as another user). However, UI design overall seems great - once you are setup.

crashdome
Jun 28, 2011
Maybe we could also add something about publishing your programs or what to use if you want product key activation in your app/program?

I have used Cryptolicensing in the past because it's cheap but, looking at Intellilock and Elipter. Is there a MS library for this to aid in roll-your-own?

edit: probably too much of a tangent discussion for the OP now that I think about it

crashdome
Jun 28, 2011
I'll just throw some things out there. Somebody correct me if I'm way off base.

Permission/Security context of VS as compared to where the files are located? Is something conflicting with a DLL in the GAC vs the files you want?

If you reference assemblies directly, put copies in a source folder and reference from there. It helps avoid "unable to find" errors when you are working across multiple machines with potentially different file structure. Try not to reference assemblies in the 'Program Files' folders as you could potentially run into the virtual file system mucking everything up.

crashdome
Jun 28, 2011
How about a validation error on the control instead of a modal? Are you just validating data entry?

crashdome
Jun 28, 2011

gently caress them posted:

That's literally it, EXCEPT that they want a big fat textbox where they can enter any number of driver's license numbers (DLNs) and I just separate them out by newline/whitespace/whatever, match them to a regex, then go search by them. This is basically just a little tool for clerks to get a bunch of driving record PDFs out of a state ran REST service. They then print out all of those PDFs.

I get a bit anal about UI sometimes. My approach would be to dynamically add textboxes after each license was entered and validated. Auto-switching focus even. If I was a user and had to enter two dozen licenses and learned only after the fact that I was entered one of them wrong that I had to hunt down both in my notes and also in the textbox OR alternatively that my zero key wasn't working and I had to go back and replace zeros in most of the lines, I would be pissed. The benefit of this method is you code the validation once and the UI behavior once. The drawback is you have to concern yourself with all of the validation markup instead of a single method/event.

But again, I am an anal SOB when it comes to data entry. Do what you need to do with the time you got and modal dialogs are perfectly fine in WPF if that's the way you go.

crashdome
Jun 28, 2011
Anyone use Xamarin? Client is looking to get a native framework supplied both for iOS and Android development into an app for both platforms and setting up two development environments for the same project seems cumbersome.

crashdome
Jun 28, 2011
Good to hear. Think I could get away with the free IDE for a demo? I'm sure if the demo was successful, the $999/year would be a drop in the bucket for the planned product development.

crashdome
Jun 28, 2011
I think that's possible. It looks amazing! Definately disappointed by the limitations of the free version but, the trial should be sufficient. I'll definitely make use of the 30 days for sure. Just realized it's $999 PER platform. Ugh.

crashdome
Jun 28, 2011
In my VERY brief attempt to play with Xamarin, it seems slick. I hold my breath though.

I have read forums where people talk about using Unity as a cross-platform LoB tool and cringe.

Seems like it is also a better tool than "we'll just throw up a web server and trust cross-platform compatibility to the browsers"


Newf posted:

Looking forward to a $1600 VS 2015!

Lol. Or that $150/month/developer/platform/number of toes you have subscription fee*


*Xbox achievement unlocked if you are polydactyl!

crashdome
Jun 28, 2011
I'm having trouble following your question. I have dealt with serial ports enough to know what to do if you want some sample code. Serial ports should be opened and closed only as needed. Disposal is critical or you will get port already opened errors. You also need to handle if your data doesnt all come in one read. It's all very tricky but if you set it up correctly you'll run into less problems.

crashdome
Jun 28, 2011
I generally used ReadExisting() but I also used to have a sleep call for 650ms to make sure it all came over.

When I converted to async, I called ReadExisting multiple times until nothing was returned and appended the bytes to a buffer. I then would send the buffer to thread safe message queue for the UI or any other usage. The dataReceived handler seems to run on it's own thread automatically. Generally I would have flow like this:

OpenPort --> SendData -->{Start Timeout and Wait}--> DataReceived {Reset Timeout} --> ProcessBuffer --> SendToQueue --> ClosePort

and then the Queue would raise an event that there was a message available. If the port would hang, it would timeout and close the port.

Edit: I also had a program that you would manually open and close the port. It would check if either CTSHolding or DSRHolding were live to determine if someone pulled the cable and auto-close if so.

crashdome fucked around with this message at 23:02 on Aug 15, 2014

crashdome
Jun 28, 2011
ReadByte will supposedly return a single byte and you can Tryparse it but, it's a lot of bloat. ReadExisting returns a string but, you can convert the string to bytes using Encoding if you know the protocol encoding.

Use Read(byte[] buffer, int offset, int count) if you want a byte array directly.

Handling this means you'll have to wait for a response and allow the thread to populate BytesToRead. It isn't weirdness as much as it is just sloppy implementation spanning all the way back to .Net 2.0

crashdome
Jun 28, 2011

JawnV6 posted:

ReadByte does not return a byte. It returns an int. An explicit conversion is required, it will not compile without that conversion. I'm confused what TryParse would help here.

I meant that ReadByte returns a byte (as an Int). In otherwords, it is an Int from 0 to 255 but, you understood what I was saying without me saying it in that you would need to convert it back.

Edit: I see Byte.TryParse doesn't take Int - may have confused you there too. In any case, I meant explicit conversion (BitConverter or whatever)

crashdome fucked around with this message at 18:02 on Aug 16, 2014

crashdome
Jun 28, 2011
This isn't a question as much as an op-ed post because I am really hating the project I am doing right now. I really have to say that working in .Net has sufficiently spoiled me. I mean, we all have our complaints about it but, I am doing a project in C using a customized Eclipse IDE (for code generation) and I feel like I went back in time to the building of the pyramids. The language/franework is certainly sound. It's the complete lack of anything other than a pretty color on syntax that is frustrating me. No auto-complete. No Intellisense. Can't even use project references without writing weird makefiles. Seperation of concerns is *almost* impossible due to their custom compiler. The documentation for the framework is laughable. They have a "wiki" which is more like 4 pages of FAQs but, instead of actual FAQs, it's sales pitches. The "tools" aren't even customizable. They code generate a bunch of generic "example" files and basically tell you that you have about 100 years of work ahead getting it all to your liking. Find/Replace all day! Yay! I could hunt down Eclipse plug-ins for all this but, instead I am trying to integrate their tools into Visual Studio since it will probably take just as long.

So thank you Microsoft for having the best online documentation I have personally ever used. Thank you .Net community for the awesome tools that are space-age compared to this. And thank you Visual Studio for being flexible enough that I can take this horrible projects tools and integrate them into you like the *wonderful accommodating partner* that you are.

crashdome fucked around with this message at 01:33 on Aug 26, 2014

crashdome
Jun 28, 2011

Gul Banana posted:

It's not magic, mind you.

I'm pretty sure it's a religious conviction though because of all the faith involved and the sinful behaviors that are committed on a daily basis :can:

crashdome
Jun 28, 2011
Alternatively, you could simply deploy each branch as it's own host header or port in IIS if you are limited.

crashdome
Jun 28, 2011

Scaramouche posted:

This is more of an academic question, but what's up with String.Format("0.00") versus Math.Round? I've got a weight value that I always want to underreport/round down a little bit, so I've been using:
code:
Format(SomeDecimal,"0.0")
As I thought it would just truncate x.xx to x.x without getting all mathematical. Instead it appears to be doing Midpoint Rounding away from zero as demonstrated here:
http://stackoverflow.com/questions/2226081/why-does-net-use-a-rounding-algorithm-in-string-format-that-is-inconsistent-wit

This means that say, 2.77 ends up being 2.8 instead of the 2.7 I want. Is there a consistent way to do this? .ToString("0.#")?

The custom numerical formats always round (up? I think?) for display. The difference between Math.Round and the formatter are that Math.Round alters the underlying value and returns it - if it is to be used elsewhere - whereas "0.00" will not return the value.

You are going to want to Math.Truncate your value and use that returned value in your display

crashdome
Jun 28, 2011
So I am looking for a bit of advice because I seem to be running around in circles from over-thinking. This is only my third WPF app and I want to be simple yet I don't want forced/bastard code ruining it this time. This current app is like others I have to build... simple (6 data tables), mostly just transactional data access (assign, add, spit some output into a table), and will have about 4-5 Views/ViewModels. I'm using EF6 because it has a designer - it's a client thing for some reason - AND I like the change tracking and the transaction/rollback features.

In previous applications I used bastardized repositories. Now, I want to explore this concept: UoW w/ No Repo

WHERE I AM HAVING TROUBLE:
I want to inject a design-time data into the ViewModel through injection. I also want to use Command/Query objects to run the transactions/queries by passing in the DBContext and manipulating Entities directly in the CQ object. I can't figure out what should be registered/injected to keep this as clean as possible. I've tried the concept registering all my CQ objects and injecting Design-time objects at design and normal objects at run-time into my VM, then I run into the problem that I have to pass a DBContext from my VM to the CQ object but the design-time doesn't use DBContext sooooo... ???? Maybe put the Conext into a run-time service instead and inject that?? If I create a basic "service" per VM and register that, I have what looks to me like a repository and I'm duplicating the CQ objects with service methods. I don't want that either.

I'm really struggling to wrap my head around a nice clean (and simple) way to get a DBContext/Entities into my VM at run-time, still use CQ objects to do all the work of doing so, AND keep my design-time data injectable (POCOs only).

Someone slap me in the back of my head please. Why is this so hard?

crashdome
Jun 28, 2011

RICHUNCLEPENNYBAGS posted:

Entity Framework is Unit of Work and I'm not a WPF whiz but you probably actually shouldn't have your view models keep references to the context.

I agree with the first part but, the article, unless I am reading it incorrectly, suggested otherwise about the second part. I'd like a suggestion if you have any thoughts.

Bognar posted:

What do you mean by bastardized repositories? Also, why don't you just use repositories where you new up a DbContext on each method call? If it's because it's not testable, then I'd say that the repositories aren't what you should be heavily testing - you should be testing the code that calls the repositories. Though, if you really cared about it you can have your DbContext implement an interface (e.g. IContext) full of IDbSets, then inject into your repositories with a factory class for IContext (a factory so you can instantiate the IContext implementation on each method call).

Actually, I know what you are saying but, it has nothing to do with testing. In fact, if I didn't want design-time data I could probably punch out the non-UI stuff really quickly. It's more about what the article is suggesting - that a repository is pretty much an abstraction of EF and redundant. My bastardized repos were basically what you suggested but since the operations were simple, I would bastardize it and make it look like a proper repository stopping short at only what I really needed to get the job done. I would create a DBContext for every operation. Each operation was to run various methods in my repository based on what my ViewModel commanded it to and maybe some items leaked in from here or there. What I discovered in trying to create a proper repository pattern is that I am basically duplicating what EF can already do in another abstraction - *for no reason other than to keep stuff away from my ViewModel*. The reasoning I am digging this article is because A) I am not going to use something other than EF on this project (and if I do in the far-far future I can easily address it because this is 6 tables we are talking about here). and B) The repository still is dependent on a DBContext anyway. Thought being... why not just remove the repository, put the Context in the VM at VM creation and while I could actually just do my operations in my RelayCommand delegates I thought it would be beneficial to pull that out into objects to prevent VM bloat and convolutions. My VM is disposed so my Context is disposed. It doesn't hang around doing various different operations like switching from major business concerns like, working Customer tables and then switching to Inventory tables. Each ViewModel deals with one specific stage of operations (all of which are tightly related). The drawback has been - and only been - that I want to inject design-time data without needing a DBContext.

I appreciate the response and it has me thinking about a possible solution. I'm working this project late tonight so maybe I'll come up with an idea and post code to get everyone's thoughts tomorrow.

Edit: I should add one of my previous possible solutions was to "new up" a DBContext in each query but, I want those Entities living for the life-time of my ViewModel to reduce building up some sort of "wire me up to the query" for data in my ViewModel. Seems easier just to have the CQ object perform operations and not be concerned about creating the context environment.

crashdome fucked around with this message at 05:34 on Oct 29, 2014

crashdome
Jun 28, 2011

Funking Giblet posted:

I use the above with the mediator pattern. I leave repositories well alone, they create constantly changing interfaces and implementations.

A mediator can figure out which query handler to use for each query, each query handler is a class that exists on its own.

code:
private IMediator _mediator;
public MyClass(IMediator mediator) //The only thing I inject, dependency graph should be shallow.
{
    _mediator = new mediator;
}

public Result SomeMethod(int id)
{
    return _mediator.Query<Result>(new ResultQuery(id));
}
I don't really care about where the query is, it doesn't belong to a repository class, the mediator works out what it needs, it's just an standalone query that I can test in isolation, and probably use any ORM I choose to fulfill T, and it has it's own dependencies. So a call to SomeMethod just ensures I new up the classes required for that query. You get horrible dependency graphs in some controllers where every action does a different thing with several dependencies, but only one may be called per request.

In MVC, I use the Ayende style session and transaction UOW management (with nHibernate). I can mock data to test for each query if I feel it requires it.

Yes! This is what I started to explore last night before I got pulled away from it. Thank you for the suggestion. I will report back when I am back on this again.

crashdome
Jun 28, 2011
I develop entirely on a Surface Pro 2 (1920x1080 10.6" screen). I have a separate 21" monitor on a workbench which helps a little when I'm debugging but, I get by.

I love it because application development is a secondary task for me and I can work on things when I'm on the bus or in-between other things at a café or whatever.

It's a whole different world from having dual monitors and a really fast PC to develop on but, if you are going to be dragging around a mobile 17" laptop because you want screen real estate you might want to consider where you are going to prop that sucker up. You'll need to constantly plug it in, have room for a mouse, etc..

Prior to the Surface, I developed on a 13.3" Fujitsu convertible. That thing was a beast compared to newer tablets/Surface Pros and being a mobile user, I never want to buy another full size laptop ever again. I can deal with not having dual screens if it means I'm not humping a gigantic rucksack full of gear everywhere.

edit: Seconding that you need an SSD no matter what. Especially if you are bouncing between other applications during development

edit2: Those Surface Pro 3s are pretty effing light. You should buy one and make me super jealous

edit3 - last one I promise: So I just found out I can use my crappy 7" android tablet as a possible second screen using iDisplay and a hidden ad-hoc WiFi signal. Lol, I'm going to buy every cheap tablet on craigslist I can find to make some weird fold out portable Franken-display.

crashdome fucked around with this message at 18:57 on Dec 8, 2014

crashdome
Jun 28, 2011
I'm pretty sure its because the usefulness would be limited. It's not like you can run full Photoshop on the iPad. Even on the surface it's not my go to input device. It's pretty rad to bust out the stylus and collapse the keyboard once in awhile though.

crashdome
Jun 28, 2011

RICHUNCLEPENNYBAGS posted:

buy a 15 or even 13 inch monitor.

Is that even possible?

Ochowie posted:

Not to go on too much of a derail of the thread but I just want to take notes on the iPad. There are such great note taking apps but all the stylii suck with writing with your finger being the only thing worse. The reason they haven't done it is because Steve Jobs hated stylus based navigation, but I don't think anyone is asking for that.

I think OneNote is awesome. I can pull them up on any tablet/phone OS too. I use it extensively with the Surface and the handwriting recognition is mostly dead on even with chicken scratch penmanship.


To keep everything on track... Blend or working with any of the designers is a huge pain in the rear end on small screens and there's no getting around it. My ideal development environment would be something like a side-ways fold out (Nintendo DS style) setup with dual screens (side-by-side) so I can keep the code on one screen and properties/solution explorer/etc on the second screen with a small flat Bluetooth keyboard that is detachable.

crashdome fucked around with this message at 05:15 on Dec 10, 2014

crashdome
Jun 28, 2011

GrumpyDoctor posted:

.NET Megathread 3.5: you won't be any more hosed than the rest of us if there's a problem.

crashdome
Jun 28, 2011
Beep bop boop double post

crashdome
Jun 28, 2011
I've done some unit testing but, I have discovered that most of my unit tests are for testing items I generally have no issues with. I guess that's good I have these in case something does go wrong at some point but, I am weighing the cost of my time in building them. What I really need is a testing framework that is all integration testing. Most of my projects have complex business logic and rely on other devices communication habits. Occasionally I unit test things like: are all properties being assigned to that struct on each of those methods? Yes? Good. Which is great. Never fails. Ever. No matter how many months I've been working this project.

Where 99% of my bugs are though... integration. Problems with I/O timing, spelling errors in strings I send over serial ports, Bit/Byte conversion on lengthy packets of data. Changed out my whole framework of serial port behavior because New Protocol(TM) (they said we'd never have to implement another new protocol ever again 6 months ago) and now I need to know if all the previous protocols still function over the communications framework. :suicide:

Unit Testing and TDD cover like 2% of my problems.

crashdome
Jun 28, 2011

wwb posted:

@crashdome -- my most successful testing has got things to the point where we know our side of the app works. So when it comes to debugging those nasty integration issues we can focus a lot better as we know one side of the equation is likely fine. Especially with outside vendors involved who want to throw your code under the bus because their code is of course "perfect" and "battle tested". Another side effect is if you can get good at simulating infrastructure you can make your code behave predictably when it fails, including firing off "this is wrong and this is what you need to look at" messages in the log.

Unfortunately, my side is the only side that changes. Most of the issues are engineers expecting me to know exactly what a product does and why even though I don't know what the hell the product is even for half the time. I do have a solid messaging framework for the operators. It helps when they call with an unexpected problem. It's the massive amounts of weird edge cases I have to deal with because a product behaves wildly different than another product for some ungodly reason I don't understand without an hour long explanation. I end up doing Thread.Sleeps and IF-THEN cases everywhere until I have time to come back and refactor after the procedure is proven to work.

I have started simulating infrastructure but, a full test suite would double my time. I've got a small simulation app to do manual tests though and that cuts through half the bullshit.

crashdome
Jun 28, 2011

mastersord posted:

I apologize in advance for sounding like an inexperienced moron. I am in the process of trying to upgrade all our in-house code from VB6 to VB.NET and since we're so small, no one really knows anything about visual Studio past VS99 or whatever was the last VB6 release. I am trying to catch up on the last 10-15 years of advances on my own.

Why does it seem like everyone is making web apps as opposed to local apps? In my shop we have no need for any special internet applications outside of the browser and with HIPAA we have little to no reason to unnecessarily expose our data to the internet more than required.

Am I mis-interpreting what MVC does?

Welcome to present day.

Here's what you're going to learn:

VB.NET is not even remotely close to VB6
Your going to have to completely rewrite everything.
Your concept of programming is antiquated and everyone hates it and if you continue to rewrite your software using old methods, young developers will never want to maintain your software.

I'm not trying to be snarky or cruel but, as a person hired to update VB6 programs to present day technology, it is going to take your VB6 devs well over a year to come to grips with everything new. You'll be far more comfortable and it will be far more cost effective if you hired up-to-date developers and just let them build what you need for you.

Internet != HIPAA violation
Web technology is far more flexible. Personally I build and prefer standard applications (now WPF) but even I have to embrace there's always going to be overlap between Web and Native applications.

crashdome
Jun 28, 2011

mastersord posted:

The differences are more prevalent in how form controls work and also going from ADODB to ADO.NET.

Just wait until you see LINQ and Lambda Expressions!

crashdome
Jun 28, 2011
I've been using a practice of my own for well over a decade and I want to run it past everyone to see if I am behind the times or something.

Basically when you have a Parent->Child relationship in SQL where the Parent is more or less a description and the children are transactions, I leave cascading update/deletes open in SQL for ease of maintenance by the DBA or if there is an archiving feature or something. Sometimes I don't want to let a user delete a Parent and the entire history with it by accident in an application. To handle this in the past, I used to query the parent and children and then create a property to allow deletion. This property was dependent on the children being returned from the database and carried along with the parent object. I had my own type which was a three-phase Boolean. It basically returned CanDelete/NoDelete/NoData with NoData being returned if the children were lost or never returned from the database. This allowed me to choose what to do (e.g. reQuery, force delete, etc..) depending on the context at the moment.

Fast forward and I am using the Nullable Boolean instead. It works great because of the method GetValueOrDefault(T) which returns a value if it HasValue or a default value so you can choose what to do when Null. I've been using this like crazy. Problem is I am also using other Nullable types to represent Sums, Averages, Counts, etc... for display so for example:

code:
class MyModel
{
	ObservableCollection<Children> Transactions;

	public bool? CanDelete
	{
		get
		{
			return (Transactions.Count > 0 ? {Retrieve a bool if any transactions are of a certain type which should prevent delete} : Null);
		}
	}

	public decimal? TotalRemaining
	{
		get
		{
			return (Transactions.Count > 0 ? {Retrieve a sum} : Null);
		}
	}
}

class MyViewModel
{
	...Some Property for a Delete Command
	{
		//This method ensures if for some reason there are no transactions available it will not allow delete for safety because in this circumstance
		//every myModel should have a minimum of one transaction and if there are none, there is something inherently wrong
		//Alternatively, I could supply a default of true in the event I want to let the user delete something with no tranasactions.
		return myModel.CanDelete.GetValueOrDefault(false);
	}

	public decimal TotalRemaining
	{
		get
		{
			//Defaults a display of -1 which in this case, indicates to the user there is something in error - I don't want to halt 
			//or throw an exception because I actually want to leave it up to the user on how to deal with it. Maybe they delete 
			//or edit the object to correct the problem. Or maybe they bring it up to an administrator
			//Or maybe in a completely different ViewModel I throw an exception instead of using GetValueOrDefault
			return myModel.TotalRemaining.GetValueOrDefault(-1);
		}
	}
}
So you see in the comments the point is that in most of my use cases an exception is overkill and I want the application to resume, correct itself, or let the user decide. Oddly, most of these nullable Booleans are for safety and, almost never get used because *waves magic wand* all is right with my data layer. The other values just simplify displayed data and let my ViewModel deal with any errors in the way I want each ViewModel to handle it.

Is this bad? I have Nullable fields on almost all of my models similar to the above. It seems solid but, I have a nagging feeling I am overusing Nullable types and trusting something too much. Like they are inherently dirty and will stab me in the balls when I'm not looking.

crashdome
Jun 28, 2011

Scaramouche posted:

Any of you guys ever had to programmatically connect to Google drive and grab the content for use/insertion into a database?

I've never done Google but, I've done Excel from Office 365 using basic Office libraries and one step even better... I programmatically pull data from an Access Web App that has a UI front end for data entry. It's basically as simple as a SQL connection to a free azure hosted database.

crashdome
Jun 28, 2011
Are you creating new directories for scratch data and then dumping them all within a second? That seems awfully awful.

chippy posted:

In WinForms, if I've got a ListBox showing a list of entities, and I want to update this listbox with a fresh list I just pulled out of the database, what's the 'best practice' way of doing this?

More specifically, I want to maintain the selection. If an item is selected in the list and is still in the list after the update, it should remain selected. It it's removed I guess the selection should jump back to the first in the list, or maybe the previous.

Just changing the DataSource property to the new collection will reset the selected item as well. I'm guess I should be using a BindingSource or something like that?

From my horrible WinForms memory:
You'll have to store a key or some way to lookup the object in the new datasource, find the index, and reset the selected index if you choose to change the datasource. - This is the fastest for large lists but the change in datasource may cause UI flickering or some other weird behavior if you hold object references.
The alternative is to have a single datasource that you add or remove items by comparing your refreshed data with the existing data.

Either way you go, if the list is small (say <1000 items), you wont see any performance problems. Although, I recommend keeping a single datasource and updating it yourself manually if it is only ever "read only" list. You can use the datasource methods to perform lookups and object comparisons. For example, with a single datasource, you can grab a reference to the selected object prior to refresh, see if it exists in the datasource when refreshed and if not, just set selected index to 0 (assuming there is always at least one item) and leave well enough alone. Its pretty simple too...

[*]Clone your datasource as a new list of "To be deleted" and make an empty "to be added" list
[*]Traverse the refresh list, compare items, and remove existing items from the "delete list" while also adding new items to the "to be added" list
[*]Remove and add each list as a range from your datasource

This has, for me, been the most effective and smooth way to do it and keep the UI responsive.

crashdome
Jun 28, 2011

chippy posted:

Thanks for this. When I used the List as the datasource for the ListBox directly, it didn't seem to update the display of the listbox as I added and removed items. I ended up creating a BindingSource with the list as its datasource, and then using that as the datasource for the listbox. Once I did it that way, it kept up with any items added or removed, and also took care of maintaining the selection automatically.

Yeah, BindingSource is great. A list doesn't have any INotify ....blah blah... so you'd have to call Suspend, Resume, Refresh on the listbox control manually during the update. Thanks for reminding me how much I don't miss WinForms.

crashdome
Jun 28, 2011

fleshweasel posted:

Has anyone written a tool to go through a source file and do this?


Inverness posted:

ReSharper can do it.


NihilCredo posted:

Yes, the find / replace tool. This is a great place to use a regular expression.


No Safe Word posted:

Use VsVim and write a vim macro to do it :getin:


There's got to be a "How many programmers" joke somewhere in all of this.

crashdome
Jun 28, 2011
I'll disagree with RangerAce a bit. I've taken to using EF Entities as models in my viewmodels directly because they are perfect.

I've also not had a problem using multiple entity sets to a single table. Can you post your code? or an example?

e: Are there relations to other tables? This might be the problem. I have a legacy datatable where there were multiple columns for different row types but, there are no foreign keys. Alternatively, you could also try mapping entities to unique SQL views or sprocs named differently.

crashdome fucked around with this message at 01:23 on Feb 28, 2015

crashdome
Jun 28, 2011
Entity Framework uses Entities/Entity Sets not strongly-typed Datatables/Datarows.

Simply use linq to Enumerate/Sort at the DB level instead of.... and.. Why clone the data into datatables of all things?

bobua posted:

I have to be making this harder than it is...

I want to take a strongly typed datatable and group\order it into another datatable. So far, without grouping I do this...

code:
var res = (from table in datatable
		select table).ToList();
res.OrderBy(x => x.FirstName);
res.ForEach(x =>
{
	var newrow = OtherDatatable.NewOtherDatatableRow();
	if(!x.isFirstNameNull()) { newrow.FirstName = x.FirstName; }
	if(!x.isCompanyNameNull()) { newrow.Company = x.Company; }
	OtherDatatable.Rows.Add(newrow);
}

Do you realize this code above takes a generalized SQL statement (e.g. "select * from myTable") and runs it on the database and then below that you spend a great deal of time sorting it and then cloning it to some other table when you could just...

code:
//Generates a query with all your requirements
var res = from table in datatable
		orderby (x => x.FirstName)
		group table by table.FirstName into g
            	select new
            	{
              		FirstName = g.Key.FirstName,
			Total = g.Sum(x= > x.Cost)
            	};
		
//Executes Query and give you just the list you want
res.ToList();
Untested of course but, should be the general direction you should go.

crashdome
Jun 28, 2011
App.Config question:

I have a WPF Application with a single project for ViewsVMs/Services/Etc. I also have two additional projects referenced by the main project. Each sub-project is basically an EF Project each with it's own connection string and data models.

When I build the solution, the connection strings are not merged up in to my main project App.Config. What am I doing wrong?

Optionally, is there a way I can have a single App.Config all projects can reference without EF wizard complaining a connection doesn't exist?

crashdome
Jun 28, 2011
:science: Custom Tokens are cool!

Adbot
ADBOT LOVES YOU

crashdome
Jun 28, 2011
It amuses me that to any layperson googling, .NET programming is centralized 100% around blog development and the occasional Customers/Orders/Products involved in Foo & Bar sales.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply