|
Here is a very vague question... How is C# for text parsing and regex expressons? I'm a non-programmer trying to help out at work, and we have a 60,000-line data log that I'd like to write a tool for and distribute to my coworkers. They'd input a user ID, and the program would parse the log pulling out relevant information. I'm a Python rookie and I think I could accomplish it in Python but I'd like to learn a language that is easily distributed in the Windows environment.
Hughmoris fucked around with this message at 01:47 on Feb 28, 2015 |
# ? Feb 28, 2015 01:39 |
|
|
# ? May 23, 2024 16:27 |
|
Hughmoris posted:Here is a very vague question... How is C# for text parsing and regex expressons? I'm a non-programmer trying to help out at work, and we have a 60,000-line data log that I'd like to write a tool for and distribute to my coworkers. They'd input a user ID, and the program would parse the log pulling out relevant information. I'm a Python rookie and I think I could accomplish it in Python but I'd like to learn a language that is easily distributed in the Windows environment. Incredibly good. Python and C# are my two favorite languages because they both feel just as flexible as eachother out of the box (C# has the wonderful enumeration library and generally a lot of helper libraries/functions) and I use C# primarily now for the same reason you just said, it's easily distributed. Also typed languages are so much nicer than untyped at this point, not to mention the intellisense is great and the compiler errors are helpful.
|
# ? Feb 28, 2015 01:54 |
|
Hughmoris posted:Here is a very vague question... How is C# for text parsing and regex expressons? I'm a non-programmer trying to help out at work, and we have a 60,000-line data log that I'd like to write a tool for and distribute to my coworkers. They'd input a user ID, and the program would parse the log pulling out relevant information. I'm a Python rookie and I think I could accomplish it in Python but I'd like to learn a language that is easily distributed in the Windows environment. It's fine, but PowerShell might be more up your alley as a non-programmer. PowerShell has regex operators built right in. http://www.powershelladmin.com/wiki/Powershell_regular_expressions
|
# ? Feb 28, 2015 02:01 |
|
EssOEss posted:That is foo.SomethingHappened += bar.EventHandler makes foo hold a reference to bar but not the other way around. If bar sets all references to foo to null, it will go away (provided that no other references exist). In case the handler is a closure, foo just gains a reference to the closure object that the compiler generates, which may in turn contain references to other objects. And if your closure is referencing the event publisher (or other objects that reference it), you've created a cycle which can cause a memory leak. The garbage collector in .NET is generally pretty good about culling reference cycles that are disconnected from the object graph but, for example, the garbage collector in Mono isn't.
|
# ? Feb 28, 2015 02:12 |
|
rarbatrol posted:Okay, cool. Thanks. I wasn't sure how tasks crossed that boundary. I imagine something like: var data = await controller.Action(); return this.Serialize(data);
|
# ? Feb 28, 2015 05:50 |
|
Bognar posted:And if your closure is referencing the event publisher (or other objects that reference it), you've created a cycle which can cause a memory leak. The garbage collector in .NET is generally pretty good about culling reference cycles that are disconnected from the object graph but, for example, the garbage collector in Mono isn't. Ouch, really? Can you give some useful links that explain the trouble spots? We are just startng to use Mono at work and this sounds like something that we need to become aware of!
|
# ? Feb 28, 2015 09:15 |
|
crashdome posted: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'll try. I have 3 tables in my model: tblEmployers, tblShops, and tblEmployees. An employer can have 1 or more shops. A shop can have 1 or more employees. I have a form with 2 ComboBoxes, a dataGrid, and a search button. ComboBox 1 (me.comEmployers) has a list of employers. I want to populate comboBox 2 (me.comShops) with a list of shops belonging to the selected employer by ID. I could populate the box through box 1s "selectedIndexChanged" event, but I want the display property to show both the number (not the shopID primary key)and name with a hyphen between them. Something like this: code:
I could create the objects in the database but I was wondering if I could avoid doing that. mastersord fucked around with this message at 22:23 on Feb 28, 2015 |
# ? Feb 28, 2015 22:01 |
|
Jewel posted:Incredibly good. Python and C# are my two favorite languages because they both feel just as flexible as eachother out of the box (C# has the wonderful enumeration library and generally a lot of helper libraries/functions) and I use C# primarily now for the same reason you just said, it's easily distributed. Also typed languages are so much nicer than untyped at this point, not to mention the intellisense is great and the compiler errors are helpful. Thanks, that's good to hear. Ithaqua posted:It's fine, but PowerShell might be more up your alley as a non-programmer. PowerShell has regex operators built right in. I don't know a ton about powershell but would there be an issue deploying powershell scripts on Windows XP computers? Or would I have to do some tinkering to get it to work?
|
# ? Feb 28, 2015 22:26 |
|
Hughmoris posted:Thanks, that's good to hear. Yeah you'd have to install powershell on the older machines, set up permissions, etc. Might be easier to just do a one-click installer or spread an exe around if you're comfortable with deploying that yourself.
|
# ? Mar 1, 2015 01:04 |
|
Scaramouche posted:Yeah you'd have to install powershell on the older machines, set up permissions, etc. Might be easier to just do a one-click installer or spread an exe around if you're comfortable with deploying that yourself. Might be worth to deploy PS. Once you've used it you'll probably see all kinds of possibilities
|
# ? Mar 1, 2015 14:27 |
|
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:
Now that I want to do a GroupBy and Sum, I'm lost. I tried code:
|
# ? Mar 2, 2015 04:39 |
|
If you're using EF why do you have to even do it with data tables?
|
# ? Mar 2, 2015 04:42 |
|
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... 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:
|
# ? Mar 2, 2015 05:32 |
|
crashdome posted:Entity Framework uses Entities/Entity Sets not strongly-typed Datatables/Datarows. I couldn't figure out how to check if the field was null when trying to do the orderby within the query, kept getting strongtypingexceptions. Doing the orderby afterwards on the list seemed to get around that. I'm working with datatables because the original program did all of it's work in stored procedures while storing all of the results in the database, the new program needs to continue to use the stored procedures\results to database, but also import\export the data and run the same calculations without the use of the stored procedures.
|
# ? Mar 2, 2015 06:03 |
|
bobua posted:I couldn't figure out how to check if the field was null when trying to do the orderby within the query, kept getting strongtypingexceptions. Doing the orderby afterwards on the list seemed to get around that. I think there's a better way to work with SPs, but don't quote me. Anyway, yeah, for the null thing, why not just .Where( x => x.sortProp != null).OrderBy(x => x.sortProp.Value) or whatever?
|
# ? Mar 2, 2015 06:37 |
|
crashdome posted: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. For Windows Forms data binding, you can use BindingList<T> (or the IBindingList interface), which supports all the list changed events you'd care about, and is natively supported by BindingSource and all the built-in controls. It's basically the WinForms version of WPF's ObservableCollection.
|
# ? Mar 2, 2015 11:24 |
|
bobua posted:EF stuff I am still learning EF so I could be talking straight out of my rear end here. It's been suggested to use LINQ but why not use straight SQL and the "SqlQuery" method? In SQL server we use "IsNull" in the Order By clause to substitute a value into Null valued-columns when we need to sort them (i.e. "0" or some ridiculously high number depending on where we want them sorted to).
|
# ? Mar 2, 2015 15:36 |
|
I am pretty sure you can just do "myrow.mycolumn ?? 0" in LINQ to Entities queries, as well. Granted, I do not specifically have proof of this scenario in front of me but I have worked with null values before using EF and do not recall any particular problems or missing features.
|
# ? Mar 2, 2015 16:33 |
|
Since we don't have a Windows Store specific thread, I'll guess I post this stuff here :shurg:. Microsoft talked a little bit about Windows 10 universal apps at MWC. Some of the Windows Phone APIs are going to be deprecated and made consistent with Windows itself. So DoSomethingAndContinue will be going away . It also seems like there will be more to have true cross-platform XAML support, with hopefully less conditional "#if WINDOWS_PHONE_APP" logic and more XAML solutions. They also showed off Xbox One Universal apps as well. Gets me a bit amped for Build. Just months away from Awful Forums Reader on XB1
|
# ? Mar 2, 2015 17:46 |
|
Speaking of apps, it irritates me that WinRT and its special C++/CX language even exists. Why couldn't Microsoft have dropped their internal conflict bullshit before W8.
|
# ? Mar 2, 2015 19:39 |
|
RICHUNCLEPENNYBAGS posted:I think there's a better way to work with SPs, but don't quote me. Well, I don't know what I'm talking about but as far as I know, checking the field for null throws the exception, so you can't do that... you have to use the generated helper method to check if it is null instead of checking it directly. This works fine for me in most cases, but you lose that helper method when you group the data. I also don't know how to use that helper method when doing an order by\group by within the query. My guess at the syntax was something like code:
|
# ? Mar 2, 2015 20:32 |
|
Are you serious? EF entities don't just return null if you access a nullable property that contains null? Also, table is not a good name in that context. You are working with individual records, not tables, so it's better to say something like for chair in chairs or for butt in butts. You're treating this like the SQL database doesn't exist? What do you mean by that?
|
# ? Mar 2, 2015 21:18 |
|
fleshweasel posted:Are you serious? EF entities don't just return null if you access a nullable property that contains null? Also, table is not a good name in that context. You are working with individual records, not tables, so it's better to say something like for chair in chairs or for butt in butts. If you have the property set to nullable, yes. Properties like datetime can't be set to nullable though. Because while the program originallly get's it's data from an sql database, it saves(and reimports that data to xml files). Each strongly typed datatable is a different step in a long process. Sometimes the tables need to be mixed an matched... table 1 from live database, table 2 from an xml file, resulting table pushed back up to the database... etc. It's always different.
|
# ? Mar 2, 2015 21:44 |
|
fleshweasel posted:Are you serious? EF entities don't just return null if you access a nullable property that contains null? Also, table is not a good name in that context. You are working with individual records, not tables, so it's better to say something like for chair in chairs or for butt in butts. They do but he's not using them apparently.
|
# ? Mar 3, 2015 04:04 |
|
bobua posted:If you have the property set to nullable, yes. Properties like datetime can't be set to nullable though. If your database column is a nullable datetime but in code you have a non-nullable datetime, your model is wrong.
|
# ? Mar 3, 2015 08:36 |
|
bobua posted:If you have the property set to nullable, yes. Properties like datetime can't be set to nullable though. Can you stop using DataTable? It's a very leak abstraction and I think you are having trouble because you are using three different technologies, DataTable, EF, and LINQ-to-objects. My suggestion is to make a POCO (Plain Old CLR Object) model, have each step project the data into your POCO model, do your model mutations, then project that into the database. At the very least dumping DataTable will probably help out. Also, posting more code could be helpful but I think is more of an architecture problem than a coding error problem. You could also move to something like SSIS (SQL Server Integration Services) or some other ETL (Extract, Transform, Load) system.
|
# ? Mar 3, 2015 15:56 |
|
gariig posted:Can you stop using DataTable? It's a very leak abstraction and I think you are having trouble because you are using three different technologies, DataTable, EF, and LINQ-to-objects. My suggestion is to make a POCO (Plain Old CLR Object) model, have each step project the data into your POCO model, do your model mutations, then project that into the database. At the very least dumping DataTable will probably help out. Also, posting more code could be helpful but I think is more of an architecture problem than a coding error problem. I probably can stop using datatable in the long term. I think you're right on this just being an architecture problem, but I needed something done in a week without being allowed any changes to the database, and it doesn't help that this is really the first time I've used sql, datatables, or linq... In any case, I got it working last night with a mix of 'sanitizing' the table before grouping and removing some of the original(stored procedure) author's grouping that wasn't actually necessary.
|
# ? Mar 3, 2015 19:11 |
|
Anyone here interested in teaching .NET/C#? We looking for a new teacher at Treehouse. I can vouch for it being an awesome place to work. PM me with any questions. Sorry if this isn't the right place to post.
|
# ? Mar 4, 2015 00:57 |
|
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?
|
# ? Mar 4, 2015 02:09 |
|
crashdome posted:App.Config question: Building doesn't merge the app.configs. However, you can have one app.config reference an external file (example).
|
# ? Mar 4, 2015 02:19 |
|
bobua posted:I probably can stop using datatable in the long term. I think you're right on this just being an architecture problem, but I needed something done in a week without being allowed any changes to the database, and it doesn't help that this is really the first time I've used sql, datatables, or linq... You don't need to change the table to use real entities.
|
# ? Mar 4, 2015 02:31 |
|
For performance on a script that parses a 60,000+ line text file, does it really matter what method I use to read in the file and iterate over each line? Poking around C# tonight and it looks like there are quite a few different ways to read in files. Is there a standard method I should be using to read and write files, excluding special cases?
|
# ? Mar 4, 2015 03:16 |
|
Hughmoris posted:For performance on a script that parses a 60,000+ line text file, does it really matter what method I use to read in the file and iterate over each line? Poking around C# tonight and it looks like there are quite a few different ways to read in files. Is there a standard method I should be using to read and write files, excluding special cases?
|
# ? Mar 4, 2015 03:17 |
|
Drastic Actions posted:Since we don't have a Windows Store specific thread, I'll guess I post this stuff here :shurg:. Microsoft talked a little bit about Windows 10 universal apps at MWC. Some of the Windows Phone APIs are going to be deprecated and made consistent with Windows itself. So DoSomethingAndContinue will be going away . It also seems like there will be more to have true cross-platform XAML support, with hopefully less conditional "#if WINDOWS_PHONE_APP" logic and more XAML solutions. They also showed off Xbox One Universal apps as well. Is there a source what what WP APIs are dead?
|
# ? Mar 4, 2015 03:52 |
|
Factor Mystic posted:Is there a source what what WP APIs are dead? Not yet, they just mentioned that the APIs are going to be folded together at MWC. So we'll find out more at build.
|
# ? Mar 4, 2015 03:57 |
|
Drastic Actions posted:Gets me a bit amped for Build. Just months away from Awful Forums Reader on XB1
|
# ? Mar 4, 2015 04:04 |
|
Inverness posted:Use a stream and text reader. Do not be one of those idiots that loads the entire file into memory at once. Doesn't File.ReadLines give you an iterator that streams the file into memory one line at a time as an IEnumerable? That's probably a more straightforward choice than messing with streams directly, especially since streams aren't IEnumerable and thus won't play nice with LINQ without some extra hoop-jumping. That's just from memory though, so I might be wrong.
|
# ? Mar 4, 2015 06:21 |
|
Ithaqua posted:Doesn't File.ReadLines give you an iterator that streams the file into memory one line at a time as an IEnumerable? That's probably a more straightforward choice than messing with streams directly, especially since streams aren't IEnumerable and thus won't play nice with LINQ without some extra hoop-jumping.
|
# ? Mar 4, 2015 06:58 |
|
Another (VB) WinForms question for you. I found out yesterday that a custom control (a sort of file browser thing cobbled together out of a treeview) was throwing null reference exceptions in multiple places. However, none of the users had mentioned it to me. After some fiddling I realised that they are only thrown when I'm debugging, and when the app is running in deployment, something is swallowing them. The exceptions are being thrown by code in event handlers for drag and drop events, there is no Try/Catch block in the handlers... where exactly 'above' the form can they be being caught? My googling so far has suggested that they might be being caught by a Try/Catch in the 'Main' sub, but I haven't explicitly implemented one so it seems that in Winforms that means it would be getting injected by the compiler when built - or, that it could be being caught by global exception handling, but ApplicationEvents.vb is empty. Does anyone know where this exception could be going, or how I can found out? update: I placed a button on the form that holds the control that's throwing the exceptions, that does nothing but throw a new NullReferenceException. If I click this in deployment, the unhandled exception is being alerted and the program exits, so it's not that somethign is catching all such exceptions. What is the difference here? The custom controls are in a seperate project in the same solution, could this have anything to do with it? another update: I put a TreeView on the form next to the custom control and wrote drag-drop event handlers for it that just throw exceptions. They just disappear when running in deployment just like the custom control ones do. So I guess it's not to do with it being in a different project. Could it be something to do with it being a drag event? chippy fucked around with this message at 11:29 on Mar 4, 2015 |
# ? Mar 4, 2015 10:01 |
|
|
# ? May 23, 2024 16:27 |
|
Ah. It's because it's in a drag drop event. Something to do with boundaries between managed and unmanaged code.
|
# ? Mar 4, 2015 12:15 |