Tuesday, December 8, 2009

Silverlight Combobox with keyboard input

Recently I had to create some comboboxes in a silverlight app that contained quite a few items. Scrolling through so many items in the list made it difficult to find what you want. I wanted the combo to respond to keyboard input such that I could press a key and have it jump to the first item in the list that started with that letter. I was kind of surprised not to find this as a standard property of the silverlight combo.

The solution I came up with uses the KeyUp event to select the appropriate item in the list. The trick is, you need to handle the KeyUp event for the Combo as well as the ItemsPanel of the combo. Once you start scrolling or interact with the list, you are interacting with the ItemsPanel of the combo, so you need to handle the events there if you want to allow keyboard input multiple times. The XAML looks like this:

  KeyUp="cboSimple_KeyUp" >
      <StackPanel KeyUp="cboSimple_KeyUp"/>
  <ComboBoxItem Content="A" />
  <ComboBoxItem Content="B" />
  <ComboBoxItem Content="C" />
  <ComboBoxItem Content="D" />
  <ComboBoxItem Content="E" />

Now when you handle the event you to select the item in the combo. So instead of working with the sender for the event, you will work with the combo by name. LINQ can be used for finding all the items that start with the letter selected on the keyboard.

private void cboSimple_KeyUp(object sender, KeyEventArgs e)
  SelectItemInCombo(cboSimple, string.Format("{0}", Convert.ToChar(e.PlatformKeyCode)));
private void SelectItemInCombo(ComboBox cBox, string keyLetter)
  IEnumerable<object> itemsWithStartcChar =
  cBox.Items.Where(c => ((ComboBoxItem)c).Content.ToString().StartsWith(keyLetter));

  if (itemsWithStartcChar.Count() > 0)
    cBox.SelectedItem = itemsWithStartcChar.First();

Notice that first I do a select so I can get a count of the items that start with the letter that was pressed. Without this you get an exception on the First function if the list is empty.

This is also a very simple list. If your combo contains more than simple strings you will need to find the string within the ComboBoxItem that you are sorting by.

Tuesday, December 1, 2009

ArcGIS Server and Virtualization

I've gotten several questions lately regarding virtualization and capacity planning with regard to ArcGIS Server. Below are my answers to some of these questions.

Q: What is ESRI’s official supportability of virtualization of ArcGIS Server?
A: ArcGIS Server is supported in a virtualized system. See: http://www.esri.com/software/arcgis/arcgisserver/common-questions.html. Go down to Standards | Interoperability | IT | Security. The third question down deals with virtualization. Basically, virtual systems are treated the same as physical systems.

Q: What versions of Microsoft Windows are supportable deployments? 32 or 64bit support?
A: The same as support for physical systems. http://wikis.esri.com/wiki/display/ag93bsr/Web+ADF+for+the+Microsoft+.NET+Framework.

Q: What kind of resources (RAM / CPU / Disk) do I need to allocate to ArcGIS Server?
A: It all depends on the services that you are using, the applications that consume those services (desktop, web/server, web/browser), and the number of users that will be interacting with the system. The book Building a GIS discusses how to use the Capacity Planning Tool that you can use to estimate capacity. You can find info on that here: http://esripress.esri.com/display/index.cfm?fuseaction=display&websiteID=141&moduleID=27. To get a more exact picture of performance and scalability you should test an application in a configuration to see how many users it will support. There is information on how to do this here: http://resources.esri.com/arcgisserver/adf/dotnet/index.cfm?fa=mediaGalleryDetails&mediaID=6D73B2DB-1422-2418-344143680A5154BA

Q: Are there any special considerations for virtual systems?

A: The one performance issue that usually plagues VM’s is disk IO. ArcGIS Server tends to do a lot of disk IO. Geoprocessing services do the most disk IO but even a simple dynamic map request involves a write to disk. So improving the performance and scalability of your disk IO will have a significant impact on system performance. For this reason, I prefer to put my ArcGIS Server, server directories on a SAN. I’m not talking about a virtual disk on a SAN, I mean the SAN is attached directly to the VM. This way, you get the fast disk IO from your SAN without the dealing with the disk IO of the virtual machine. This also makes it easier to allocate space for the machine and it makes it easy to share the same server directories between VMs.