ObjectSharp Blogs

You are currently viewing

Dan's Blog

Random Ramblings on Software


New MS (Dundas) Chart Controls

The client I’m currently working with needed a charting control that would allow us to create something similar to a Gantt chart.  Unfortunately the control suite we were using wasn’t quite up to the task.  Fortunately a fellow Objectsharpee (and former Dundas employee) told me that Microsoft was going to be putting the Dundas controls they had purchased into the framework, even better was that it had been released just the week previous.  I’ve never used Dundas controls previous to this, so I’m not 100% clear what the feature set differences are, or if there are any.  The MS Chart control did everything we needed and it was dead simple to do. 

All you need to do is download and install the small installer and have .Net 3.5 SP1 already installed.

Chart Docs
Chart Controls
Chart Forums – Note: Not a lot of information in the forums as of this posting, but the Dundas support forums are filled with great, applicable, information.
Chart Samples

Also, Alex Gorev has started a blog all about the new data visualization in the .Net Framework.

TFS Powershell PSSnapin

The October Team Foundation Power Tools drop includes three new features:

  • TFS Power Shell Extensions
  • TFS Windows Shell Extensions
  • Team Members Tool

The only one I care about is the Powershell extensions. Keith Hill has a great post with some examples.  I already had a script that made some .NET assembly calls to get me the latest good build off of TFS.  I converted that script to use the new snapin, and posted it below.  I’m sure some of this is not best practices, feel free to let me know if you have a cleaner implementation.

(Get-TfsServer -Name myTfsServer).GetService(Microsoft.TeamFoundation.Build.Client
.IBuildServer]).QueryBuilds("myProjectName", "myBuildName") | 
where { $_.BuildDefinition.LastGoodBuildUri -eq $_.Uri } | select DropLocation
 
Two lines in my profile.ps1:

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")

SQL Server – Dropped my default database

Today I learned an important lesson about Sql Server 2005, don’t change your default database unless you absolutely have to.  I set mine to DatabaseX and then I promptly dropped DatabaseX.  When I tried to log in I got a nice error message

            Cannot Open User Default Database, Login Failed

I didn’t setup the VM that I was using, so I didn’t know the SA password.  I basically had no way to get back into the server.  So if you ever find yourself in this predicament, execute the following from the command line:

C:\> sqlcmd -E -d master 
1> ALTER LOGIN [YOUR USER NAME HERE] WITH DEFAULT_DATABASE=master 
2> GO
 

That will reset your default database back to master and you can login again. 

Infragistics Tips and Tricks - Part 1 of N

The current project I'm on is using Infragistics controls exclusively.  Infragistics can do some wonderful things, but damn, sometimes it does it horribly.  So here are a couple little hints and tips that might save someone a couple of frustrating moments of despair.  Find something in my list that I did wrong?  Found something I could have done better / cleaner / quicker? Please let me know.

Binding to a List<>

If you are binding your Grid to a BindingSource that in turn is bound to a Generic List, the key of your band needs to be the name of the class your list contains.

List<Message> myList = new List<Message>();
myBindingSource.DataSource = myList;
myUltraGrid.DataSource = myBindingSource;
 

Band key in your schema is 'Message'.  If your class contains another collection there will be bands for those collections which will add 'plus' signs beside all your rows even if that collection is empty.  Create another band in your schema with a key equal to your child collection and then set Hidden = true.  (See below about the Hidden property...)

The other note for binding to a generic list is that if it isn't an ObservableCollection or BindingList  (or anything that doesn't implement IBindingList or IBindingListVIew) then you are not going to get an update when you add or remove and item from the list.  If you know these things are happening you can call myBindingsource.ResetBindings(false) when they happen to update your grid with the new bindings.

Good article on what interfaces have what binding functionality.

Can't Find the .Visible property?

This one baffles me, and I'd love to know why some infragistics controls do not have a .Visible property, instead they have a .Hidden.  Watch out for that.  Apparently this is some sort of VB throw back blah blah blah.

CreationFilter's To Change GroupBy Headers

CreationFilters are a really cool concept that let you change the layout of a lot of Infragistic controls and add new functionality.  I used this to add some status lights to the GroupByRows of my grid. 

Create a Creation Filter class that implements IUIElementCreationFilter.  My AfterCreateChildElements(UIElement parent) does nothing but here is my  BeforeCreateChildElements method.  This will create 3 icons and some text in the group by row.  I create my own text element but if you want to grab the existing text element: 

DependentTextUIElement dependentTextUIElement = parent.GetDescendant(typeof(DependentTextUIElement)) as DependentTextUIElement;

 
public bool BeforeCreateChildElements(UIElement parent) { bool value = false; if (parent is GroupByRowDescriptionUIElement) { int X = 17; int Y = parent.Rect.Y + 1; int Width = 516; int Height = 17; UltraGridGroupByRow groupByRow = (UltraGridGroupByRow)parent.GetAncestor(typeof(GroupByRowUIElement)).GetContext(typeof(UltraGridGroupByRow)); DeviceStatusInfo deviceInfo = groupByRow.Tag as DeviceStatusInfo; if (deviceInfo == null) { deviceInfo = new DeviceStatusInfo("", DeviceState.Offline, DeviceOnlineState.NotOnline, "", FoundationHelper.GetImage(typeof(string))); groupByRow.Tag = deviceInfo; } string text = deviceInfo.DeviceName; if (!string.IsNullOrEmpty(deviceInfo.DeviceCurrentOperationsText)) text += " - " + deviceInfo.DeviceCurrentOperationsText; TextUIElement textElement; ImageUIElement firstIndicator; ImageUIElement secondIndicator; ImageUIElement deviceIcon; parent.ChildElements.Clear(); deviceIcon = new ImageUIElement(parent, deviceInfo.DeviceImage); textElement = new TextUIElement(parent, text); firstIndicator = new ImageUIElement(parent, deviceInfo.DeviceStatusImage); secondIndicator = new ImageUIElement(parent, deviceInfo.DeviceOnlineImage); deviceIcon.Rect = new Rectangle(X, Y - 1, deviceInfo.DeviceImage.Width, deviceInfo.DeviceImage.Height); firstIndicator.Rect = new Rectangle(deviceIcon.Rect.X + deviceIcon.Rect.Width + 2, Y, deviceInfo.DeviceStatusImage.Width, deviceInfo.DeviceStatusImage.Height); secondIndicator.Rect = new Rectangle(firstIndicator.Rect.X + firstIndicator.Rect.Width + 2, Y, deviceInfo.DeviceOnlineImage.Width, deviceInfo.DeviceOnlineImage.Height); textElement.Rect = new Rectangle(secondIndicator.Rect.X + secondIndicator.Rect.Width + 2, Y, Width, Height); parent.ChildElements.Add(deviceIcon); parent.ChildElements.Add(textElement); parent.ChildElements.Add(firstIndicator); if (deviceInfo.DeviceStatus == DeviceState.Online) { parent.ChildElements.Add(secondIndicator); } firstIndicator.ToolTipItem = deviceInfo.GetDeviceStatusToolTip(); secondIndicator.ToolTipItem = deviceInfo.GetDeviceOnlineStatusToolTip(); value = true; } return value; }

 

Set the creation filter:

this.ultraGrid.CreationFilter = new GroupRowIndicatorsCreationFilter();

 

TabClosing Event Order

This tip is kind of specific, but thought I'd post it here anyway.  If you are using the Mdi Tabbed Workspace (and I assume the Mdi Tab Control) then a little gotcha is that when the user closes a form, either by clicking the 'X' or by you firing the form.Close() method the Mdi_Tab_Closing method is fired BEFORE the Form_Closing event.  If you think about it, it makes sense, however it is a pain in the butt if you want to handle someone closing a tab, and someone closing the whole app differently.  In our app we have functionality similar to visual studio, if you caused it to fire?!? Short answer is you can't.  So here is a little method that will fire before either Mdi_Tab_Closing and Form_Closing.

protected override void DefWndProc(ref System.Windows.Forms.Message m) { if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE) { applicationClosing = true; } base.DefWndProc(ref m); }

The applicationClosing bool allows me to check if the user hit the X button when I'm in my Mdi_Tab_Closing.  If you have an 'Exit' option from a file menu then in that code you will want to set applicationClosing = true in there as well.

Reset permissions for existing folders on a new Vista Install

I just did a fresh install of Vista Ultimate on my home desktop PC.  The install all went fairly smooth except for 2 things:

1) IIS was not installed, and I missed the little checkbox to install ASP support.

2) I had a lot of problems accessing my existing Documents And Settings folders and could not access (only read access) my other partitions.  Even as Administrator I could not seem to set permissions on these folders and drives so I could write to them.  Thankfully Tim Sneath came to the rescue with a posting about 'Deleting the Undeletable' in which he explains how to reset the permissions on files to give yourself access to them. 

it's not unusual to find some folders that can't be accessed, even by an administrator, because their ACLs were set for accounts with SIDs that applied to an old partition

Tim provides a quick batch command that will allow you to reset the proper permissions for the Administrators group. 

takeown /f %1 /r /d y
icacls %1 /grant administrators:F /t

Just pass it a directory to start at (it is recursive).

Big thanks to Tim.

IIS 7, ASP, and Vista

When I did a fresh install of Vista on my home desktop machine it did not install IIS by default which is to be expected.  But the real problems started when I could not find out how to install ASP support.  Anytime I would try and load an aspx file it would say it didn't know how to handle .aspx as a static file.  Very frustrating.

Barry Gervin provided a link that shows the step by step instructions on how to properly install IIS 7 on vista, including the slightly hidden ASP.NET support.  Is anyone really installing IIS7 and not installing ASP.NET support?

Vista DreamScene

While I was out at the Vista Ice House in Toronto last week they were demo'ing 'DreamScene', which is movies as desktop wallpapers.  The basic idea is that you take a small subtle looping video and apply it as your background.  Obviously this is eye candy only, but it is pretty impressive eye candy when done properly.  There is a video here that shows a couple of examples.

 

DreamScene is one of those annoying Ultimate Extras which must really drive anyone without Ultimate absolutely nuts.  Thankfully I have Ultimate, and managed to get my hands on a beta (the official release is apparently some vague time in the future), only problem is that the beta does not seem to support dual-monitors, something that hopefully will be addressed in time for the final release.  WinCustomize has started a page where you can get some DreamScene movies, apparently both in-house created, and user submitted.  It doesn't appear that the page is ready for primetime, but you can check it out none the less.

How Smart Are You?

How smart are you? http://crux.baker.edu/cdavis09/roses.html A very challenging little game, some people can do it in 5 minutes, apparently others take a year... took me about 20 minutes.

Is Google Taking Over My Computer?

It has been rumoured for months, but finally today it was announced that google had entered the Desktop Search business with Google Desktop. Anyone that has ever used Microsoft Windows Search knows it is a big pain, and it is slow and the indexing is pretty bad. Needless to say I've been looking forward to the newest addition to the Google family, and I downloaded it as soon as I heard.
Right off the bat I had a bit of a problem with the install not working because I had Microsoft Firewall Client Version 3 installed, instead of version 4. Even though this is disabled it would not let me continue the install.
Once I was past that problem, it was fine and I started playing with it. It is amazing. Amazing.

It does a one time indexing of your system when there is some idle time, and after that it just keeps track of new and changed files as you work. The searches are amazingly quick and search text files, Word docs, Excel spreadsheets, Outlook mail, browser cache, and all your file names. To do a search for 'jpg' took 0.04seconds and it returned every picture on my computer and every email in which I ever sent, or mentioned a jpg file in. Amazing. Why have you not downloaded it yet?

There is one beef that I have. I've considered this problem and I've decided it might be a premeditated decision, but I hope it is not. Google Desktop does not look at .cs files, as a C# developer this is very frustrating. For the VB.NET guys it doesn't do .vb files either... Google Desktop will treat .java .c .h .cpp files as text files AND allow for a "filetype:c" or "filetype:java" search. But nothing on .cs files. Google what is the deal with this? I also haven't been able to find anyway to change how certain file types are handled.

Despite this problem I still love it, it integrates itself with http://www.google.com so that any search on the site will also tell you if you have matches on your own machine, this is done by intercepting google requests and then merging your results with the html when your response comes back. None of your personal info is sent to Google, rest easy. The only thing that is sent is how many searches are run, and how long they took, and even this you can opt out of.

Google is the greatest thing in the world, Dave will tell you how much he loves Google if you ask him.
As well as taking over the internet, it is also taking over my machine, I now have my Gmail, and the Gmail Notifier, Picasa for all my pictures, Google Desktop, and Google Deskbar. I don't mind this take over a bit.

Clipboard Copying Problem

I recently ran into a problem with the clipboard that is apparently a fairly common problem without a common answer.
The problem occurs while making a temporary copy of the clipboard.

I needed to put something into the clipboard, but I didn't want the user to lose what they already had in there, the easy way that I assumed would work looked like this:

IDataObject oldClipboard = Clipboard.GetDataObject();

//random clipboard manipulation here

Clipboard.SetDataObject(oldClipboard,true);


The true ensures that the data is held in the clipboard even after the program closes.  This solution meets with a "The requested clipboard operation failed" message if there is ever anything actually in the clipboard originally.

 

So here is the proper way of making a copy of the clipboard data, assuming of course that you have no idea what is in the clipboard before you arrived.  An important note if you aren't aware of how the clipboard is structured.  When you copy text out a richtextbox it is actually stored in several different ways:
Rich Text Format
Rich Text Format Without Objects
RTF As Text
System.String
UnicodeText
Text

 

The solution:

IDataObject oldClipboard = Clipboard.GetDataObject();

DataObject newClipboard = new DataObject();

string[] s;

s = oldClipboard.GetFormats(); //gets all the possible formats for that data

foreach(string ns in s)

{

newClipboard.SetData(ns,oldClipboard.GetData(ns)); //re-associate the old data with the proper types

}

//this is where your clipboard manipulation goes.

Clipboard.SetDataObject(newClipboard,true); //true makes sure the data persists

 

 

More Posts Next page »