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
Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

This is kind of an implementation question, that I'm wondering how you guys would handle. I have to take a string up to 300 characters long and extract up to 5 values for it based on keywords in the string. Some of the values I'm matching are (always deepest level when present, e.g. I can use 'christian-crosses' but not its parent 'christian-symbols' or 'religious-symbols'):
https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/icg/jewelry_item_classification_guide.html#dc_general_SubjectContent

So the way I did it way back when, when I was only concerned with 3 or 4 of them, was just a bunch of IF...THEN statements like this:
code:
Do While ListOfSubjects.Count < 5
  If title.Contains("crucifix") Then
     ListOfSubjects.add("crucifixes")
  End If
  If title.Contains("star of david") Then
     ListOfSubjects.add("star-of-david")
  End If
  (etc etc)
Loop
But if you take a look at that link, there's actually hundreds of possibilities. I could code out hundreds of IF...THENs, but that seems inefficient to me for a lot of reasons.

One idea I thought of is to make a database table (Subjects) like so:
code:
Keyword | AttributeValue
crucifix, crucifixes
star of david,star-of-david
And then do:
code:
Dim dsSubjects as DataSet = (stored proc that's basically "SELECT * FROM Subjects")
 For Each dr as DataRow in dsSubjects.Tables(0)
    If ListOfSubjects.Count > 5 then
      Exit For
    Else
      If title.contains(dr("Keyword")) then ListOfSubjects.Add(dr("AttributeValue"))
    End If
 Next
This gets me a lot of the way there, but I also have negative keywords. For example there's a 'crowns' symbol, but I don't want it to trigger for 'crown of thorns', or 'dragon' but not 'dragonfly'. This would probably be handled by adding a NegKeyword column to the database above and doing:
code:
Keyword | NegKeyword | AttributeValue
dragon,fly,dragons

and then
  If title.contains(dr("Keyword")) AndAlso Not title.contains("dr("NegKeyword")) then ListOfSubjects.Add(dr("AttributeValue"))
But then I run into multiple negative and positive keywords as well (e.g. "saint", " st ", "st.", "our lady", "o/l", "miraculous" for "saint-depictions"). So before going all the way down that path, I thought I'd ask you guys how you'd handle this. The IF...THEN way? The Keyword/Attribute database way? Or some crazy other way?

EDIT-You can ignore the special cases like month-birthstone and zodiac-sign since they're 'two step' processes that I already handle elsewhere

Scaramouche fucked around with this message at 01:17 on Jan 8, 2015

Adbot
ADBOT LOVES YOU

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Bognar posted:

Are you always searching for whole words and not subsets of words? If so, you should use a HashSet<string> or Dictionary<string, string>. Build a dictionary with all of your matching strings as keys, and the hyphenated versions as the values. Split your input string into words, then check for the existence of a key in the dictionary matching each word. Dictionary lookup is constant time so it will be a lot faster than doing a bunch of String.Contains calls, but now you'll have to worry about getting exact matches.

I get what you're saying there, but I was hoping to use .Contains to cheat a bit on a regex style match so I don't have to make as many rows/keyword entries. For example .Contains("baseball") will match 'baseball', 'baseballs', 'baseball player', 'baseball glove', 'baseball hat', 'baseball bad', 'baseball pitcher', etc etc. I started the database table approach and have a first run with about 200 rows, but if I had to do exact match that would balloon up to at least 800-1000 when you take pluralization and other things into account. I also really can't split the input string very easily because it's not clear what to split on. For example split on space would work on 'dragon' but not 'star of david' or any other compound terms.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Dr Monkeysee posted:

Are you stuck with having to use the database directly? Because it sounds like you're trying to implement full-text search which you'd be better off using a tool that already does this like Lucene or elasticsearch, or an RDBMS that supports full-text search (I believe postgres has recently added support for this). They will support stemming, pluralization, etc out of the box. This is a problem with a huge amount of edge cases and natural language-aware logic that is gonna be pretty hard to get right yourself.

Yeah, I have access to our SOLR/Lucene install (it drives the search on our site) but didn't want to mess around with setting it up for this. I wasn't looking for a perfect solution, just a better one than the IF...THEN chain that I had going previously. The database solution is relatively elegant for the amount of effort involved, and if I want to add/remove/change it's just a simple INSERT/UPDATE away. It falls down for complicated cases (multiple negative keywords), but for multiple positive keywords I can just add rows (e.g. Boxer, Boxing). I've actually already repurposed it for some other similar attribute name -> attribute value relationships (by adding a Type column) for about 100,000 products.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Yeah VB6 more logically progresses to WPF/WinForms unfortunately, in that you're still dealing with relatively familiar form elements, events, triggers, etc. That said, making a WPF app in this day and age still feels a bit weird, but it might work out for you. I actually went from VB6 -> ASP Classic -> ASP.NET -> VB.NET, but I was always more of a database logic guy than an interface guy so it was mostly a positive experience. I'm trying to remember what the biggest gotchas coming out of VB6 were, but they mostly relate to declaring variables and scope, not having to deal with ODBC for database (hallelujah!). Other than that IF THEN is still IF THEN, FOR NEXT is still FOR NEXT, etc. Oh and always use GOTO.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I'm not a MVC/Entity expert at all, but I think that sp_executesql is being called because you're passing in a string and having it executed directly, and the server at run time has no idea if you've passed in a proc or a dynamic string. I have no exposure to the framework but I'd expect the sproc to only get explicitly called the server knows it directly. Again, never coded for it but I'd expect something like:
code:
Dim sprocUserQuizzesCreate as New SomethingObjectEFUnderstands

sprocUserQuizzesCreate.ProcedureName = "dbo.UsersQuizzesCreate"
sprocUserQuizzesCreate.Params.Add("@BadgeID",555)
Dim dsThinger as DataSet = sprocUserQuizzesCreate.Execute()

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I'm getting a pretty generic error from connecting to a MSSQL server with my web app so I thought I'd pick youse guys' brains to see if anyone's come across it before. The error is:
Exception message: [DBNETLIB][ConnectionRead (recv()).]General network error. Check your network documentation

So googling around leads me to a lot of bitching about how generic and unhelpful it is but not much for remediation. This is the scenario:
There is a development server called ServerB that runs a web app. There are scheduled tasks that kick off every (interval) that cause ServerB to query an MSSQL 2008R2 server over OpenVPN (ServerA), take that query and turn it into XML.

The event occurs in ServerB's event log, but I can't find sign of any matching problem in ServerA's event log. Most of the troubleshooting I've seen around this is saying check cables, check network cards, etc. but this setup has been running smoothly for months now, and I doubt any physical/network infrastructure events have occurred since this started happening (Monday).

The one thing I did read that kind of made sense was suggesting bad re-use/recyles of connections (near the end, ignore that it's a Delphi question):
http://stackoverflow.com/questions/10755560/auto-recover-when-dbnetlib-connectionwrite-general-network-error-causes-ado-conn

So the way we do these database calls is a general function in a 'helper' file that is structured like so (for those worried about injection/etc. this thing is locked down to only accept connections from the OpenVPN connection):
code:
    Public Function GetMeTheDatas ExecuteSqlReturnDataSet(ByVal sql As String) As DataSet
        Dim dbConn As System.Data.OleDb.OleDbConnection
        Dim dbComm As System.Data.OleDb.OleDbCommand
        Dim dbDs As New System.Data.DataSet
        Dim dbAdapter As System.Data.OleDb.OleDbDataAdapter

        Dim appPath As String = HttpContext.Current.Request.ApplicationPath
        dbConn = New System.Data.OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("sqlConnection").ConnectionString)
        dbConn.Open()
        dbComm = New System.Data.OleDb.OleDbCommand(sql, dbConn)
        dbComm.CommandTimeout = Integer.MaxValue
        dbAdapter = New System.Data.OleDb.OleDbDataAdapter(dbComm)
        dbAdapter.Fill(dbDs)  <-- Event Log error points to this line on first entry,

        dbConn.Close()
        Return dbDs
    End Function
Which is then called in a page_load (e.g. ProcessXMLFiles1.aspx) like so:
code:
Dim buttes As New DataSet <-- Error layer 2 is here
buttes = GetMeTheDatas("procname 'buttes''")

(xml processing For...Each row in buttes.tables(0).rows goes here)
So, the thing is, I'm not sure why this is happening. The connection between the two is steady; according to the OpenVPN logs and network uptime tracking (We use pingdom) the two machines are constantly connected. Also the proc itself is not 'heavy' (about 30,000 rows max) in anyway, and it's not tied to any specific procedure/page either. I've seen this error intermittently only starting last Monday, and on a variety of operations that use the database (all SELECTs of one kind or another).

Anyone run into this or have any insight?

Lastly, here's the detailed text from the event:
Thread ID: 7
Thread account name: IIS APPPOOL\buttesbackend
Is impersonating: False
Stack trace: at System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr)
at System.Data.OleDb.OleDbDataReader.GetRowHandles()
at System.Data.OleDb.OleDbDataReader.ReadRowset()
at System.Data.OleDb.OleDbDataReader.Read()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) (line numbers and file names removed)

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Thanks for all the good info guys; I figured it was something like that (incredibly generic error) that some of you had come across before. Some answers to people's questions:

The server info:
ServerA - Actually a repurposed desktop sitting under my desk, all it does is generate XML; it's not public facing or anything, just has scheduled tasks fire off that make calls into web pages. So basically it's running IIS and that's it. Q6600 @ 2.4 GHz processor and 4gb of RAM.
ServerB - Oldass Dell rack server we're in the process of clouding out. Runs IIS and MSSQL. Xeon 2 quadcore 3.2 GHz 8gb RAM.

Location: ServerA is in the office, and ServerB is in the colocation facility about 20 kilometers away; they are not in the same LAN. ServerB is running an OpenVPN listener that ServerA connects to.

Error frequency: About once or twice a day, usually first thing in the morning (which makes sense because that's when XML is being generated).

OLEDB vs Native: Haven't even thought of it to tell the truth. Is there somewhere that lists the differences between them?

Activity Monitor: This is a Good Thing that I forgot about. Problem being, I'm not 100% sure on how read the results. I'm currently concentrating on 'Recent Expensive Queries'. There's one with a plan count of 13,000 which seems high; it's basically a proc that goes 'SELECT * FROM Product WHERE Productid=@Productid' to help build and XML file about products (about 100,000 products).

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

wwb posted:

If you've got IIS on server B I'd just push the app over there and eliminate the network angle. Keep Fowler's 1st law in mind.

That's actually what it was like originally, but was causing load problems because ServerB is a full blown web server handling tens of thousands hits a day. The 'brute' crunch was string handling, not database operations, so I moved t hat off to ServerA.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Mr Shiny Pants posted:

Buy a new server? I don't want to sound like a dick or anything but I just bought a Lenovo Thinkserver with 4 core HT Xeon with 32GB of ram for less than 1000 euro's.

I mean, if it's an important application a new rackserver is not that much of an investment these days.

No I get you, the problem being we want this server to eventually not exist and are in the process of offloading everything on it into VMs and Cloud Storage, and therefore don't want to invest in further infrastructure. I've just got to baby this along until we finish switching over.

As for the error, uggh it happened over a dozen times yesterday. I uploaded a new code base last night that has optimized a lot of the high plan count queries and today I'll be working on the high execution time ones. I've also put a network monitor on ServerA to see if the network card is getting over-saturated when these errors happen so we'll see how that goes.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

This is a hypothetical question I guess, since I've already done it, and it's going to be replaced by the real solution (make the proc on the database return the right results) eventually. But I found myself in need of filtering down one datatable based on the contents of another. I just threw together a quick and dirty Linq-y style thing since I knew it would work:
code:
Dim GoodProduct as datatable = (sql that makes a table with a SKU field)
Dim BadProduct as datatable = (sql that makes a table with an ItemCode field that matches SKU field)

Dim LLJK = From t1 in GoodProduct Join t2 In BadProduct on t1.Item("SKU") Equals t2.Item("ItemCode") Select t1

For each dr as DataRow in LLJK
 'My poo poo
Next
What I'm wondering, how performant is this? My past experience with Linq is that it's a neat way to write things out in a terse, yet mostly readable style, but it ends up being not so hot when it comes to performance. Was there a better way? Is this a bad way?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Any of you guys ever had to programmatically connect to Google drive and grab the content for use/insertion into a database? We've got a marketplace that we're doing good sales on, but they have zero automation for sales reporting, order importing, etc. So the way our staff keep track of them is to update a Google Spreadsheet Doc. The idea being I'd connect to Drive, open this sheet, and grab new rows and put them in the database.

I've found and am messing around with this:
https://developers.google.com/resources/api-libraries/documentation/drive/v2/csharp/latest/annotated.html

But am just wondering if anyone else has done it and if they have any 'gotchas' or advice.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

RICHUNCLEPENNYBAGS posted:

The .NET libraries are loving awful because they're just maintained by one guy who constanlty keeps changing how the auth and stuff works so it ends up being easier to just mess with the REST stuff yourself. That's how I remember working with the Google Apps stuff.

I think I get what you mean; I did a similar thing with translate however instead of including a bunch of references and creating a bunch of classes I ended up curl'ing the URL I wanted and pushing it in, and then grabbing what I needed out of the resulting JSON. So it sounds like you're saying that's the case here too?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Hughmoris posted:

Thanks, that's good to hear.


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?

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.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Built in support for outer space time.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I don't have an IDE in front of me, but isn't matches just a collection? So something like
code:
Dim strFind As String = "[0-9][0-9][0-9]"
Dim strSearch As String = "Test string 123 and another 456 and a third 789"
Dim strResults as New List(Of String)
Dim regLook As New Regex(strFind, RegexOptions.IgnoreCase)
Dim m As Match = regLook.Match(strSearch)
For Each mm As Match In m.Groups
 strResults.Add(mm.Value)
Next
or am I smoking crack?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

GrumpyDoctor posted:

I believe that the example you posted will actually yield a collection in Groups[0].Captures, but I'm not entirely sure without playing around with it myself.

That could well be, I'm helpless like a baby without Intellisense/Autocomplete.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

EDIT - I got it working, leaving first part of the question in for historical reasons. However, I still want to limit access to this, so read on below the code to see the updated question!
Have you guys ever programmatically accessed an FTP server that requires >active< connection from .NET? I adapted my passive code to do so:
code:
        Dim request As FtpWebRequest = DirectCast(WebRequest.Create("ftp://placetoftpto/" & strFileName), FtpWebRequest)
        request.Method = WebRequestMethods.Ftp.UploadFile
        request.UseBinary = False
        request.UsePassive = False 'added this

        request.Credentials = New NetworkCredential("name", "pass")

        Dim sourceStream As New StreamReader(strFilePath)
        'Dim sourceStream As New StreamReader("C:\Feeds\Orders\Outbox\" & fileName & ".txt")
        Dim fileContents As Byte() = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd())
        sourceStream.Close()
        request.ContentLength = fileContents.Length

        Dim requestStream As Stream = request.GetRequestStream() ' error occurs here
        requestStream.Write(fileContents, 0, fileContents.Length)
        requestStream.Close()
I'm getting a "(425) Can't open data connection" error. Which I think is firewall related, but thought I'd run this by you guys first to make sure there's nothing dodgy with the code.

The instructions from the person running the server are:

quote:

IMPORTANT!! Please ensure that you are in "Active" mode as "Passive" mode will not work. Active FTP requires the clients firewall to allow traffic above > 1023 from port 20 & 21. Port 20 is the data communication port that most people forget to allow. Check both hardware firewalls and software firewalls like (XP firewall).

Which I believe I've done by making a pretty blanket rule of :
-> In TCP
Remote Port: Any
Local Port: 20,21,1024-65535
and
<- Out TCP
Remote Port: Any
Local Port: 20,21,1024-65535

But it still doesn't work, even in command line FTP (which is why I think it's a firewall problem). I know firewall questions are a bit outside the scope of this thread, but couldn't really figure out a place to put the second part of this question, which is: how to configure the firewall to let active ftp through.
EDIT - This is the real question now
And the last question is, if I want to limit this access to only my web application, how would I do that? Limit it to the app pool user name in the firewall?

Scaramouche fucked around with this message at 22:36 on Mar 6, 2015

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Hah just had a funny. I have a job fired by an .aspx page that connects to an FTP and uploads a file I've created. I was testing it out in another application so hurriedly just commented out the ftp code (because I didn't want to upload test files to the live server) and then let it run in the background to test the file generation part. Switched to something else for 30 minutes, look up and see that the browser tab I was running it from still had the spinning 'waiting for localhost' icon going. This thing should normally take 5 minutes top. Turns out I was a bit too lazy when commenting, and the guy who did this before me a bit too lazy when naming variables:
code:
' Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse) <-- this got commented out

' other stuff

response.Close() ' <-- This didn't get commented out
Turns out when you name a variable the same thing as a class bad things can happen.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

RICHUNCLEPENNYBAGS posted:

VB isn't case-sensitive and I'm guessing GetRequest returns a Request.

Yeah. Right click on that 'Response.Close()' and choose to Go To Definition and you get the class in the Object Explorer, not a variable declaration.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

TheEffect posted:

I have no formal VB.Net training, only C++ and very little at that. That was exactly what was needed. Thank you!!!

Off the top of my head the &/&&/AndAlso and |/||/OrElse are probably the two biggest 'gotchas' about VB.net as compared to how other languages work. Actually bitwise operators too have a few quirks, maybe brain up on them:
https://msdn.microsoft.com/en-us/library/wz3k228a.aspx

The other big change is how variable declaration is done, but that's mostly syntactical and you probably won't even run into it unless you're doing a bunch of List (of or LINQ style one line statements.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Question about file locking. I'm doing this:
code:
        Dim files
        files = Directory.EnumerateFiles("d:\somewhere\", "*.csv")
        For Each filename As String In files
            Dim afile As FileIO.TextFieldParser = New FileIO.TextFieldParser(filename)
            Dim csv As String()
            afile.TextFieldType = FileIO.FieldType.Delimited
            afile.Delimiters = New String() {","}
            afile.HasFieldsEnclosedInQuotes = False
            Do While Not afile.EndOfData
                csv = afile.ReadFields
                'buncha csv parsing stuff
            Loop
            afile = Nothing
            File.Move(filename, "d:\somewhere\Processed\" & Path.GetFileName(filename).ToString)
        Next
However, on the File.Move at the end, I'm getting a file access error. I had thought destroying the afile object would remove the lock, is there something else? I obviously can't desttory the files object populated by Enumerate Files because I'm still looping through it.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Mr Shiny Pants posted:

I think you need to dispose the stream before moving it.

Can you use "using" around the TextReader or something? Don't know if VB has it. Otherwise dispose of the textreader.

You sure are correct. Dispose() fixed it, though I didn't try .Close() Rooster Brooster.

Bad habit from the VB 6 days I guess. Actually a trenchant question, is there any point in setting an object to Nothing any more?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Munkeymon posted:

I ran windows update, rebooted and now I can't build my ASP MVC project because System.Web.Mvc looks like this:


:wtc: happened and how do I go about fixing it? Yes I restarted VS. Do I need to repair some dev kit I forgot I installed?

Is it this guy?
http://blogs.msdn.com/b/webdev/archive/2014/10/16/microsoft-asp-net-mvc-security-update-broke-my-build.aspx

Also, another 'I've already done but is there a better way' question:
I'm parsing files that get downloaded by an FTP job that I don't control, let's say invoices instead of the sexy real thing it is. So every night a WGET script grabs *.csv from an ftp server and copies it here:
d:\invoices

Then I parse them, and move them to here:
d:\invoices\processed

The way I'm avoiding double parsing is like this currently:
code:
Dim files
files = Directory.EnumerateFiles("d:\invoices", "*.csv")
For Each filename As String In files
  If Not File.Exists("d:\invoices\processed\" & Path.GetFileName(filename).ToString) Then
    'do stuff
    'move file to processed
  Else
   'File is duplicate delete
   File.Delete(filename)
  End If
Next
This works, but I'm wondering, will the .Exists method eventually introduce some overhead lag if the contents of \Processed ends up being thousands of files? There would only ever be 5-6 files in \Invoices at a time. Is this premature optimization, or is there a better way?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Nother academic question. I've been going through and updating all this old code I've inherited from when we were much smaller. In this case I'm creating and writing a large file, with little changes for each file (saving 4 times). What the first guy did:
code:
'(Generate 'base' file that the others are modified versions of)
Dim strFileBase as string = System.IO.File.ReadAllText("name of base file")
strFileBase = strFileBase.replace("thing1","thing2")
System.IO.File.WriteAllText("name of thing 2 file", strFileBase)
This quickly ran into OutOfMemory problems that I've been tasked to fix. What I did was:
code:
'(Generate 'base' file that the others are modified versions of)
If File.Exists(strFilename) Then 'strFilename is the base file
                Using reader As System.IO.StreamReader = New System.IO.StreamReader(strFilename)
                    Dim fsY As New FileStream("new file name", FileMode.Create)
                    Using writer As New System.IO.StreamWriter(fsY)
                        Dim line As String
                        line = reader.ReadLine
                        writer.WriteLine(line) 'Header
                        If (line IsNot Nothing) Then
                            Do While (Not line Is Nothing)
                                line = reader.ReadLine
                                line = line.Replace("thing1", "thing2")
                                writer.WriteLine(line)
                            Loop
                        End If
                    End Using
                End Using
End If
Is this streamreader/streamwriter thing common, or am I assuming they can co-exist and this will actually improve the situation?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Hay GrumpyDoctor, Bognar, NihilCredo, thanks for answering my large file write question back on April 13. I no longer work for that organization, which is why I haven't been back here to give you fist bumps on your advice. But daps all around, I really appreciate you guys answering questions.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Just giving all of you soon-to-be-my-best-friends a heads up, I'm moving back into the .NET world after being out of it for years. I'm going from WPF VB.NET circa 2010 into all new and cool C# MVVM/EF, so I'm sure I'll have tonnes of dumb questions as I get further into the details. I had some initial questions:
- I'm seeing a lot of LINQ SQL type stuff, I had thought this was being deprecated? Or was it just folded into a more core library?
- After installing Resharper (org mandate) I'm seeing a lot of slowdown and messages like "blah seconds unresponsive because of Resharper". Also seeing general Windows lagginess in comparison to pre-install. Is this solved through configuring Resharper more completely or just throwing more horsepower at it? I currently have a 2 Core i5 @ 2.6GHz and 12gb RAM, using VS 2017.
- I really like SourceTree for git management, but is it really necessary any more? The impression I get is everyone just does stuff in VS proper now. I would only be mostly pulling and doing little commits here and there, not really anything complex.

Sorry if those are dumbo questions, looking forward to getting back into "real" development!

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Thanks for the replies guys, especially the clarity on LINQ syntax versus LINQ to SQL.

I've also ended up disabling Resharper for now until I actually need it since it was causing two minute startup time delays, and sometimes Explorer would just up and crash. Now I just need to figure out all this Entity Framework stuff, which seems to be buried pretty deep.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I'm digging into Entity Framework, and I apologize for the basic nature of this question, but it feels like stuff is happening "invisibly" to me when a database update is committed. However I can't find the final statement that actually does the update/insert/etc. I believe this is because how Entity Framework operates, that is it is tightly bound to the database structure and once you reach a certain point (e.g. object.update(parameters)) syntactical sugar takes over and just does the database work, instead of calling stored procs and prepared strings like I'm used to.

The way I would learn a code base is find something I'm interested in and then keep diving through "Go To Definition/Implementation" until I get to the "nitty gritty" of whatever that call does. But in following these down I only end up at boilerplate definitions from metadata that are things like "public void InsertAllOnSubmit<TSubEntity>(IEnumerable<TSubEntity> entities) where TSubEntity : TEntity;". I get what's going on, but it feels weird not to see that final SQL statement.

There isn't really a question, just more of a musing that I'm used to seeing that almost "bare metal" view and by definition EF stuff as an ORM doesn't do that.

On the plus side, I'm sitting in on the scrum meetings and have learned what Floccinaucinihilipilification means.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

.NET Progress Update:
I'm actually doing work and have had my first PR approved!

Cons: Apparently there's this thing called Code Review and man it can get ugly. I think I pissed off a guy by suggesting to use StringComparison.OrdinalIgnoreCase instead of doing x.ToLower = y.ToLower. Now there's a fight that's snarled a bunch of other people on whether we should use an extension method instead of replacing all the current instances of ToLower=ToLower

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

B-Nasty posted:

I don't want to work with the kind of guy that would actually try to argue a case for x.ToLower()==y.ToLower() over x.Equals(y, StringComparison.OrdinalIgnoreCase)

I mean, even without looking at the reference source, it's obvious the .Equals method is more performant and easier to read.

Yeah it turns out that I might have misunderstood the controversy internally. This kind of comparison isn't endemic throughout the application, only in some extremely old stuff made by people who aren't here any more. I suggested changing out the comparison method, but this old stuff is actually set to be completely refactored by end of Q1 anyway. So the "fight" I referenced isn't about whether to do it or not, it's whether to bother since it's being overhauled in the medium future anyway. No one here seriously believes that ToLower (and in some cases ToUpper I have found since) is the better way of doing things.

As for the different answers, I believe the main difference is as mentioned in the international/non-ASCII case where ToLower/ToUpper might have unintended consequences. I seem to recall someone posting in detail what happens to highbit characters in the poo poo that pisses you off thread way back when. I think they worked in pharmacy and they elucidated all the weird ways that the micrograms character gets messed up by region encoding upper/lower case operations.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

raminasi posted:

Reinventing the wheel is perfectly appropriate if you're studying wheel design.

Yeah I'm on Long Sack's side here, this is basically how I learn too.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I made an EDI parser in Bash way back in the day using regex and I'm still pretty sure it's being used at that organization to extract order numbers called in a CRON job, despite them having an existing web application that does the same thing.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Is there a way to get timings on all events that occur on a pageload? I've got an ASPX page I'm diagnosing that has a 26s "waiting" time in Chrome inspector before any payload reaches the browser. This isn't surprising, because it has sub-tabs on it that each load up with like, Address Info, Order History, etc etc. The thing is, so many things are loading I can't really step through all of them see. What I was hoping is I could just turn something on during the debug, VS records how long each thing takes, then I could stop it, and examine what the longest running events are.

The events already get listed in the Diagnostic Tools > Events section, but there's no timings attached to them, just "Thing 1 happened\nThing 2 happened". I think what I'd like is the Delta between Thing 1 and Thing 2. This happens when you're F10ing through the code with that little x ms popup, but I was hoping to have it harvest/record automatically.

Apologies if this is a basic question, I'm really more of a server guy, and really not much of a VS guy. If you're wondering why such a guy is even looking at this, it's a little self improvement project I've taken on to track down some of these more involved complaints and get them more codified before handing them off to a real programmer.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!


FFS it was there already, but the event profiler was default docked to right, the Time/Duration/Thread columns were invisible off to the right, and when it's docked it doesn't let you scroll the display.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

More newbie Visual Studio question:
Has anyone noticed some flakiness with the Solution search (not Shift-Ctrl-F > Scope: Entire Solution) in the Solution Explorer? What seems to be happening with me is that it gets less and less effective over time, until eventually I have to close VS and restart again from scratch. It seems to go in this order:
- After launch, finds everything I search for
- Suddenly can't find string literals/non-keyword values in code
- Suddenly can't find function/object names
- Can only find file names, can't "see" anything actually in the file
- Can't find anything. I'll have "thinger.aspx.cs" literally open and when searching for thinger in the Solution explorer nothing comes up

Is this just a known issue? I've googled around but can only find people complaining of similar issues with Shift-Ctrl-F entire solution (which generally doesn't work and locks up VS if I try it).

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

It's Visual Studio Professional 2017 15.9.3 on a big ol web app.

I'll check out those ctrl-,/t I knew about it but the interface is pretty bare so I'll have to brain up on using it.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

downout posted:

I've never experienced anything like this. Is there a repair for VS, maybe through the installer? I'm not sure how VS search is implemented, but that seems like some kind of data corruption or maybe some text string is causing a weird bug? Does the solution have lots of projects in it?

Sorry guys I was way out of town on the weekend and usually only go into CoC at work.

I've updated a couple times, which I thought might help but this is has been a pretty consistent experience with VS since I first got back into it, which is back in Nov IIRC. The solution has 32 projects in it, which I'm afraid I'm too green to know if that's a lot or not.

I do have ReSharper installed, but due to performance issues I have deactivated it. Is it possible that it would still be having an effect despite being deactivated?

EDIT-Happened again after computer was sitting over the weekend. Maybe it's an artifact of having VS just open too long?

Scaramouche fucked around with this message at 17:48 on Mar 18, 2019

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Might check it out for the c# 8 preview stuff that I missed in December:
- Null warnings on specified reference types
- Range/index slicing in arrays
- Asynch IEnumerable<T>

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Yeah the big If here is if WPF et al actually go away in any meaningful sense

Adbot
ADBOT LOVES YOU

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I've used PDFsharp in the past but have no idea how well it's aged into the -core era.

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