« first day (2184 days earlier)      last day (2766 days later) » 

12:11 AM
@Tomwa You aren't calling any unmanaged code, are you?
 
Nope, pure Managed C#. Not dealing with unloading in anyway
No finalizers, destructors, etc.
God this is frustrating
 
12:30 AM
Hi All! Let's talk Linq.
 
:(
 
I have a sql table of tires. It has a status field, a tireID fiield, and a date field.
One of the statuses is Discarded. A tire can be in Discard status more than once. In that case it would have multiple rows with its tireID in the table.
Using Linq, how to you get the most recent row with a Discard status?
In SQL you could do something like group by tireID and Status having max date.
Hey Kendall, I could use some occasional help with this project. Are you available via skype, or do you know someone that could mentor here and there?
 
12:55 AM
@ChristopherJ.Grace isn't that just a Where and an orderByDescending?
 
You'd think, huh. if it's that simple I'd better just go to bed or something. Sheesh.
 
What do you have then?
 
I also need to make sure that it was not already in discard status before the date range.
 
So you need it before and after a specific date as well?
 
1:08 AM
I assume you mean something like this,

tires.Where(tire => (tire.id == 2) && (tire.status == Status.Discarded)
&& (tire.date < new DateTime(2006,1,1))
&& (tire.date > new DateTime(2001,12,1))).OrderByDescending(tire => tire.date).ToList();
You can do it with the query syntax too, not sure it would be any prettier though
Before
ID: 1 Status: Discarded Date: 3/25/2011 12:00:00 AM
ID: 2 Status: Discarded Date: 11/9/2012 12:00:00 AM
ID: 3 Status: Discarded Date: 8/1/2015 12:00:00 AM
ID: 0 Status: Discarded Date: 9/16/2000 12:00:00 AM
ID: 1 Status: Discarded Date: 3/23/2006 12:00:00 AM
ID: 2 Status: Discarded Date: 6/21/2001 12:00:00 AM
ID: 3 Status: Discarded Date: 8/30/2005 12:00:00 AM
ID: 0 Status: Discarded Date: 11/7/2005 12:00:00 AM
ID: 1 Status: Discarded Date: 9/20/2002 12:00:00 AM
ID: 2 Status: Discarded Date: 8/10/2003 12:00:00 AM
@ChristopherJ.Grace that seems to work, is that what you want?
If you just wanted the first you could do:

tire ti = tires.Where(
tire => (tire.id == 2) && (tire.status == Status.Discarded) &&
(tire.date < new DateTime(2006, 1, 1)) &&
(tire.date > new DateTime(2001, 12, 1)))
.OrderByDescending(tire => tire.date).First();
Replacing the constants with your variables ofc.
 
1:24 AM
That's pretty nifty, but TireID 2 should not be included because it has a discard before the start date.
 
Ohhhhhhh
I getcha
If it was discarded before the start date don't include it
Any other restrictions?
 
That's pretty much it. In SQL there could be a not exists select statement in the where clause.
 
Is the end date a thing as well?
 
This can be a very large table though, so it probably doesn't help performance to have to scan by date more than once.
 
You shouldn't have to, you can negate a Where statement
 
1:32 AM
No, basically we are just looking for tires that were discarded within the date range, and only not earlier.
If they were brought back, and then discarded again at a later date, querying my that later date range would omit it from the results.
 
And the ID also has to match right?
 
1:46 AM
Alright
        IEnumerable<tire> tiresOld = tires.Where(t => (t.date < new DateTime(2005,1,1)) && t.status == Status.Discarded);
        HashSet<int> set = new HashSet<int>(tiresOld.Select(t => t.id));
        IEnumerable <tire> tiresNew = tires.Where(t => !set.Contains(t.id));
Oh hold on
Didn't adjust the foreach
 
@Tomwa I searched around for some answers on your problem. That's a tuff one.
 
Before
ID: 1 Status: New Date: 4/24/1999 12:00:00 AM
ID: 2 Status: New Date: 3/10/2004 12:00:00 AM
ID: 3 Status: New Date: 4/11/1998 12:00:00 AM
ID: 4 Status: New Date: 6/2/2009 12:00:00 AM
ID: 5 Status: Discarded Date: 1/25/1995 12:00:00 AM
ID: 6 Status: New Date: 2/11/2011 12:00:00 AM
ID: 7 Status: Discarded Date: 6/16/2001 12:00:00 AM
ID: 8 Status: Discarded Date: 10/28/2000 12:00:00 AM
ID: 9 Status: Discarded Date: 3/15/2013 12:00:00 AM
ID: 10 Status: Discarded Date: 11/24/2015 12:00:00 AM
ID: 11 Status: New Date: 7/2/2002 12:00:00 AM
It's a little wonky due to the random dates (Time travelling tires?)
But as you can see they no longer re-appear
        IEnumerable<tire> tiresOld = tires.Where(t => (t.date < new DateTime(2005, 1, 1)) && t.status == Status.Discarded);
        HashSet<int> set = new HashSet<int>(tiresOld.Select(t => t.id));
        IEnumerable<tire> tiresNew = tires.Where(t => !set.Contains(t.id)).OrderByDescending(t => t.date);
Yeah, not sure I might have to buy a book on WPF/Garbage Collection been having that issue for months
Aw crap, forgot to filter only discarded
Before
ID: 1 Status: New Date: 2/23/2011 12:00:00 AM
ID: 2 Status: Discarded Date: 1/26/2011 12:00:00 AM
ID: 3 Status: New Date: 10/27/2007 12:00:00 AM
ID: 4 Status: Discarded Date: 3/10/2000 12:00:00 AM
ID: 5 Status: New Date: 3/10/2001 12:00:00 AM
ID: 6 Status: New Date: 5/21/2003 12:00:00 AM
ID: 7 Status: Discarded Date: 6/10/2002 12:00:00 AM
ID: 8 Status: New Date: 12/10/1996 12:00:00 AM
ID: 9 Status: Discarded Date: 2/4/2009 12:00:00 AM
ID: 10 Status: Discarded Date: 2/8/2003 12:00:00 AM
ID: 11 Status: Discarded Date: 5/20/2007 12:00:00 AM
 
@Tomwa Did you check in with Roy T regarding his post? stackoverflow.com/questions/37476695/…
 
        IEnumerable<tire> tiresOld = tires.Where(t => (t.date < new DateTime(2005,1,1)) && t.status == Status.Discarded);
        HashSet<int> set = new HashSet<int>(tiresOld.Select(t => t.id));
        IEnumerable <tire> tiresNew = tires.Where(t => !set.Contains(t.id) && t.status == Status.Discarded).OrderByDescending(t => t.date);
I did, if you look I even left a comment.
Does that query do what you want it to?
 
@Tomwa I was checking for that, but must have missed it.
@Tomwa It looks pretty close mister :) I'm checking it out now.
 
1:58 AM
The dates are random so it looks a little wonky
 
@Tomwa That's pretty cool how you generated the test data so fast.
 
I just bumped out some very very ugly test functions lol
 
I could probably improve a lot by going to one of those hackathons.
 
I mostly struggle with lowlevel things, despite being having written MSIL\Assembly
 
More and more just keeps building in top of it.
That's some really interesting Linq. I'll have to study up on HashSets. Thanks for spending the time on it!
 
2:06 AM
Seems pretty quick
Printing takes foooooooooooooooorever with 1,000,000 elements but the query is quick
Basically I just found the ones I didn't want, added them to a hashset to make excluding them faster and said "Everything that isn't one of those and that has been discarded"
Then order them by date in descending order
I'm curious to see if WPF is the culprit but I can't remember if I checked that before and I don't want to convert from WPF -> Winforms/Console for nothing.
 
i appreciate it Tomwa. I was just looking for a StackOverflow feature where you could favorite people who write good answers and ideas, but sadly there's no built in way to do that.
What about the new Universal Apps? I think they are still using XAML, but have not gotten to work with it much.
Time for dinner. Thanks buddy :)
 
2:22 AM
@ChristopherJ.Grace NP, cya later.
 
 
1 hour later…
3:50 AM
@ChristopherJ.Grace I'm available here.
 
 
5 hours later…
9:18 AM
Yawn
@KendallFrey I fixed my Crash, switched from WPF to WinForms and it's completely gone.

Any reason why such might be the case? Maybe a difference in threading or thread management?
 
 
3 hours later…
11:52 AM
sigh
 
 
1 hour later…
12:58 PM
@Tomwa winforms? gah
 
Hello, I have a Csharp project where a user can type in a certain word like a command and it will do something, I want to create something to only allow them to do a command every 3 seconds so that they cant spam it, what is the best way to do this? hold a dictionary with the string and the last time they did it (datetime) and time it? any ideas?
 
@LiamHardy Dictionary sounds like a good approach
 
@KendallFrey "Gah" is what I say to random, unexplained crashes ¯_(ツ)_/¯
It's either Winforms, or a console window. That or fixing whatever is wrong with WPF in this instance
 
switching from WPF to WinForms should be prosecutable
 
Evidently XNA doesn't play nicely with WPF
 
1:14 PM
Why are you mixing the two, anyway?
 
1:28 PM
Stardew Valley is a game written in XNA
I wrote a program that manipulates it, adds various APIs, loads mods into their own Appdomains so they won't crash the main program, etc.
I wrote the form from which you install, view, configure, etc. mods in WPF
I might just throw the form out and inject one into the game.
 
1:47 PM
Hey, does TryGetValues method on a dictionary return false if they couldn't find it? am I correct in thinking this? I run a null check when it returns the value but I am thinking of removing that if it just returns false if its null anyway and I can just handle the null and failing in 1 if statement..
example I changed

this: https://gist.github.com/anonymous/c710b86d6fe87ea880548f3067516a0c
to: https://gist.github.com/anonymous/a38f0db8e751daea361ef276e32b3b52
 
New to MVC and Entity Framework. Lets say I have a table in SQL Server with 2 fields, Username and Password. Lets say I generate class for this table in c#. Do I reuse the said class for both registering and logging in the system?
 
@LiamHardy Yes it does.
 
@Tomwa Thanks :) good to know!
 
hi guys i have a question
some people create an access file
 
Just ask it then
 
1:53 PM
then they change extention of that access file to .dll
they they connect that .dll with c#
how how they can do that?
 
You can't just change the extension to DLL it won't be a valid library.
 
i have seen
i can give you an example if you want
 
That would help
 
Um, hey guys, um, I've been on quite a long hiatus from coding... but I'm back now. Can anyone recommend a good book to 'revise' C#?
 
2:00 PM
thats the database of a dictionary named Qaslan
which created with access
then changed its extention to .dll
then connected VB with that dll
i can give you the download link of that Dictionary if you want
 
That's not a valid DLL, PEVerify says it's not a PE File.
It's likely that the .dll extension isn't necessary.
In what way is it used in VB?
 
just download it
then change uts extention to .mdb
then open it
if you have MS Office
 
Yeah, it's a valid mdb file
You should be able to load it regardless of it's extension, unless the program looks for a specific extension
The extension doesn't change the file in any way
How does it get used in code?
 
how the owner of that dictionary could connect VB with .dll
HEHE
i want know that
 
"connect VB with dll" doesn't say much. You can load .mdb files using C#\VB\.NET, as a database.
you could rename it dic.pizza and still load it, as long as you gave the right filename to the program.
 
2:08 PM
really?
means if i publish the program dosnt matter what is its extention
i mean extention of the access db
 
Yes, the extension doesn't change the contents of the file.
i.e. take a text file name it "dic.dll" and open it with notepad.
It's still only a text file.
 
but if i change the extention
what about the connection string
how it can work
 
Typical connection string looks like this:

string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\Access.MDB";
Changing the extension just makes it look like this:

string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\Access.dll";
 
are you sure that works correctly?
i try with it
thanks
 
You have to make sure it works with your version of Access, that you setup OLEDB correctly, etc.
 
2:13 PM
i dont know mutch about connecting c# with access
 
@HamreenAhmad Here's a sample in C#:

https://stackoverflow.com/a/18508312/2828986
 
thanks Man
before it i have used UCanAccess in Java
:)
@Tomwa what is the difference between using ADOX or OLEDB
i want my app be portable
 
Portable between?
What language are you writing in?
 
c#
share it on net
people can use it
 
So you'd use OLEDB and rely on Mono for cross platform support.
Your database has a password on it
 
2:22 PM
yes
 
If you give me a sample database without a password (or with one you can give me) I'll see if I can whip up a solution real quick.
 
thanks
i would like try with it for now
later maybe
 
K good luck
 
2:43 PM
@HamreenAhmad I did manage to get it to connect and read the data in a test database, let me know if you have questions.
 
 
3 hours later…
5:25 PM
Um, hey guys, um, I've been on quite a long hiatus from coding... but I'm back now. Can anyone recommend a good book to 'revise' C#?
 
5:58 PM
@Tomwa How come you didn't go with the UWP solution? Just testing?
 
UWP is only available on Windows 10
I.E. Windows 8/7 users (most of the people on PC) would be S.O.L.
@ChristopherJ.Grace I gave it a look though.
 
 
5 hours later…
10:48 PM
UWP is great. I develope all my apps with UWP. I can switch my apps between my Laptop with Windows 10 and my Pi3 with Windows 10 IoT Core. It's very helpful for me.
Hey
 

« first day (2184 days earlier)      last day (2766 days later) »