Jump to content
Xtreme .Net Talk

Nerseus

*Experts*
  • Posts

    2607
  • Joined

  • Last visited

Everything posted by Nerseus

  1. In Visual Studio you can go to the Debug menu to turn on the Locals or Autos windows - those will help with seeing variables. There's also the watch window, but I like the other two better. You can also right click a breakpoint to set breakpoint properties. From there you can have the breakpoint only hit on a condition, on a "hit count" (like >= 5 times the breakpoint is hit, etc.), and more. -ner
  2. Take a look at the Wikipedia: http://en.wikipedia.org/wiki/Aspect_oriented Here's a snippet: For example, consider a banking application. The method for transferring an amount from one account to another is conceptually very simple: void transfer(Account fromAccount, Account toAccount, int amount) { if (fromAccount.getBalance() < amount) { throw new InsufficientFundsException(); } fromAccount.withdraw(amount); toAccount.deposit(amount); } (the examples are shown in a Java-like syntax, since at the time of writing, an overwhelming majority of AOP-related research and work is done in Java or Java-variants.) However, in a real-world banking application, this transfer method is far from being sufficient. We must include security checks to verify that the current user is authorized to perform this operation. We must enclose the operation in a database transaction, to prevent accidental data loss. We must log the operation to the system log. And so on. A very simplified version with all those new concerns would look somewhat like this: void transfer(Account fromAccount, Account toAccount, int amount) { if (!getCurrentUser().canPerform(OP_TRANSFER)) { throw new SecurityException(); } Transaction tx = database.newTransaction(); if (fromAccount.getBalance() < amount) { tx.rollback(); throw new InsufficientFundsException(); } fromAccount.withdraw(amount); toAcount.deposit(amount); systemLog.logOperation(OP_TRANSFER, fromAccount, toAccount, amount); tx.commit(); } The code is no longer simple and elegant. This is because the various new concerns are tangled with the basic functionality (sometimes called the business logic concern). The transactions, security, logging, etc. are all examples of cross-cutting concerns.
  3. This is secondhand knowledge as I'm not the IS guy. We've been using network balancing for a few years now in production, back when it came with the NT Option Pack for Windows 2000 (I think). We don't use File Replication services though - we just copy all the same .NET files to each webserver. I was involved in the early stages of implementation but haven't touched it much lately. SQL Server replication: not using and probably wouldn't use. I've heard some bad stories from the trenches, including a SQL Server guru (one who coded part of the optimizer in SQL 7 and SQL 2000). Not that it's problematic, just tedious and... well, you'd better have a guru help. On a different note, we've had numerous issues with SQL Server running in parallel mode (taking advantage of multiple processors) - confirmed bugs from MS with no patch. But, the parallel bugs are only on SQL Server, not web servers. Just a smattering of info, but maybe it will help. -ner
  4. Really? That used to cause me so much confusion about halfway through my VB career. It confuses how people think of objects since it introduces the conept of "things that are always there" when they're really not. I guess I should prepare for more "I need to pass a value from Form2 to Form1" questions, only this time I'll have to ask if they instantiated Form2 or took the default instance :) As a nerd/geek myself, I think the new features are cool, but I won't be looking for ways to use them. But I want to know about them so I'll know when to use them, to save me time or energy. Hopefully that's how most people will use the new features. -ner
  5. I think you have a valid point, marble. By giving developers so much of what they want, MS has left a gap in the languages. That is, they used to have VB which served a GREAT purpose - easy to write apps with a lot of built in functionality. VB made doing hard things, easy. It may have left you plenty of opportunity to shoot yourself in the foot, but that's true in every language. While all the new language features are GREAT for mature software developers, newcomers may find it overwhelming - and confusing - as to the best, easiest way to do something. It's one of the reasons C++ is so hard to newcomers. When you look for good quality sample code, there is a TON of error checking, pointer checking, etc. It all gets in the way of seeing what the code is supposed to be doing. Hopefully the new features in C# help to keep the code simpler and not harder to read. I'm curious to see if MS doesn't release something like a simplified version of existing languages. If not, I'd bet that if there is a need, some company will fill it. As for the new features, I think they're ALL great. My company has a bunch of custom classes (with a lot of code) to handle nullable value types. The partial classes aren't just for forms but ideal for any kind of designer based code generation. For example, a DataSetGenerator or a custom object builder. The idea is that ANYONE can create a builder that generates code without having to worry about how to integrate it into the existing class. As for the generics, I haven't had to use too many type safe collections. Where I have needed them, I used a simple template that replaced my class name. Sure, it's code bloat, but it works well enough. Although generics are all the talk about .NET 2.0, I think they'll be one of my least used new features. Now if you want to talk about Visual Studio, holy cow - what an improvement! That, to me, is where the big bang for the buck comes in. The refactoring alone is worth it. I can't wait to play more with Team System. It's all just candy for developers, but good stuff still. -ner
  6. Other than very small, simple apps or test projects, I've not known anyone to really use the default SQL generated by ADO.NET. There are three main problems with the auto-generated code: 1. The generic engine just can't make optimized code like someone who knows the system 2. The generic engine makes buggy code. For example, if you have a column named id in a SQL Server, it may build "SELECT id, ..." but that's invalid. You need brackets around the name like "SELECT [id], ..." because id is a reserved word. But not all databases use []. 3. The generic engine is slow - it has to run a query to analyze the DB before it can build the right SQL. That's usually an extra trip to the DB that could be saved if you coded the SQL yourself. Why does it not recognize the Primary Key and use that in the WHERE? I don't know. Sounds like an oportunity to write your own SQL generator, if it's warranted :) -ner
  7. Best program ever for me? Probably a spline drawing program back in college. It was "refactored" perfectly before I even knew what refactoring was. It was a testament to it's "goodness" that I ported it from QuickBasic to VB3 to VB6 with no problems and almost no changes. Second best is a super secret one I'm working on right now - my "masterpiece". Don't ask, I can't tell. -ner
  8. I opened up System.Windows.Forms with Reflector to see how it implemented things. It uses an ImageAnimator internally to animate the GIF. As far as I could tell from 5 minutes of poking around (I LOVE Reflector), the ImageAnimator just handles looping through frames in an animation - it doesn't check whether or not looping is turned on or anything else. I don't know much about the ImageAnimator class, but I saw this blog that had some sample code to manually animate a GIF. If it's that important, maybe there's something in there that will help. It's also possible that the PictureBox has an event you could use. Or, worse case, make your own animator using the code from the blog above. You'd only have to do it once and it would be yours forever! :) -ner
  9. Technically you need only put single quotes around your SQL: Create proc Test @Description varchar(100) as exec ('Select * from media where description in (''' + @Description + ''')') If I might make a few suggestions? 1. Put brackets around description since that's a reserved word: exec ('Select * from media where [description] in (''' + @Description + ''')') 2. Use "=" instead of "IN" if you really only have one value. If this is truly a list of items, then you're doing fine. 3. Make sure you replace single quotes in @Description with doubled-up single quotes to prevent SQL injection OR use step 4. To see SQL injection, try this to see SQL injection at work: declare @sql varchar(255) set @sql = 'value''); DELETE FROM The SQL you'll be running will look like: Select * from media where description in ('value'); DELETE FROM You just allowed someone to delete from one of your tables! To double up single quotes, use this: [b]exec ('Select * from media where [description] in (''' + REPLACE(@Description, '''', '''''') + ''')')[/b] 4. Instead of custom, dynamic SQL, try using sp_executesql. This will work if you need to compare to one value with an "=". If you need to use IN because @Description is a list of values, then you'll have to use the steps above: [code] Create proc Test @Description varchar(100) as exec sp_executesql @statement = N'Select * from media where [description] = @DescriptionVal', @params = N'@DescriptionVal varchar(100)', @DescriptionVal = @Description They key bits above: A. The SQL used in sp_executesql is easy to read - it uses "where [description] = @DescriptionVal" which just reads nice. ie, easy to debug. B. You have to define the params used in the dynamic sql - those params are strings (@DescriptionVal above). C. The @statement and @params are nvarchar, hence the N' syntax on the strings. D. I generally add "Val" to the end of my dynamic SQL params, but otherwise keeping them the same name. So when the param to the proc is @Description then the param in the dynamic SQL is @DescriptionVal. The last line of the code above assigns the value to the dynamic SQL. It looks as if the proc sp_executesql has 3 params: @statement, @params, @DescriptonVal. I'm not sure how the engine handles that, but it knows about these arguments and does its thing! -ner
  10. I would try MS Access if I were you. There's also MSDE, but that's a bit more complex than I think you want right now. -ner
  11. I'm confused as to what you're doing (we're creating a new programming language...?). But, to save out the contents of a textbox to a file: System.IO.File.CreateText("c:\\test.txt").Write(textBox1.Text); That's all in one shot, obviously you should break that down and check for errors, etc. You said you needed something asap, and I hate that kind of pressure! Good luck with the assignement! -ner
  12. You can use .Length on any string to get the length. But this technique will only work if this is a fixed-width file, meaning each line is the exact same length. If it is then you don't want to use sLine.Length; use a constant that has the length of each line. To get the total number of lines: FileSize / LineWidth (the constant). Don't forget to add 1 or 2 to LineWidth to account for the EOL character(s) (sometimes 1, sometimes 2). -ner
  13. If you can't determine the exact count easily, you can use the "web progress bar" trick. That is, have the progress change on a timer or some interval - it goes back and forth, instead of just filling to the right. It's basically just some movement on the screen to let people know that things are working. How big is the file, would you guess? If it's less than a hundred meg you may consider reading the whole file into a string. Then you could count the number of EOL characters (char 10 or 13 or a combination, depending on the file). Kinda cheesy, but throwing out suggestions. If this is a fixed width file, I would definitely use the FileInfo object to get the FileSize - the OS can provide that without having to read in the whole file. -ner
  14. I'm not sure why it returns -1 instead of the actual rowcount. If you can't get that to work, you can always change your SQL to select the rowcount after the INSERT. If this is SQL Server you can put these all in one string. You'll have to use a method other than ExcecuteNonQuery - I'd suggest ExecuteScalar. In the code below, I snipped the INSERT statement down and appended a SELECT to the INSERT. With cmd .CommandType = CommandType.Text .CommandText = "INSERT INTO NMYLIB.BMNS_PF (...) SELECT ..." [b].CommandText = .CommandText & " SELECT @@ROWCOUNT"[/b] .Connection = OleDbConnection1 End With -ner
  15. @Diesel: I agree with your 3 reasons for "nominating" JoeMamma as a leader. But you left out two other factors affecting JoeMamma: He's an *** and he slams VB.NET at almost every turn. These are two things that I'm sure he's proud of, so I don't mind saying them here in the public forums. It doesn't matter much anyway. AFAIK this board doesn't really nominate any leaders - they're picked as needed. I can't imagine anyone would pick Joe to represent these forums, but who knows? -ner
  16. @mskeel: I haven't used the Licence Compiler. My guess is that it just prevents usage unless you have a valid license. Most 3rd party controls work this way. It means you have to buy a license (if one is for sale) to use the DLL. It doesn't prevent anyone from decompiling (nothing does) or looking at the code through Reflector - at least, I don't think the License Compiler does any obfuscation. If you truly wanted to hide the internals you would need to obfuscate. Can you simply decompile and recompile the code in a .NET DLL that used a license to get around the license? I have no idea - you could test it out and let us know :) -nerseus
  17. I think what you want is a license file; do a google search for "License Compiler", with the quotes. I've not done that myself, but I would guess that would work for you. That would keep others from using your DLL. If you want to protect the algorithms (the actual code inside), you're probably best off using an obfuscator. That will only make it harder for people to see your code - you can never truly hide it all. -nerseus
  18. I'm not sure how you'd call that Delegate that's passed to ProcessDelegate? Taking your pseudo-code one step further: void ProcessDelegate( delegate could either be VoidDelegate or BoolDelegate) { // Call delegate here... but how? } If the delegate you want to call can be either VoidDelegate or BoolDelegate, how would you plan on calling it? One takes 2 params while the other takes none. To use a delegate, it must be called and it must "know" the signature. There is no "BaseClass" syntax for a Delegate, or an interface that a delegate can support. A delegate is just a signature of what a method will look like. An instance of a delegate must be of a specific type of delegate and that will always only have one signature. -nerseus
  19. At the very least, your dates are in the wrong format - you should try MM/DD/YYYY instead of DD/MM/YYYY. It seems odd, but that's what SQL Server wants (that's the USA standard). As a simple test, try this in Query Analyzer: SELECT CONVERT(datetime, '27/05/1982') That should fail (I copied the date from your sample). The following should work: SELECT CONVERT(datetime, '05/27/1982') The rest of that code is so bad-looking that I didn't want to see if it work. I assume you've tested it and the parsing all works well and you're just having issues with the date formats. If you want other suggestions on what to clean up, we could all help. For starters, I'd move all of the string parsing out of the proc if at ALL possible. The DB engine supports string functions like how you're using them, and even WHILE statements. But it doesn't mean it's good at it. In fact, it's very, very bad. If you have to pass in some unknown number of dates as a string, I'd consider using dynamic SQL (still done through a proc) over what you've got. -ner
  20. I was thinking of using Contains on a hashtable. Here's the pseudo-code: Create Hashtable Loop each item in DataSet if hashtable.Contains(name) continue Add value to hashtable End Loop Loop each item in hashtable (GetEnumerator) Add items to hashtable End Loop Another possibility is to create a dummy dataset with one table, one column and do something similar to above. You would add rows to the new DataSet if they weren't already there. The advantage is that you could bind to the new DataSet if you wanted. The disadvantage is that you'd likely have to do a datatable.Select(...) to see if a value existed, and that just seems slower to me. I wouldn't worry about performance at this stage though, always profile afterwards. Let me know if you need a more concrete example. -ner
  21. I use CONVERT, works great! If that didn't help, maybe you could post a bit of code and values you're using? Any other info that seems relevant. - Jerry McGuire -ner
  22. Well, the sorting can be done through the ComboBox itself. As for the "distinct" part, I've not come across a way to do this automatically. I have "cheated" many times, using a Hashtable to store the values I want to add to the Combo with the keys being - for you - the value in Column 0. You will have to use a foreach and check ht.Contains() to see if a value already exists. If this is data retrieved from a DB, you can always use DISTINCT in the QUERY returning data. If you must use custom code, just wrap it in a function named GetDistinctValues() and you can always change your implementation later, if needed. I've found that using a hashtable is fine performance-wise. I've had as many as 200-300 entries before and it's very fast. Any more than that and I'd start to wonder why a user would want a drop-down anyway and not some sort of type-in control. -ner
  23. This may not be any help to you at all, but if you're binding to a DataSet, you can also use the DataSet's "HasChanges" method which might return true in your case. Where I work we have a policy of never trusting a control to give alerts on datachanges - always use the DataSet. For example, if we need to check on changes or "trigger" something (such as filtering a combo when another combo changes a value) we use the DataSet's events, such as ColumnChanged or RowChanged. I'm not much help on the DataGrid so if this doesn't help, just say "No way, Jose!" and hopefully someone who knows, can help. -nerseus
  24. mutant is not referring to this thread, but a post titled "rant" that has since been removed. -ner
  25. If I get you right, you want Class2 to hold a reference to an instance of Class1 - maybe pass that in the constructor. Then your property in Class2 just returns the value from Class1. Let me know if that doesn't make sense and I can throw out a sample - or maybe that's not even what you want. -ner
×
×
  • Create New...