Tuesday, March 22, 2011
Maven auto increment build number
In the pom.xml file add following plugin:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>true</doCheck>
<doUpdate>false</doUpdate>
<format>${version}.{0,number}</format>
<items>
<item>buildNumber</item>
</items>
</configuration>
</plugin>
Now the $buildNumber value can be used from inside the pom file e.g. this way:
<build>
<finalName>
${project.artifactId}-${buildNumber}
</finalName>
Every time build gets to the maven validate phase, there is a buildNumber.properties file created or updated with current build number. However there is a catch.
This solution is good if the buildNumber.properties file is not being moved or deleted and I have learned that if the file is gone, the build number will be reset to 1 again, making this not usable, especially on dynamically created build agents, as it is used in my organization (Teamcity and Amazon EC2 integration).
More information about the build number plugin: http://mojo.codehaus.org/buildnumber-maven-plugin/
Tuesday, February 22, 2011
Parsing XML time value with java SimpleDateFormat
<startTime>2011-02-23T08:00:
Monday, February 21, 2011
Embedded mule ESB Java web services deployment and configuration to Tomcat server
Tomcat setup:
- Install Tomcat server (e.g. version 6.0 - requires Java 1.6 installed)
Deployment or upgrade of web services
- Place the war file (WebApplicaton_War_File_Name.war) file in Tomcat_Home\webapps
- Start / Restart Tomcat
Service url configuration
(Tomcat_Home\webapps\WebApplicaton_War_File_Name\WEB-INF\classes\mule-config.xml)
by changing endpoint address value
-After configuration changes restart Tomcat server.
Testing if correctly deployed
Troubleshooting
Tomcat_Home\logs
Resolving invalid target release error, java maven build
Friday, January 7, 2011
Attaching debugger to .NET Compact Framework on mobile device (or emulator)
Enable Managed debugging on the mobile device - by default it is disabled to not affect performance.
Run Visual Studio Remote Tools> Remote Registry Editor and choose the Mobile Device/Emulator
Add/Change following key in registry
Go to the :
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETCompactFramework/Managed Debugger/ and set the AttachEnabled value to 1
if the 'Managed Debugger' key does not exist just create it, the same with AttachEnabled value (new DWORD Value with name: AttachEnabled and value: 1)
In the Visual Studio go to Debug > Attach to Process
In the Transport choose Smart Device
Browse for your Device/Emulator
Choose the application and attach debugger ( if an application have been opended before making changes in the Device Registry you may have to restart the application )
Right now (if the symbols are loaded) you can start debugging application. Voila!
Eclipse conditional breakpoints
1) on the Debug perspective go to Breakpoints view
2) Right-click the breakpoint and choose "Breakpoint properties" (or select the breakpoint and press Alt+Enter)
3) On the properties window enable checkbox "Enable condition" and type a condition expression, breakpoint can be hit when condition becomes true or the condition value changes-it is all configurable.
That's all, although setting conditional breakpoint is not as intuitive as in Visual Studio, it works and does the job!
Monday, March 1, 2010
Sun VirtualBox and Windows Mobile Emulator issues
I have been using VMWare for hosting virtual images of development but i got some serious performance issues after starting more than one virtual machine. Someone suggested using Sun Microsystems VirtualBox and I can say that everything ran very well until I had to configure Windows Mobile Device Emulator 6.5 Professional. After starting the Emulator (during "install device drivers" pop up) the whole guest operating system (Windows 7) got frozen and plugging the power off was the only solution.
I have searched for possible solution on the internet but could not found similar case; anyway I don't believe it happened only to me ;)
Temporary solution was switching back to VMWare (VMWare Player in this case) where the Windows Mobile Emulator works fine there.
Friday, February 26, 2010
Migrating ClickOnce deployment to IIS7 and Fiddler Web Debugger
After migrating ClickOnce deployment to IIS7 I tried to install the application I got following exception:
System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
- Downloading file_name_.extension did not succeed.
I have checked the log but still I could not figure out what exactly was wrong and my colleague suggested using the Fiddler (thanks Benny!) – great Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. The Fiddler allows you to inspect all HTTP(S) traffic, set breakpoints, and "fiddle" with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language.
Fiddler helped me found out that there were some missing MIME types configured on IIS 7. IIS uses a default list of global MIME types to determine which types of content to serve. If a client requests a MIME type that is not defined on the Web server, IIS returns a 404.3 error (according to MSDN). To fix this I had to add those missing MIME types in the IIS7 configuration.
After adding MIME types to the configuration I got again the same exception but this time a ".config" file could not be downloaded and again the Fiddler helped me figure out what was wrong. This time it was Request Filtering - IIS7 has really many types denied in request filtering by default. If your ClickOnce application contains .config file you have to allow this extension in request filtering feature.
After allowing the ".config" extension in request filtering feature in IIS7 the deployment started to work. Problem solved.
Thursday, February 25, 2010
How to deploy service on IIS 7
Recently I had to deploy compiled services on IIS 7. When I tried to make the services work I have encountered a couple of problems, mostly caused by differences between IIS 6 and 7. IIS 7 seems to be totally different than version 6. Here is a short guide how to make services work.
- IIS 7 does not work with WCF by default - following command has to be executed from the command line
"%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -r –y
- Compared to IIS 6 services instead of being kept in virtual directories have to be created as an application. I have created virtual directories first and then converted them into applications
- Make sure that the service assemblies are in the bin folder under the virtual directory!
If the assemblies are not in the bin folder the server will respond with following error:The type 'YourServiceName', provided as the Service attribute value in the ServiceHost directive could not be found
If you see the above error, the most probable reason is that you don't keep the assemblies in the bin folder. It took a while before I have found this out J
- This is not necessary but can improve security - set permissions for IIS_USR and Network service (read & execute; list folder contents; read)
After applying above steps the service should work like a charm J
Thursday, February 11, 2010
SQL Server Management Tools installation problem and Windows Installer CleanUp Utility tool
Sunday, January 24, 2010
Setting up playground bug tracking system (Bugzilla on Win7 and IIS 7)
I have decided to improve my coding playground by setting up bug tracking system. I took a look at some open source tools and decided to install Bugzilla (http://www.bugzilla.org) which is widely used in many organizations and projects. I use Windows 7 and instead of recommended Apache server I used IIS 7.
Information on how to set up Bugzilla on windows environment can be found here: https://wiki.mozilla.org/Bugzilla:Win32Install
Most of the installation steps are quite straightforward; anyway it takes a lot of time to install and configure all the required components.
NOTE: if you plan to use smtp.gmail.com as SMTP do not install Perlx64 but Perlx86 (I could not install the required Email-Send-Gmail perl package)
There were a couple of issues during installation… The default installation of IIS 7 on Windows 7 is missing some required modules like ISAPI extensions etc. Click here for instructions how to do it.
Adding Script Modules on IIS 7 is quite different then on previous versions of IIS which goes like this: Select the virtual directory in the IIS (e.g. Bugzilla), then open feature Handler Mappings then 'Add Script Map' from context menu. Two Script Maps has to be added – for Perl and for CGI; for both choose Execute in Edit Feature Permissions.
For Perl type as follows (providing correct path)
Request path: *.pl
Executable: c:\Perl\bin\perl.exe "%s" %s
Name: Perl Script Map
Press 'OK'
Say 'YES' to ISAPI message
And the CGI:
Request path: *.cgi
Executable: c:\Perl\bin\perl.exe -xc:\bugzilla -wT "%s" %s
Name: CGI Script Map
Press 'OK'
Say 'YES' to ISAPI message
After running "checksetup.pl" from <BugzillaFolderPath> I got notifications about some missing required Modules so I had to execute following commands and again run checksetup.pl
ppm install DateTime
ppm install DateTime-TimeZone
ppm install Template-Toolkit
ppm install Email-Send
ppm install Email-MIME
ppm install Email-MIME-Encodings
ppm install Email-MIME-Modifier
Now, after executing 'checksetup.pl' the localconfig file was created and has to be updated with correct mySQL db_pass and db_port information
Since Bugzilla requires an SMTP to function on Windows another problem occurred because SMTP/POP service is not included in Win 7 J I have used smtp.gmail.com since I have an account there… however it does not work!
Gmail uses TSL protocol and to make it work some hack is required as described here.
After providing the necessary information you should be able to access http://localhost/Bugzilla or whatever name you have chosen for the virtual directory in IIS.
Saturday, December 19, 2009
Drag’n Drop files in WinForms
Recently I have been playing a little bit with drag and drop functionality and this short article shows how to implement drag and drop for files in WinForms.
The first thing is to set the AllowDrop property to true for the control we are going to drop files, without it drag'n drop events are not fired. I have used ListView control listView1 to display some basic file information about the dragged file e.g. file name, path and size. To make it more fun lets allow dropping multiple files at the same time, which is a standard Windows behavior.
Next thing is create DragEnter event handler in which dragged data is being checked and Effect property is set. You might want to add some conditions e.g. allowing files with certain extension.
It may look something like this:
private void listView1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
Now is the time for the DragDrop event handler, in which the file names are retreived from the dragged files and passed to the method which does the rest of job i.e. adds data to the listView1 control.
private void listView1_DragDrop(object sender, DragEventArgs e)
{
try
{
if (e.Effect == DragDropEffects.Copy)
{
string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];
if (fileNames != null)
{
foreach (string s in fileNames)
{
Console.WriteLine(s);
AddFileInfoToTheListBox(s);
}
}
}
}
catch (Exception exception)
{
Console.WriteLine("Exception in listBox1_DragDrop: " + exception.Message);
}
}
Here is the AddFileInfoToTheListView method definition. It might be not the most elegant way of handling data but for the purpose of this example it is fine. To get information from the dragged file the FileInfo class is used.
private void AddFileInfoToTheListView(string fileName)
{
try
{
FileInfo fi = new FileInfo(fileName);
string [] fileData = { fi.Name, fi.ToString(),fi.Length.ToString() };
ListViewItem lvi = new ListViewItem(fileData);
this.listView1.Items.Add(lvi);
}
catch (Exception exception)
{
Console.WriteLine("Exception in AddFileInfoToTheListView: " + exception.Message);
}
}
And here is the final result
Friday, October 23, 2009
SyntaxHighlighter
SyntaxHighlighter is an excellent tool for highlighting code syntax in blog posts. It works with many different languages, here is the full list.
If you'd like to see how your code is going to look, take a look at this post about Trace statements , I updated it to use the SyntaxHighlighter.
The tool is completely free of charge. You don't even have to download anything, just use hosted version and voila.
Its creator definitively deserves a couple of beers!
Wednesday, September 30, 2009
Strong name assembly and unit test project (InternalsVisibleTo attribute)
I tried to create a test project for a strong name assembly and I've encountered following error
Friend assembly reference 'TestProject1' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.
In order to fix it, the test project assembly has to be strong signed as well. The thing is that the test assembly needs to get access to the private members in the tested assembly, so it has to be decorated with the InternalsVisibleTo
attribute and should look like this:
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("TestProject1, PublicKey=PUBLIC_KEY")]
Where TestProject1 is the name of the test assembly which need access to private members, and PUBLIC_KEY is,as the name suggests, the public key value of tested assembly. But how to get the PUBLIC_KEY value?
> sn –Tp AssemblyFileName
And this information is displayed; we need the public key
Public key is
0024000004800000940000000602000000240000525341310004000001000100537d27966b492e
6e4402d93b86848897b04781de2bf54fbef46671e3163d817d43bed3a786eeaa0e5beda76cda89
ec6845deef5d2852165bac0a4df08a22bb8fccec93c4c24ed7803886178b6d4279488b7800eac0
bbfa6357e3c52d6bb19bb278056955fba5f4c85fa18164088ca18377f15d74d9b75e0fd58cd053
97cdc7de
Public key token is fd41b11fd220edb5
So the attribute at the end has this form:
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("TestProject1, PublicKey="+
"0024000004800000940000000602000000240000525341310004000001000100537d27966b492e"+
"6e4402d93b86848897b04781de2bf54fbef46671e3163d817d43bed3a786eeaa0e5beda76cda89"+
"ec6845deef5d2852165bac0a4df08a22bb8fccec93c4c24ed7803886178b6d4279488b7800eac0"+
"bbfa6357e3c52d6bb19bb278056955fba5f4c85fa18164088ca18377f15d74d9b75e0fd58cd053"+
"97cdc7de")]
After adding above attribute I could build without the unit test project any issues. Problem solved.
Wednesday, September 23, 2009
FxCop
FxCop is a great free tool for static code analysis, which checks managed code assemblies for compliance with .NET Framework Design Guidelines. FxCop is available both as GUI and a command line tool, so it can be easily used in build process. Certain messages can be excluded from future reports if you can intentionally avoid rules. New custom rules can be created using FxCop SDK.
If you recently updated Windows SDK to version 7, the FxCop installation file can be found in the Windows SDK v7.0/Tools/ directory.
To use GUI version of FxCop just start the application, add targets i.e. assembly or assemblies which you want to check and click Analyze button. After a while, depending on the assembly size, you will get the report.
Every message should be reviewed and one of the following actions should be taken
- If there is a code defect - fix the code
- If rule broken intentionally – exclude message
- If message generated is false– exclude message
After you fix the code for all other messages rebuild the assembly and analyze the code again.
FxCop is great tool for all .NET developers, especially for these who are not familiar with .NET Framework Design Guidelines. FxCop can help you write robust and easily maintainable .NET Framework code.
Monday, September 21, 2009
Extension methods – great new feature of C# 3.0
C# 3.0 has a new great feature which is extension methods. It basically allows you adding methods to already existing types without recompiling, creating derived types, and yes it can be used with sealed types!
Let's take a look how to create an extended method for string type which checks if string is empty or null.
Ok we have a method defined, let's see how to use it – it couldn't be simpler, just type method name after string object. As you can see Visual Studio IntelliSense shows it as an extension with arrow shape icon.
I think extension methods are great feature making developer life easier and what's important code just looks cleaner and simpler, doesn't it?
Tuesday, September 15, 2009
Single instance application for each user
Sometimes there is a need of creating a single instance application. It can be achieved in several ways and below you can find how it may be done using named Mutex. Named mutexes are visible throughout the operating system and can be used for synchronization purposes. Additional requirement is that there has to be single instance application for each user. To achieve this we are going to create a unique mutex name for every user. Please notice that if you use the same name for every user there it will be possible to run only one instance for the whole system. If another instance of the application is running, the main window will be displayed with SetForegroundWindow
method from user32.dll library.
Because an external library will be used add namespace declaration
using System.Runtime.InteropServices
Now the SetForegroundWindow metod declaration
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWindow);
And here is the code that does the job
Friday, August 28, 2009
A few Software Development Podcasts worth checking
HanselMinutes is a weekly audio talk show with noted web developer and technologist Scott Hanselman and hosted by Carl Franklin. Scott discusses utilities and tools, gives practical how-to advice, and discusses ASP.NET or Windows issues and workarounds.
.NET Rocks!
is a weekly talk show for anyone interested in programming on the Microsoft .NET platform. The shows range from introductory information to hardcore geekiness.
Herding Code is a weekly podcast with K. Scott Allen, Kevin Dente, Scott Koon, and Jon Galloway on .NET development topics
Software Engineering Radio is a podcast targeted at the professional software developer. A new episode published every ten days. Episodes are either tutorials on a specific topic, or an interview with a well-known character from the software engineering world.
Thursday, April 23, 2009
Structured debugging process
Debugging should never be done chaotically. Below you can find instructions how to debug in a structured way.
- Duplicate the Bug
The most important, no repro no fix - Describe the Bug
Keep it in database – easier to track changes - Always assume that the Bug is yours
If bug is in your code you can fix it, if not = trouble; eliminate any possibility before looking elsewhere - Divide and conquer
Hypothesis and elimination, look into code, like a binary search. - Think creatively
Version mismatches, operating system differences, problems with program binaries or installations, external factors - Leverage Tools
Helps to investigate e.g. Error detection tools (invalid memory accesses, parameters to system APIs and COM interfaces) - Start Heavy Debugging
Much time on exploring program's operations - Verify that the Bug is fixed
Easy when isolated module, harder in critical code – verify for all data conditions, good and bad & regression. Changes to critical code => inform the team! - Learn and Share
Summarize what you have learned and share with colleagues – helps eliminate the bug faster.
Of course there is no need to follow all the steps. If the bug is found and fixed just go directly to the step no.8
The steps are taken from an excellent book "Debugging Applications for .Net and Microsoft Windows" by John Robbins.
Wednesday, April 1, 2009
Windows Developer .Net 3.5
I have upgraded MCPD Windows Developer .Net 2.0 to .Net 3.5 by passing following exam 70-566: Upgrade: Transition your MCPD Windows Developer Skills to MCPD Windows Developer 3.5
The exam has two parts, the Technology Specialist part, with 20 questions and the second one, the Pro, with 25 questions. From 'upgrade' exam I expected more questions strictly about .NET 3.5 features but actually there were plenty of general Windows Development questions, many similar to those from both TS and Pro .Net 2.0 exams. The main benefit is that in order to get .Net 3.5 certification you have to, instead of passing two exams with about 45 questions each, pass one two parts exam with 45 questions.
I have been thinking about next step and decided not to extend skills with other technologies (e.g. ASP.NET), but rather specialize and improve skills in my current domain, which is .Net Windows Development.
