poniedziałek, 23 lutego 2009

enum DisplayText

http://www.west-wind.com/weblog/posts/632732.aspx

I usually don't like to use enum values as display content.
Using a custom DisplayText attribute on the enum value that is
extracted in the UI is IMHO more flexible and less code. :-)

public enum BugStatusTypes
{
[DisplayText(Text = "Entered")]
Entered,
[DisplayText(Text = "In Process")]
InProcess,
Fixed,
ByDesign,
NotReproducible,
NoBug,
None
}


Often times this will save some cross assembly refactorings that would
arise as the display text needs to be changed.

You
can then extract the display text with a simple method. (Making it an
extension methods enables calling it directly off the enum value)
public static string GetDisplayText(this Enum enumValue)
{
var type = enumValue.GetType();
MemberInfo[] memberInfo = type.GetMember(enumValue.ToString());

if (memberInfo == null || memberInfo.Length == 0)
return enumValue.ToString();

object[] attributes = memberInfo[0].GetCustomAttributes(typeof(DisplayTextAttribute), false);
if (attributes == null || attributes.Length == 0)
return enumValue.ToString();

return ((DisplayTextAttribute)attributes[0]).Text;
}


The calling code is dead simple.

string displayValue = BugStatusTypes.Entered.GetDisplayText();



The custom attribute
public class DisplayTextAttribute : Attribute
{
public string Text { get; set; }
}


What do you think?

czwartek, 22 listopada 2007

Failed To Create AppDomain

Failed To Create AppDomain

I was playing around with Visual Studio Whidbey last night and had been altering my CAS security policy. I tested what I wanted and forgot all about it.

This morning, I came to play with some of my ASP.NET demo projects and found that when I ran up the local web server I couldn't get any page to display whatsoever (everything was coming back with a "page not found").

I couldn't understand this at all and (having the memory of a goldfish) it took me ages to get back to the point where I worked out when things had last been working and when they'd stopped. I could see in the VS debugger that when the little Visual Web Developer Web Server was coming up it was throwing a "Failed to create AppDomain" exception but I couldn't for the life of me think why that might be given that it'd been working fine up until about half a day ago.

After staring at it for a while I thought a bit about what might go wrong with creating an AppDomain and security suddenly hit me and I remembered that I'd tweaked with my settings last night.

A quick;

caspol -s off

showed me that I could now run up pages in the Web Developer Web Server and a quick

caspol -reset

fixed the problem.

One to bear in mind should you find this page whilst searching for "Failed to create AppDomain".

poniedziałek, 5 listopada 2007

Serwery proxy

Dla użytkowników TPSA
217.98.20.195:8080 (w3cache.tpnet.pl)
217.98.20.20:8080 (w3cache2.tpnet.pl)

Dla użytkowników Dialogu
62.87.244.34:8080 (proxy.dialog.net.pl)

Dla użytkowników TkTelekom
82.160.0.10:8080 (w3cache.tktelekom.pl)
213.199.225.43:8080 (w3cache2.tktelekom.pl)

Dostępne dla wszystkich Polaków
193.219.28.144:8080 (w3cache.icm.edu.pl)
193.219.28.146:8080 (w3cache2.icm.edu.pl)

piątek, 26 października 2007

piątek, 19 października 2007

How to use makecert.exe

How to use makecert.exe to create a self-signed test certificate that can be used with IIS for SSL

Problem: Special options must be specified with makecert.exe, to create a self-signed certificate that can be used with IIS (Microsoft Internet Information Server).

Note: Microsoft recommends to install and use the "Certificate Server" to generate an SSL test certificate (Q216907), instead of using makecert.exe. But using makecert is simpler.

Solution:

The following command can be used to create and import a self-signed SSL test certificate:

makecert -r -pe -n "CN=www.yourserver.com" -b 01/01/2000
-e 01/01/2036 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine
-sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12

To install this certificate in IIS 5.0, open the IIS "Web Site Properties", "Directory Security", "Server Certificate...", "Assign an existing certificate" and select the new certificate from the list.

Note: Older versions of makecert.exe do not support the "-pe" option, which makes the private key exportable. If you have an old version of makecert.exe, you can omit the "-pe" option, but then the certificate cannot be exported including the private key.

(The October 2002 version of the Platform SDK (build 3718.1) contains a new version of makecert.exe (5.131) that supports the "-pe" option. The .NET Framework SDK 1.0 of 2002-03-19 contains an old version of makecert.exe that does not support the "-pe" option).

If the private key is exportable, you can export the certificate together with the private key into a PFX (PKCS #12) file as described in Q232136.

Note: SSL server certificates for IIS are stored in the "Personal" ("My") certificate store of the "computer account" ("localMachine"). The "Certificates" snap-in of the Microsoft Management Console (mmc.exe) must be used to manage these certificates. The normal certificate management window (accessible via "Internet Properties" / "Content" / "Certificates" or via "Control Panel" / "Users and Passwords" / "Advanced" / "Certificates") cannot be used.

Note: To create a key with more than 512 bits, use the "-len" parameter of makecert.exe.

piątek, 12 października 2007

http://joe.truemesh.com/blog/000390.html

wtorek, 9 października 2007

error during asynchronous processing

There was an error during asynchronous processing. Unique state object is required for multiple asynchronous simultaneous operations to be outstanding.

Solution: Guid.NewGuid()
cimMesgProc.exchangeMessageAsync(cimExMesg, Guid.NewGuid());