Robert Harvey

1

votes
2

answer
25

views

How do you retrieve one of the pallet brushes from the Material Design in XAML toolkit using C# Code Behind?

My pathetic attempt to retrieve one: MaterialDesign.Themes.Wpf.Current.Brushes.MaterialDesignBody (which doesn't work, of course.) The documentation for the brushes is here. The brushes themselves appear to be located here; I can get to them in xaml, but don't know how to get to them in C#. If anyo...
Robert Harvey
1

votes
0

answer
20

views

How do I use a Pack Icon as a mouse cursor?

I have the following code which I'm using to provide mouse cursor feedback on a drag and drop operation. It uses a local cursor file. private void UserControl_GiveFeedback(object sender, GiveFeedbackEventArgs e) { if (e.Effects == DragDropEffects.None) { e.UseDefaultCursors = true; e.Handled = true...
Robert Harvey
2

votes
1

answer
390

views

What are the use cases for jQuery Templates in ASP.NET MVC?

For awhile now I have been looking for an overall data/markup strategy to settle into ASP.NET MVC, and am now currently looking at jQuery Templates. jQuery templates appear to me to be a new binding system, similar to the MVC view engine or its various flavors, except that it does the data binding i...
Robert Harvey
3

votes
2

answer
606

views

Instrumenting an expression tree — How to get the computed result of each subtree?

I'm doing some work in Expression Trees, a rules engine of sorts. When you call ToString() on an Expression Tree, you get a lovely bit of diagnostic text: ((Param_0.Customer.LastName == "Doe") AndAlso ((Param_0.Customer.FirstName == "John") Or (Param_0.Customer.FirstName == "Jane"))) I wrote thi...
Robert Harvey
17

votes
8

answer
29.1k

views

Regular expression to split string and number

I have a string of the form: codename123 Is there a regular expression that can be used with Regex.Split() to split the alphabetic part and the numeric part into a two-element string array?
Robert Harvey
18

votes
4

answer
13.5k

views

How do you get the duplicate key that ToDictionary() has failed on?

I'm creating a Dictionary object, using IEnumerable's ToDictionary() extension method: var dictionary = new Dictionary (myCollection.ToDictionary(k => k.Key)); When it executes, it throws the following ArgumentException: An item with the same key has already been added. How do I get it to tell me wh...
Robert Harvey
18

votes
1

answer
26.6k

views

How do I group data in an ASP.NET MVC View?

In reporting tools like Crystal Reports, there are ways to take denormalized data and group it by a particular column in the data, creating row headings for each unique item in the specified column. If I have this: Category1 Data1 Category1 Data2 Category1 Data3 Category2 Data4 Category2...
Robert Harvey
5

votes
4

answer
16.5k

views

Bit manipulation in C# using a mask

I need a little help with bitmap operations in C# I want to take a UInt16, isolate an arbitrary number of bits, and set them using another UInt16 value. Example: 10101010 -- Original Value 00001100 -- Mask - Isolates bits 2 and 3 Input Output 00000000 -- 10100010 00000100 -- 10100110 0000...
Robert Harvey
2

votes
4

answer
859

views

Performance Testing a Greenfield Database

Assuming that best practices have been followed when designing a new database, how does one go about testing the database in a way that can improve confidence in the database's ability to meet adequate performance standards, and that will suggest performance-enhancing tweaks to the database structur...
Robert Harvey
6

votes
5

answer
1.3k

views

How to create a menu in WPF that has Microsoft Web Application styling

We have been tasked with designing an enterprise application in WPF that will replace a battleship grey Winforms application with a modern look and feel. We like the look and feel that Microsoft web applications currently possess: We could create these menus in WPF in the usual way: But we'd get som...
Robert Harvey
5

votes
3

answer
2.7k

views

Creating Database Mocks in ASP.NET MVC using Data from Existing Database

I have an existing ASP.NET MVC application with some sample data in the SQL Server database, which is working fine.. Assuming I have all of the necessary repositories and IOC in place, is there a tool that will extract the data from a group of tables, and "freeze-dry" it into a mock object (perhap...
Robert Harvey
5

votes
3

answer
9.5k

views

Why is my Extension Method not showing up in my test class?

I created an extension method called HasContentPermission on the System.Security.Principal.IIdentity: namespace System.Security.Principal { public static class IdentityExtensions { public static bool HasContentPermission (this IIdentity identity, int contentID) { // I do stuff here return result; }...
Robert Harvey
3

votes
2

answer
616

views

How can I identify the color of the letters in these images?

I am using this article to solve captchas. It works by removing the background from the image using AForge, and then applying Tesseract OCR to the resulting cleaned image. The problem is, it currently relies on the letters being black, and since each captcha has a different text color, I need to ei...
Robert Harvey
11

votes
2

answer
1k

views

Is there a relatively straightforward way to finalize a CD or DVD in C# or PowerShell?

First, some clarification of terms. By finalize, I don't mean closing a session; I mean writing a lead-out to a CD or DVD in such a way that information can no longer be added to it via the usual means (Roxio, Nero, Windows Explorer, etc.) I've done a fair amount of research on this. There are som...
Robert Harvey
5

votes
7

answer
1.3k

views

Disposing objects in the Destructor

I have an object that has a disposable object as a member. public class MyClass { private MyDisposableMember member; public DoSomething { using (member = new MyDisposableMember()) { // Blah... } } } There can be many methods in MyClass, all requiring a using statement. But what if I did this instea...
Robert Harvey
4

votes
2

answer
662

views

How secure is using an encrypted appSettings element in your app.config?

In a CodingHorror blog post a commenter made the observation that it is more difficult to obscure sensitive configuration information (e.g. SQL Server connection strings) in a program than it used to be, because the obscuring algorithm can be disassembled quite easily with Reflector. Another comme...
Robert Harvey
11

votes
2

answer
5.3k

views

Binding to a Collection of Strongly-Typed Objects in ASP.NET MVC

I have a data class that contains a number of fields: public class Person { public int id { get; set } public string Name { get; set; } public double Rate { get; set; } public int Type { get; set; } } If I understand Scott Hanselman's take on binding arrays of objects, I should be able to create a f...
Robert Harvey
11

votes
7

answer
969

views

What is the motivation behind “Use Extension Methods Sparingly?”

I find them a very natural way to extend existing classes, especially when you just need to "spot-weld" some functionality onto an existing class. Microsoft says, "In general, we recommend that you implement extension methods sparingly and only when you have to." And yet extension methods form the...
Robert Harvey
2

votes
6

answer
406

views

Use of Legacy “Communication” Classes in .NET Framework

I have a web application which passes long-running requests to a Windows Service on another computer, using .NET Remoting. I have been told that .NET Remoting is an obsolete technology, and that it should no longer be used. Should I rewrite the service using WCF, or leave it as it is? If I rewrite...
Robert Harvey
3

votes
2

answer
3.6k

views

Calling a method on every instance of a type in c#

I know that you can call an instance method that executes for each object. I also know that you can have a static method on the type that is callable from the type. But how would one call a method that acts on every instance of a particular type (say, to set a member variable to zero, for example...
Robert Harvey
4

votes
1

answer
467

views

Will “Temporarily Work Uncontrolled” allow me to retain VSS source control safely?

If I move a solution to another computer, and select the Temporarily Work Uncontrolled option from the SourceSafe plugin, can I move the project back to the original computer (deleting the original solution on the original computer and replacing it with my "temporarily work uncontrolled" copy of the...
Robert Harvey
2

votes
1

answer
497

views

How do I determine what assembly a namespace is in?

The MSDN documentation doesn't generally specify the assembly a namespace is in, so there's no easy way to add the necessary assembly reference. NOTE: I am using MonoDevelop, so right-click, resolve is not an option.
Robert Harvey
2

votes
4

answer
2.5k

views

Creating a standalone ASP.NET MVC application for Windows XP

Is there a way to create an installable (ideally XCopy installable) version of an ASP.NET MVC application that will run in a standalone fashion on a Windows XP machine? I don't mind installing SQL Server Express for this purpose, so I guess the question boils down to this: Can the Cassini web server...
Robert Harvey
12

votes
1

answer
3.6k

views

Convention over configuration in ASP.NET MVC

I am relatively new to ASP.NET MVC, and am very impressed with the clarity of the platform so far. However, there is one aspect that I find uncomfortable. At first, I accepted the fact that when I say return View(); I am calling a helper method that returns an ActionResult, and makes some assumpti...
Robert Harvey
2

votes
1

answer
548

views

How do I pass Url Parameters on a POST?

I have a controller method with the following signature: [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateValues(int id, MyViewModel[] array) { } The id is normally picked up as part of the Url on other GET controller methods (I have a working route that does this) I am successfully passing t...
Robert Harvey
5

votes
3

answer
5.5k

views

How do you create a unit-testing stub for an interface containing a read-only member?

I am writing some unit tests for an extension method I have written on IPrincipal. To assist, I have created a couple of helper classes (some code for not-implemented members of the interfaces has been omitted for brevity): public class IPrincipalStub : IPrincipal { private IIdentity identityStub =...
Robert Harvey
2

votes
5

answer
238

views

Updating database on website from another data store

I have a client who owns a business with a handful of employees. He has a product website that has several hundred static product pages that are updated periodically via FTP. We want to change this to a data-driven website, but the database (which will be hosted at an ISP) will have to be updated...
Robert Harvey
1

votes
2

answer
231

views

My ISP does not support ASP.NET MVC. Can I still use some of it anyway?

My ISP doesn't have ASP.NET MVC installed on their servers yet, although they do have .NET Framework 3.5 SP1 so they do have the new routing engine. It occurs to me that, if I create a model using Linq to SQL, it's possible to expose parts of the model as properties in the code behind. I could then...
Robert Harvey
1

votes
4

answer
1.2k

views

Redirecting Old Urls After Web Site Overhaul

We have a website which we recently migrated to ASP.NET MVC. All of the URLs are now different from the original website. Google still has all of our old URLs, so if anyone finds us in a search, currently they will get a 404. I have a catchall route that catches bad URLs, including all of the old...
Robert Harvey
6

votes
8

answer
2.6k

views

How do I efficiently search this hierarchical structure?

I have a data structure that looks like this: public class Node { public string Code { get; set; } public string Description { get; set; } ... public List Children { get; set; } } I want to write a method that will return a specific node, given the specified Code. Normally I would just do a recursi...
Robert Harvey
4

votes
2

answer
6.2k

views

Using CefSharp.Offscreen to retrieve a web page that requires Javascript to render

I have what is hopefully a simple task, but it's going to take someone that's versed in CefSharp to solve it. I have an url that I want to retrieve the HTML from. The problem is this particular url doesn't actually distribute the page on a GET. Instead, it pushes a mound of Javascript to the brows...
Robert Harvey
7

votes
1

answer
629

views

How do I rotate individual letters of an image into the right orientation for optimal OCR?

In my previous question, I transformed this image: into this: which Tesseract OCR interprets as this: 1O351 Putting a frame around the image actually improves the OCR result. 1CB51 However, I need all 5 characters to OCR correctly, so as an experiment I used Paint.NET to rotate and align each indivi...
Robert Harvey
2

votes
5

answer
228

views

Managing Descriptive URLs

I have noticed that many blogs use URLs that look like this: http://www.hanselman.com/blog/VirtualCamaraderieAPersistentVideoPortalForTheRemoteWorker.aspx I assume this is done for search engine optimization. How is this read from the underlying data model? Do you really search for VirtualCamarade...
Robert Harvey
1

votes
2

answer
1.6k

views

Why does moving classes into a new folder in Visual Studio break things?

I have an ASP.NET application with three areas. In the root of the application is a Models folder containing a hodgepodge of classes, including two DataContexts, some Repository classes, some ViewModel classes, some helper classes, and some business logic classes. I'd like to create subfolders for...
Robert Harvey
4

votes
6

answer
4.9k

views

How do I create a two-column snaking layout in ASP.NET MVC?

I have about a hundred short-text data items (this number can vary substantially) that I would like to put in a page and have the browser manage that into three columns within a surrounding div, arranged with the items going down and then across, like this: A F L B G M C H N D I...
Robert Harvey
4

votes
2

answer
935

views

What is the C# extension methods equivalent for this Linq query?

In this example: public void Linq40() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var numberGroups = from n in numbers group n by n % 5 into g select new { Remainder = g.Key, Numbers = g }; foreach (var g in numberGroups) { Console.WriteLine("Numbers with a remainder of {0} when divided by 5...
Robert Harvey
1

votes
4

answer
1.2k

views

Create an anonymous type object from an arbitrary text file

I need a sensible way to draw arbitrary text files into a C# program, and produce an arbitrary anonymous type object, or perhaps a composite dictionary of some sort. I have a representative text file that looks like this: adapter 1: LPe11002 Factory IEEE: 10000000 C97A83FC Non-Volatile WWPN: 1000000...
Robert Harvey
3

votes
6

answer
394

views

Is CSS layout really as delicate as it seems to be?

I have been experimenting with the Majestic template at freecsstemplates.org. So far so good; I really like the look (or to be more specific, my boss really likes the look). However, I am noticing that the CSS that drives this template seems very brittle; small changes can cause really radical bre...
Robert Harvey
3

votes
5

answer
3.6k

views

Should Lookup Table Foreign Keys Always be Indexed?

If I have a lookup table with very few records in it (say, less than ten), should I bother putting an index on the Foreign Key of another table to which it is attached? For that matter, does the lookup table even need an index on the Primary Key? Specifically, is there any performance benefit tha...
Robert Harvey
4

votes
2

answer
3.9k

views

How do I correctly dispose a Linq to SQL DataContext in a Repository?

In a Rob Conery-style ASP.NET MVC application, you typically have a repository: public class CustomerRepository { DataContext dc = new DataContext(); public IQueryable AllCustomers() { return db.Customers; } public Customer GetCustomer(int customerID) { return db.Customers.FirstOrDefault(c => c.Cust...
Robert Harvey

View additional