Blogging Efforts

I have decided to start contributing to my companies Blog on Microsoft Technologies. They will require me too post more frequently.  So if my past blogging efforts have been beneficial to you keep an eye on http://blogs.perficient.com/microsoft/ to see what I have too say. I will likely post references to the post here as well.

C# Pluralize and/or Singularize

Recently I had a need to Pluralize some data elements to be displayed on screen. I didn’t want to have to write my own logic to figure do I need an”s” or  and “es” as so on. So come to find out in .NET 4 there is a class that aids in this process “System.Data.Entity.Design.PluralizationServices.PluralizationService“. Also since I’m using VS2010 and .NET 4 I get the capability to add Extension Methods to existing types. I wanted to be able to easily call the Pluralize method from any Sting.

Here is the code for the Pluralize and Singularize Extension methods for the String type.

using System;
using System.Data.Entity.Design.PluralizationServices;
using System.Globalization;

public static class ExtensionMethods {
    public static String Pluralize(this String s) {
        return PluralizationService.CreateService(CultureInfo.CurrentCulture).Pluralize(s);
    }
    public static String Singularize(this String s) {
        return PluralizationService.CreateService(CultureInfo.CurrentCulture).Singularize(s);
    }
}

Now I can easily call the method on any String.

str.Pluralize();
str.Singularize();

The “DeleteCurrentDeployment” task failed unexpectedly and IE8 tab hang

Thank you Roel van Lisdonk (http://www.roelvanlisdonk.nl/?p=653). I have been having problems with my Visual Studio  2010 when building and running Windows Azure projects. I would get an error which I posted in the MSDN forums and also on StackOverflow and never received a solution to the problem. So I re-imaged my machine and re-installed everything.

Same issue occurred again.

Error 1  The "DeleteCurrentDeployment" task failed unexpectedly.
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.OLE.Interop.IServiceProvider'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6D5140C1-7436-11CE-8034-00AA006009FA}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, Boolean& pfNeedsRelease)
at Microsoft.VisualStudio.OLE.Interop.IServiceProvider.QueryService(Guid& guidService, Guid& riid, IntPtr& ppvObject)
at Microsoft.VisualStudio.Shell.ServiceProvider.GetService(Guid guid, Type serviceType)
at Microsoft.VisualStudio.Shell.ServiceProvider.GetService(Type serviceType)
at Microsoft.Cct.IServiceProviderExtensions.GetService[InterfaceType,ServiceType](IServiceProvider serviceProvider)
at Microsoft.Cct.CctBuildDeploymentTaskHost.DeleteCurrentDeployment()
at Microsoft.CloudExtensions.MSBuildTasks.DeleteCurrentDeployment.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)

So I removed the "DeleteCurrentDeployment" task from the targets file and then i was able to build. When i went to run the project in debug i was prompted with a smaller version of the error.

Windows Azure Tools: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.OLE.Interop.IServiceProvider'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6D5140C1-7436-11CE-8034-00AA006009FA}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

After I searched for that error I again came across a blog post from Marc Valk, which then pointed me to another blog post from Roel van Lisdonk. Come to find out that the IE8 hang issue which i was also having was created by SourceGear Vault 3.1.9 which i happened to be running for my VS2005 projects. So i followed the instructions given by Roel van Lisdonk.

1. Install the SourceGear Vault client v3.1.9 in "C:\Program Files (x86)\SourceGear\Vault Client"
2. Backup all files and folders from the folder "C:\Program Files (x86)\SourceGear\Vault Client" to a backup folder "C:\Program Files (x86)\SourceGear\Vault Client Backup"
3. Uninstall the SourceGear Vault client v3.1.9
4. Restore all files and folders from the "C:\Program Files (x86)\SourceGear\Vault Client Backup" to the "C:\Program Files (x86)\SourceGear\Vault Client"
5. Create a FixSourceControlProviderOnWin7x64.reg file and paste the following values:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SourceCodeControlProvider]
"ProviderRegKey"="Software\\SourceGear\\Vault Client"
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SourceCodeControlProvider\InstalledSCCProviders]
"SourceGear Vault Client"="Software\\SourceGear\\Vault Client"
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SourceGear]
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SourceGear\Vault Client]
"SCCServerName"="SourceGear Vault Client"
"SCCServerPath"="C:\\Program Files (x86)\\SourceGear\\Vault Client\\VaultIDE.dll"

6. Run the FixSourceControlProviderOnWin7x64.reg file.

Sure enough this solved both of my problems. Just wish I would have found this out before I did the re-image :). Talk about killing two birds with one stone.

SpeakerRate.com

Whether I get feedback or not I’m going to start using SpeakerRate.com to post all the events I will be speaking at. You can find most of my past events here (http://SpeakerRate.com/rduclos). I will be posting all my upcoming events as they are finalized.  If you have been to any my talks please give feedback.

This site will make it easier for me to track my events.

SSRS 2008 Generate Calendar(s) based on a date range

I’m finally able to start blogging again. In addition to my Simple-Talk article I figured my first post would be an updated calendar report based on employee birthdays in the AdeventureWorks Database. Using recursive common-table-expressions I was able to generate the records needed to build a calendar for a given date range. Here is a link to the article (http://www.simple-talk.com/sql/reporting-services/ten-common-sql-server-reporting-services-challenges-and-solutions/#hr) to give you a basic idea of what the query is doing to generate the data as well as an example of how to build the report .

Here is the updated query:

--DECLARE @StartDate DATETIME = '03/26/2009', @EndDate DATETIME = '03/26/2010'
SELECT @StartDate = DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,@StartDate),0)) --FirstDayOfMonth
SELECT @EndDate = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@EndDate)+1,0)) --LastDayOfMonth

; WITH Months AS (
	SELECT
	 [Month] = DATEPART(MONTH,DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,@StartDate),0))),
	 [Year] = DATEPART(YEAR,DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,@StartDate),0))),
	 FirstDayOfMonth = DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,@StartDate),0)),
	 LastDayOfMonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@StartDate)+1,0)),
	 FirstDayOfCalendar = DATEADD(DAY,-DATEPART(WEEKDAY,DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,@StartDate),0)))+1,DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,@StartDate),0))),
	 LastDayOfCalendar = DATEADD(DAY,6-DATEPART(WEEKDAY,DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@StartDate)+1,0))),DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@StartDate)+1,0)))
	UNION ALL SELECT
	 [Month] = DATEPART(MONTH,DATEADD(MONTH,1,FirstDayOfMonth)),
	 [Year] = DATEPART(YEAR,DATEADD(MONTH,1,FirstDayOfMonth)),
	 FirstDayOfMonth = DATEADD(MONTH,1,FirstDayOfMonth),
	 LastDayOfMonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,DATEADD(MONTH,1,FirstDayOfMonth))+1,0)),
	 FirstDayOfCalendar = DATEADD(DAY,-DATEPART(WEEKDAY,DATEADD(MONTH,1,FirstDayOfMonth))+1,DATEADD(MONTH,1,FirstDayOfMonth)),
	 LastDayOfCalendar = DATEADD(DAY,6-DATEPART(WEEKDAY,DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,DATEADD(MONTH,1,FirstDayOfMonth))+1,0))),DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,DATEADD(MONTH,1,FirstDayOfMonth))+1,0)))
	FROM
	 Months
	WHERE
	 LastDayOfMonth < @EndDate
), Dates AS (
	SELECT
	 [Month],
	 [Year],
	 [Date] = FirstDayOfCalendar,
	 FilterDate = LastDayOfCalendar
	FROM
	 Months
	UNION ALL SELECT
	 [Month],
	 [Year],
	 [Date] = DATEADD(DAY,1,[Date]),
	 FilterDate
	FROM
	 Dates
	WHERE
	 [Date] < FilterDate
), EmployeeBirthDay AS (
	SELECT
	 e.BirthDate,
	 [Day] = DATEPART(DAY, e.BirthDate),
	 [Month] = DATEPART(MONTH, e.BirthDate),
	 [Year] = DATEPART(YEAR, e.BirthDate),
	 FullName = e.FirstName + ' ' + e.LastName
	FROM
	 DimEmployee e
) SELECT
 DisplayOnCalendar = DENSE_RANK() OVER (ORDER BY d.Year, d.Month),
 d.Month,
 [Day] = DATEPART(DAY,d.[Date]),
 d.Year,
 [WeekDay] = DATEPART(WEEKDAY, d.[Date]),
 [Order] = DENSE_RANK() OVER (PARTITION BY d.Year, d.Month ORDER BY d.Date), 
 d.Date,
 ebd.FullName
FROM
 Dates d
 LEFT JOIN EmployeeBirthDay ebd ON ebd.Month = DATEPART(MONTH,d.[Date]) AND ebd.Day = DATEPART(DAY,d.[Date])

OPTION (MAXRECURSION 1000)

The earlier version of the report has been updated to  SSRS 2008. There is only a few changes that need to be made to get multiple calendars to display. Add a new tablix which is grouped by "DisplayOnCalendar" with page break after each group. Move the Month information from the report header into the new tablix as the group header. Drag the previous tablix into the details section on the new tablix. You can now remove the "Note" column from the previous tablix and update the value on the "Time" column to look at "FullName." I made some additional format changes but won't go in to details on those. Below is an example of what my report looks like before I preview it.

Once I preview the report I will show you the report which includes all the employees from AdventureWorks with their birthday in February 2010. The Date range I used is 03/26/2009 through 03/26/2010 so you will see there is 13 pages of the report to reflect the 13 months in the date range.

Here is a link to download the RDL file for the report above (http://www.box.net/shared/o7i6pc2znt) the zip file also contains the original RDL for the current month calendar report. The current month report is "Calendar.rdl" the updated version is "RangeCalendar.rdl" these reports will work with SSRS 2008 and the Adventureworks database.

10 Common SSRS Challenges

Check out my Article on Simple-Talk.com: http://www.simple-talk.com/sql/reporting-services/ten-common-sql-server-reporting-services-challenges-and-solutions/

Create application Shortcut in .Net the easy way

Have you ever needed to create an application shortcut on the fly in your .Net application? Well I have and this is what I did. The easiest way to create a shortcut is to create a url file which contains a reference to your file instead of a web address. A url file is basically like an ini file. To create a real desktop shortcut requires the use of a COM object, which for my case was not needed.

A url file is a plain text file with the “url” file extension. Below is an Example of the required content of a url file:
[InternetShortcut]
URL=http://rduclos.wordpress.com

There are other options that can be added to the url file as well, but all you need to specify is the URL. Rather than using a url to a internet location you can create one for a file on your system by setting URL to file:///c:/Temp/ReferenceFile.txt. Example of a url file content with additional options to specify the icon:
[InternetShortcut]
URL = file:///c:/Temp/ReferenceFile.txt
IconIndex = 0
IconFile = C:\Temp\application.ico

Here is an example of how to create the url file in C# using .Net 2.0:
using System;
using System.IO;
using System.Text;

public static class Program {
  public static void Main() {
    CreateDesktopShortcut();
  }

  private static void CreateDesktopShortcut() {
    String appName = "Application.exe";
    String appDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
    String shortcutName = "Application";
    String shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
    StringBuilder sb = new StringBuilder();

    sb.AppendLine("[InternetShortcut]");
    sb.AppendLine(String.Format(@"URL=file:///{0}/{1}", appDirectory, appName).Replace(@"\", @"/"));

    File.WriteAllText(String.Format(@"{0}\{1}.url", shortcutPath, shortcutName), sb.ToString());
  }
}

Follow

Get every new post delivered to your Inbox.