Wednesday, December 9, 2009

Developer showcase and contest

Do you have .NET based solution which is unique?

The Developer Platform Marketing team has launched a compelling new worldwide Microsoft® .NET Framework campaign at www.dotnetstories.com.

Through online videos and written case studies featuring real developers who built amazing and diverse solutions on the .NET Framework, the campaign is intended to tell a clean and cohesive end-to-end story that is engaging and relevant to the developer community.

GET INTO .NET CHALLENGE at www.mydotnetstory.com

for a chance to win a 12-day Galapagos Islands trip or a Smart Car!

Upload your solution before 31.12.2009

Thursday, May 14, 2009

Unlocking application files (running from cached location)

Month or two ago, I was working on project for automatic installation and upgrade of windows forms application. In preparation for the project, I was trying to modify component (dll file) on which application depends. Result from those attempts was inconsistent, When I had tryed to modify component which I had already used in my application, modification fails, but when component was unused, modification succeeded.
That was not enough for me, because requirements ask for possibility of upgrading the files at any time.
First idea was, to download new file in some subfolder and when application exits, override the application or component file. Searching the msdn for better solution, I found way to load and run application from cached folder, here is the example of Main method which I had incorporated in the solution:


static void Main(string [] args)
{
// Aplication name ( from command line )
string appName=args[0];
// Get the startup path.
string startupPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
// cache path = directory where the assemblies get
// shadow copied
string cachePath = Path.Combine(startupPath,"cachedFiles");
string configFile = Path.Combine(startupPath,appName+".config");
string assembly = Path.Combine(startupPath,appName);

// Create the setup for the new domain
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationName = appName;setup.ShadowCopyFiles = "true";
// it isn't a bool it's a string,
// developer team decide to leave that inconsistent API for
//backward compatibility
setup.CachePath = cachePath;
setup.ConfigurationFile = configFile;
// Create the application domain with same evidence
AppDomain domain =
AppDomain.CreateDomain(appName,AppDomain.CurrentDomain.Evidence,setup);
// Start appName application by executing the assembly
domain.ExecuteAssembly(assembly);
// After the application has finished clean up
AppDomain.Unload(domain);
Directory.Delete(cachePath, true);
}

Wednesday, February 11, 2009

Operator ^ in C#

Yesterday I was surprised with Question:



In VB.NET we can use caret for computing the power of some number. Example:
double power=2^3
power will have the value of 8.



How can we do that in C#?






Yes, C# is has the caret (“^”) operator, but that operator does XOR , so what to do?






Answer is relative simple:
Use the System namespace and Math class which have Method Pow
double power=System.Math.Pow(2,3)

Saturday, January 24, 2009

Custom Tool Property - Part 1

One friend of mine, developer, asked me about property custom tool.
So I start VS and try to put something what in my opinion is the name of a tool: XSD.EXE and VS gave me the message that, that tool cannot be found.



Picture 1 Setting Custom Tool ( With wrong value )





Picture 2 – Running custom tool ( with wrong settings )




Picture 3 – Result


So what next is there magic word for declaring Custom Tool to use XSD.EXE which is default when you use DataSet schema?
Yes, put MSDataSetGenerator in Custom Tool property and that will do the Magic.



Picture 4 – Setting the property




Picture 5 – Run the tool

And …



Picture 6 – XMLSchema1.cs is created

Friday, January 16, 2009

Adding xml comments

Having class like this:


using System;
using System.Collections.Generic;
using System.Text;

namespace ClassLibrary1
{
public class Class1
{
public string Method(int number, string name, DateTime date)
{
}
}
}

How easy is to put xml comments?

Very easy, just type /// before the class,method, property ...

And you will got this:


namespace ClassLibrary1
{
/// <summary>
///
/// </summary>
public class Class1
{
/// <summary>
///
/// </summary>
/// <param name="number"></param>
/// <param name="name"></param>
/// <param name="date"></param>
/// <returns></returns>
public string Method(int number, string name, DateTime date)
{
}
}
}