Friday, December 14, 2007

Iterating through Enum

Every time i need to iterate through enum, i forget how to do it... so, for the last time:

foreach(byte b in Enum.GetValues(typeof(CounterPartyVO.CounterPartyTypes)))
Console.WriteLine("{0} : {1}"
, b
, Enum.GetName(typeof(CounterPartyVO.CounterPartyTypes), b)
);

Tuesday, December 11, 2007

ReSharper

Just ran into this add-in and it seems extremely usefull - ReSharper. I especially like the null detection (nightmare with junior devs)... at $199 looks like a good deal to me.
Also, Elegant Code is definately worth keeping an eye on - can't wait for some more in-depth feedback on the VS 2008 stuff (especially testing, since i'm still not ready to give up n-unit).

Friday, December 07, 2007

Graphs on Web

Google came up with yet another cool service - graphs!
Here's kind of SDK and there's also very nice article about it (in czech though).

There's also a paid site here - i believe it's $69 or so. Pretty cool!

Wednesday, November 28, 2007

UserControls based on abstract classes in designer

I really hate the fact, that VS doesn't allow to display design of user controls (of forms) based on abstract classes.
Here i found solution to the problem - basically "fooling" the designer with substitute artificial instance. It's just a little messy (especially when you have abstract classes in different assemblies), but it seems to work. Mentioned example is done for forms, but works equally well with user controls.

Tuesday, November 27, 2007

Extending indexer on collection in C#

I was looking for a way to implement alternative way to access members of List (or any other collection) through index. By default i could use only:

myCol[0].Value

What i'd like to use is:

myCol[strKey].Value

The way to implement it is through property (code-fragment only):

public MyColItem this[string strKey]
{
get { return #code to get the item#; }
set { #your code#; }
}

ASP.Net 2.0 Precompilation

Since i never remeber the command-line for precompilation, i found AspNetCompiler very handy...

Thursday, October 11, 2007

Debugging in VS2005 using NUnit

As I'm using NUnit more and more (i really started to fall in love with the whole unit-test concept), i find it sometimes useful to be able to debug while running the unit-test. Turns out to be quite easy. This is how it's done:
1) Put your unit-tests into separate project (I do that anyway to keep the NUnit out of "live" references) and compile it (make it either exe or dll, no difference).
2) Start NUnit, browse the compiled dll/exe (from step 1), select "File -> Save as" and save the nunit project. I typically save it in the project's root as "myproject.nunit".
3) Open the project's properties, "Debug" tab.
4) Set "Start Action" to "Start external program:" and browse the "nunit.exe" (e.g. c:\program files\nunit 2.4.1\bin\nunit.exe)
5) Set in the "Start Options" the "Command line arguments" to point to the nunit project you created in step 2. If you did the same as me, i.e. saved it in the project's root, the path should be something like "..\..\myproject.nunit"

And that's it! Just run the debug with F5 as usuall and it'll open NUNIT environment. Set break-points wherever you need in the code and run the appropriate test...

Monday, October 08, 2007

VS 2005 - error while loading form into designer

I get this error quite frequently:
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes. TypeLoad failure. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.


Aparently, it's a problem in VS and there's a hotfix available for it. Restarting studio works as well, which is what I do.

Friday, October 05, 2007

Backup data using ROBOCOPY

Need to set up some way of making backups of data from my drive. There's a ROBOCOPY utility in the Win2003 Resource Kit which should do the trick. I found even Robocopy GUI, which generates the script for you. Once you have the CMD file, just put it into scheduler.

Thursday, October 04, 2007

Overriding operators in C#

In one of my projects, i thought i'd love to use operators like ==, !=, > and < style="color: rgb(51, 51, 255);font-size:85%;" > public static bool operator ==(BaseEventVO evt1, BaseEventVO evt2)
{
return (((object)evt1 == (object)evt2) || ((object)evt1 != null) && ((object)evt2 != null) && evt1.IdSeq == evt2.IdSeq && evt1.Year == evt2.Year);
}

public static bool operator !=(BaseEventVO evt1, BaseEventVO evt2)
{
return !(evt1 == evt2);
}

public static bool operator >(BaseEventVO evt1, BaseEventVO evt2)
{
return (evt1.Year > evt2.Year || (evt1.Year == evt2.Year && evt1.Day > evt2.Day));
}

public static bool operator <(BaseEventVO evt1, BaseEventVO evt2)
{
return (evt1.Year < evt2.Year || (evt1.Year == evt2.Year && evt1.Day < evt2.Day));
}


Notice the cast to "(object)evt1 != null" - it is necessary in order to prevent loopback - you can't do "evt1 != null" as it'd use the "!=" overridden operator, hence ending in effective infinite loop (until call-stack blows).

You may also want to override GetHashCode() to produce unique ID of the object - speeds up things very significantly when you do hashtable lookups.

Saturday, September 29, 2007

Number Formatting in C# using String.Format

Just so that i remember it next time. Number formatting examples (for US english):

double x = 12345.6789;

String.Format("{0:n0}") ... 12,345
String.Format("{0:n1}") ... 12,345.6

etc...

Thursday, September 27, 2007

Vaccination for Peru

When travelling to Peru, you'll need following:
  • Tetanus
  • Typhoid
  • Hep A (if you do 2nd shot within a year, you get 10yrs immunity)
  • Yellow fever
I also picked up tablets for Malaria and high-altitute sickness... Total damage about $100 :(
Oh well, better be safe than sorry i guess...

To check current situation about travel health issues, goto CDC - especially the malaria is quite important.

Recording video (AVI/SFW)

I'm doing quite a bit of demos lately and it's starting to take way too much time. Same with writing "how-to's" for new releases. So I decided to record short sessions where I demo how to use the software and ship them along with the ClickOnce deploy. Pretty sweet I must say and users seem to like it as well.
I'm using CamStudio - excellent tool, supports regions, converions, annotation, audio recording, etc. simply great!

Thursday, September 13, 2007

TFS Install

I've ran into some issues during the TFS install. First, we'd like to use the dual server configuration (having DB server separate). What I didn't expect is limitation of TFS to default instance! Well, here seems to be a workaround (can't confirm it yet though) in case you need to use named instance as we do.
The install process is quite complex task too - Cliff's blog post is quite a nice summary of the core things to do.

Monday, September 10, 2007

ASP.net Permissions - protecting non-asp.net content

The allow/deny approach works very well for all asp.net content, but i needed to secure all the documents in protected folders - namely PDF, XLS and DOC files.
Here is excellent description how to do it - it uses wildcard mapping feature of IIS.

Tuesday, September 04, 2007

ASP.NET 2.0 CSS Friendly Control Adapters

One of my students showed me this about a year ago and since then I've been looking for the link again. Basically, these adapters replace the table-oriented rendering of most of the ASP.Net build-in controls with light-weight "div" versions, that support CSS styling.
Anyway, check it out yourself...

Thursday, August 30, 2007

ASP.net Membership, Roles and Profile

I'm finally playing with the membership part of asp.net - works great, but i may need to develop it w/o using any kind of database - preferably all in plain XML files. It should be fairly easy, since it's all done using the provider model.
Here is a great resource - links all info in one.
4 guys from rolla did a great job as they always do - this part even has a section of code that i may use (still need to build on it though).

Update: CodePlex has complete example on the XmlProvider implementation, which includes Profiles, Memberships and Roles.

Thursday, August 23, 2007

Running Access 2003 and 2007 on the same system

I'm running 2003/2007 office on the same system (Vista) and every time i was switching between versions, i got that stupid install dialog. Well, here is the solution.
In short, run this:

reg add HKCU\Software\Microsoft\Office\11.0\Access\Options /v NoReReg /t REG_DWORD /d 1

reg add HKCU\Software\Microsoft\Office\12.0\Access\Options /v NoReReg /t REG_DWORD /d 1

More information is in this KB article.

Friday, August 17, 2007

Getting current / calling method info (C#)

Getting current method:
System.Reflection.MethodBase.GetCurrentMethod()

Getting calling method:
System.Diagnostics.StackTrace st =
new System.Diagnostics.StackTrace(false);


System.Diagnostics.StackFrame sf =
st.GetFrame(1); // previous method

return sf.GetMethod();

Wednesday, August 15, 2007

Calling WebService from VBA

Instead of struggling with writing the code yourself, use Microsoft Office 2003 Web Services Toolkit 2.01. It generates the proxy for you - nice and easy.

Open linked report in new window

Unfortunately, there's no simple way to open linked-report in new browser window. The work-around is to use the URL link, rather than report, however that has couple of issues. (a) you have to specify the location, which is a problem if you have dev/test/live environments (basically you have modify the report for each). (b) passing parameters is possible, but can be tricky in case you're passing complex texts.

Here is detailed solution.

In short:

Non-parameterized Solution
="javascript:void(window.open('http://servername
/ReportServer?%2freportFolder%2freportName&rs:Command=Render'))"



Parameterized Solution
="javascript:void(window.open('http://servername
/ReportServer?
%2freportFolder%2freportName&rs:Command=Render
&MyParam1=" & Fields!MyField.Value & "'))"

Couple things to know:

1) Notice that you have to use "http://server/
ReportServer" and NOT the "http://server/Reports" link!

2) In case your "reportFolder" and "reportName" contain spaces, either leave them there or replace them with "+" (e.g. "My Report" -> "My+Report").

3) Notice the "
&" in parametrized solution - it's safer to use than "+", because it will force string conversion on the parameter value.

4) There are more parameters you can use to modify the way the report is presented. Nice description is in this MSDN article.

Tuesday, August 14, 2007

TFS Evaluation - thoughts

I've spent last couple of days evaluating TFS along with the Team Suite version of studio. Luckily, as a trainer, i have access to the MOC 2631 course, so I was able to actually test the stuff rather than just reading about it.

Prior to this, i've evaluated SourceSafe 2005 as well as Perforce - needless to say, SS doesn't match PF by any means. PF intergrates with VS quite nicely - it may not be as smooth as TFS (especially when it comes to solutions/projects), but still good enough to keep developer happy.

For testing, i evaluated NUnit. TFS offers much more that that though (code-coverage tests, load tests, etc.).

Here are couple of my thoughts:
1) TFS server is running for about $2700 if i'm not mistaken. The real killer is VS Team Edition. If you combine that with "Visual Studio Team Suite with MSDN Premium", you're looking at almost $20,000! Ouch. Compare that to "Visual Studio Professional Edition with MSDN Professional" for $2000... It already includes license for SS! Perforce is kind of pricey as well - $750 per user.

2) What i really like about VS-TS is the integration of work-items with everything (code changes, artifacts, builds, etc.) User logs a bug, you fix it in "myobject.cs" and when you check-in the file, you just link it with the bug work-item. This really kicks a$$.

3) I haven't had a chance to do a research on UI tools for work-items though. I hope there's something that would allow regular users to add/view work-items - and I sure hope it won't require CAL for each user!

4) Documentation. We all hate it, avoid it, fake it... I've tested couple of the diagramming tools in VS-TS and I have to say i was pleasantly surprised. As an architect, I can quickly draw top-level diagram, drill down to application diagram, code-generate from that to give it to the developers. Nothing impressive yet - get this, it propagates changes in the lower-level diagrams back to the upper level ones! Still need to play with this in some real-life scenarios, but so far very impressive.

5) Policies. Oh developers are gonna hate me now - I can actually FORCE them to TEST before they submit changes back to repository.

6) SharePoint site - i'm still kind of undecided on this one. I like the idea of sharing documents in SP for each project, having them version-controlled, etc. I just don't like SP and then I'm worried about maintenance...

Final words - so far, I'm inclining towards the TFS. Yes, it's very expensive, but if you need to put process around your app development and actually have a tool that helps, i think this is the way to go. Can you do all the stuff without it? Certainly yes, but expect to pay for some of the tools (Perforce, etc.) and don't expect them to communicate as seamlessly as TFS...

This FAQ may have some questions for you as well, plus many TFS links...

Thursday, August 09, 2007

Windows Explorer has stopped working - Vista error

After about a month of being happy with Vista, i ran into this message. It all started by Vista not being able to restore from hibernation. Then, when it attempted to start normally, after log on two messages kept coming up with "Windows Eplorer has stopped working" and that Vista is restarting it... over and over... After skimming through web and basically not finding a resolution, this is what I did:

1) Restarted Vista in Safe Mode - didn't do any good - the error appeared even there.

2) Restarted Vista in Safe Mode with Command Prompt
- there i ran "MSCONFIG" and:
a) Disabled all non-microsoft services
b) Disabled all start-up programs
c) Disabled UAC (some posts on web suggested that it might be the cause of problems)

After restart, the issue was still present. So back to the Safe Mode with Command Prompt:
d) open the Event Viewer (you'll find it in the Tools tab) and check application log. In my case, there was an error that windows can't read the file "C:\Users\...\AppData\Local\Microsoft\Windows\Explorer\thumbcache_idx.db".
e) run command (from Tools again), and rename the file (using "move") or even delete it.

Restart and all good! Vista will then show dialog that you modified the start-up options and whether you want to take your changes back to "Normal" - do so, restart again and you sould be back in business...

Monday, July 23, 2007

Couple of BizTalk 2006 Resources

These are worth your attention:

1) BizTalk Server Documenter - generates CHM documentation on BT artifacts (orchestrations, etc.) You'll need the Microsoft's Help Compiler in order to user it as well. Notice that you may need to make modification to the config file - depends on where you have the hcc.exe located. Works like charm with BT 2006, you can choose assemblies or even orchestrations that you want to document. It generates pictorial description of orchestrations too. Extremely helpful!

2) BizTalk Server Pattern Wizard - this one can be a bit tricky to set up and use. After download, execute the "BTPatternsWizardSS\BizTalkPatternWizards\Debug\setup.exe" to install the wizards into your VS. Then start a new project, and find the templates under "Biztalk Projects/Pattern Templates". I also highly recommend reading the "BTPatternsWizardSS\WizardDocumentation.doc" - it contains links to detailed descriptions of the patterns. Finally, there are videos (370MB) available which describe the patterns on examples.

Thursday, July 19, 2007

SharepointServices - crawler error

You may receive "Access Denied" erros in EventLog (Application) from SharepointServices, that it can't crawl... something like "The start address cannot be crawled". Here you can find nice description why. And here is the fix.

Short story: Create a DWORD registry key at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Lsa named DisableLoopbackCheck and set the value to 1, for TRUE, to disable the loopback checking.

BizTalk 2006 - working with WebServices

To effectively call WebService (WS) from BizTalk (BT), you have perform couple of steps. I'm going to list one of the scenarios, where you call WS from orchestration and you need to pass parameters along as well. To make this work, do following:
1) Add WebRefernce to your BT project
2) In the orchestration, add new port and select existing port type (select appropriate WS port in the "Web Port Types" at the bottom. You can either specify now or later.
3) Add Send and Receive shapes to your orchestration
4) Add 2 messages to the orchestration (msgRequest, msgResponse). The message types are in "Web Message Types" - just select appropriate for your method call and request/response.
5) Connect the send/receive shapes with appropriate methods on the port.

This sounds simple enough, but now you have create the request and populate with parameters. This can get tricky, depending on whether you're using primitive types (int, string, etc.) for parameters or complex types. Here is excellent description.
I would only add that in case you work with primitive types and want to simply assign values from some other message, you need to make sure that the fields you want to use are distinguished (otherwise you'll not see them on the message when you "." it)!

Finally, when you deploy, you'll have to create physical port in BT (unless you used "specify now" option). You need to create Send Port, type "SOAP", Send/Receive pipelines are "PassThruTransmit". In the "Configure" section, put the ASMX link to the URL. Note that you can specify authentication there as well, which may be very handy if your WS doesn't allow anonymous access.

Should any errors occur, you'll find them in the Event Viewer - also check for suspended (dehydrated) orchestrations in the BT admin console.

Monday, February 26, 2007

BizTalk 2006 : SQL Receive Location

If you're not sure that your SQL Receive Location is running or not, check Event Viewer - any problems would be reported there.

You may run into issued with MSDTC - e.g. see an error in Event Viewer saying the the MSDTC on the host computer is not running. Restarting the MSDTC is usually the trick (go to Component Services > Computers > My Computer > right-click and Stop/Start MS DTC)

Wednesday, January 31, 2007

BizTalk 2006 : can't create instance error (XLANG/S)

If you get error like:

Could not load type "B2BSchemas.PO_Num" from assembly "B2BSchemas, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d7b72bf643e25262".

Check that:
  1. Your assembly is correctly deployed in BizTalk (i.e. check in Resources) - look at the version and ID
  2. Your assembly is in GAC (again version & ID)

If both are ok, BizTalk is "messed up" and you need to restart the host instance (ie. Platform Settings > Host Instances, select the instance you're using and right-click > Restart).

BizTalk 2006 : Installing assemblies manually

In the BT admin console, when you try to register assembly manually (under YourApp/Resources -> Add -> BizTalk Assembly), make sure that the 1st option in the Options part (bottom) is checked. It ensures that the DLL gets registered in GAC as well. If you register assembly w/o having it in GAC, at first it appears to act normal (e.g. you can start orchestrations, etc.), but it can't create instances or schemas, etc...