.net

How are asp.net mvc 2 controllers instantiated?

When an asp.net application is notified of a URL, it routes it to the appropriate controller and specifically to the appropriate method. Are those controllers placed upon the stack once? Or do they get instantiated again for each request? For example, say I have a controller with a linq-to-sql class that gets instantiated in the declar...

Restoring a control's position and size inside the form at runtime. (.NET)

Hi, I have a DataGridView in one of my form which at a certain point I resize an change it's position. I would like to be able to restore it to the designer's default position at runtime. I know I could save it before changing and then restoring it later, but I feel like there surely is a way in .NET to just restore a control position t...

OOP/OOD Coupling question

I have a function that returns the orders for a given period. I've create a Period object which ensures that, when specifying a date range, the start date is <= to the end date. Likewise, if dealing with a month period, the start and end dates of the period should be the first and last days of the month, respectively. My question is thi...

Find if an item in one IEnumerable is also in another IEnumerable

I have 2 IEnumerable of Type1 and Type2, ie. IEnumerable<Type1> & IEnumerable<Type2>. Type1 and Type2 have 1 common field, called TypeID. Multiple of same TypeID may exists in IEnumerable<Type2>, I would like to check against the 2 IEnumerables and if TypeID inside Type2 equals to TypeID inside Type1, I would combine the 2 into a new obj...

What is CAPICOM DES doing under the hood?

I found a link that explains what CAPICOM does for 3DES (Understanding Capicom), but I'm not sure if this is directly applicable to the single DES algorithm that CAPICOM does. It seems that CAPICOM does some proprietary stuff to derive the actual key it uses to encrypt. It also puts a lot of header information in front of the encrypted ...

Problem with data binding in C#

I'm trying to understand better how data binding works in .net. I was checking this article, and I came up with this code: public partial class Form1 : Form//, INotifyPropertyChanged { public event PropertyChangedEventHandler MyTextChanged; [System.ComponentModel.Bindable(true)] public string MyText { get { retu...

Can I define a method to accept EITHER a Func<T> OR an Expression<Func<T>>?

If I attempt to write two overloads of a method, one accepting an Expression<Func<T>> parameter and another accepting a Func<T>, I will get a compiler error on trying to call the method with a lambda expression because the two signatures create ambiguity. The following would be problematic, for example: Method(() => "Hello"); // Is that...

How to generate a XLS or XLSX with a Stored Procedure?

My client needs to read some queries using Excel or something like it, so I need to generate XLS calling in some queries in stored procedures. Basically I have the SP, I have the View Done, and the query working fine, but I don't know how to make an xls or an xlsx with the SP itself. Is there any good practice or some specific steps I...

Multiple key lookup for Dictionary

I am parsing a file and I would like to store it in a lookup structure in a way that I can lookup with two keys. I have a User Entity that has name, email and id, types are irrelevant. I would like to store it in a Dictionary<User, id> so I can get the user id by looking up with User. I also want the other way around, ie : Dictionary<...

Modeling NHibernate queries

Usually I'd put my criterias/hql queries in a repository/dal class related to the entity, but lately I'be been thinking of adding another abstraction that represents what a query is, this would give me the possibility of adding common behavior to all queries (e.g. pagination) in a base class, etc. so these are my components now; generi...

Custom or .Net Class as COM parameter or ouput

Hi all, can anyone point me to an example that show how to pass and/or return a class from a .NET class exposed as COM. The COM consumer would be a VBScript. Also, it is possible to pass an object from VBScript to a .NET-COM exposed method? For example [ComVisible(true)] public class A { public SomeClass MethodName(NameValueColle...

FileStream and memory usage

I've written the following program which purpose is to create a file of a give size with some random data in it. The program works fine and does what it's suppose to do. However, I don't understand why it consumes 5GB of RAM (see screenshot of my Task Manager). While I am writing the file with random data, I am not creating new objects. ...

Checking if field data changed before leaving page

How should you place one validator on a masterpage that wont allow postback of any content pages until all changed control data on that page has been either saved or canceled. The specifics of my current situation and the way its currently being done on my project are listed below This is an IE web application. The application is curre...

Attach/bind the same set of commands to multiple controls

I have a Control inside a Canvas and I want to be able to move it using the arrow keys. For the sake of trying things out, I created the following class, which does what I want. <Window x:Class="DiagramDesigner.CanvasControlArrowKeyTest" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://sc...

Roll populating a Dictionary into a LINQ of For expression

I have a data object Data = class public s: string; i: Integer; end; with many of them in a list (or some collection): var ol : List<Data> := new List<Data>; ol.Add(new Data(s := 'One', i := 1)); ol.Add(new Data(s := 'Two', i := 2)); ol.Add(new Data(s := 'Three', i := 3)); ol.Add(new Data(s := 'Four', i := 4))...

Where does Microsoft.Practices.ServiceLocation come from?

Does any one know where Microsoft.Practices.ServiceLocation comes from? This is a namespace and a dll used in MS EnterpriseLibrary. Admittedly it's a very simple dll with just a handful of classes (using reflector), but I can't find published source code for it. It's not in Enterprise Library project and not in Unity project. So does so...

System.Net.Mail.MailMessage, Adding an image to a mail message

I need to add images to a mail message and need them to be place at a specific point. Nothing too fancy just after some text but before some more text. Is this possible?? Thank you! ...

Move a control inside a Canvas using directional keys

I have a number of controls inside a Canvas element and I want to be able to move them inside the Canvas using the arrow/directional keys (up, down, left, right). What's the easiest way to do this in WPF/code-behind? Is there an idiomatic WPF way of doing this? I guess I should clarify: I want to be able to move each control independent...

LambdaExpression CompileToMethod

I Have a few lines of code public void CreateMethod<TContract>(Expression<Action<TContract>> method) { var innerMethod = Builder.DefineMethod("SomeName",MethodAttributes.Private); method.CompileToMethod(innerMethod); //more code } However the second line fails. I've tried with different versions of DefineMethod with little lu...

Get network tracing information without enabling tracing

I'm writing a little proxy server, and I'm trying to debug a problem. If I refresh the browser twice quickly, my proxy throws an exception, usually with no stack trace or indication of where the problem is. I have a hunch it has to do with a socket being closed prematurely by the browser, or being used for two different requests in my pr...