Jaymz87
Forever in beta

Tab Action Bar with AppCompat shows both Fragments on ICS August 14, 2013

I’m writing an Android application using the Action Bar which needs to run on devices using API version 7 and up. It’s a pretty simple application and I want it to have Tab navigation. Getting this set up and working should be a very simple task. However, it’s taken me 2 evenings to get it to work.

That’s not quite true. I got it working following the instructions over on the Android Action Bar API Guide page within a few minutes. When it was installed on an emulator running Froyo, that is.

However, when it ran on my actual phone, running ICS, switching between tabs resulted in the contents of all visited tabs being displayed over the top of each other. The tabs which should not have been active were still visible, but could not be interacted with.

I spent a while playing with the Fragment Transactions, as adding a manual commit to the onTabUnselected callback resulted in the fragment switch working correctly… the first time. After a 2nd attempt, an exception was thrown due to commit being called more than once. I was on the right tracks though…

It turns out there is a bug with the v7 support library: Issue 58602: Support AppCompat – onTabUnselected does not call tx.commit() on ICS. The root cause being a missing fragment transaction commit in the onTabUnselected callback.

The bug has been closed, as it’s been fixed and will be included in a future release. Until that point however, the workaround is to add the following code after the last line inside the onTabUnselected callback:

[code lang=”java”]
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
try {
Method commit = tab.getClass().getDeclaredMethod(“commitActiveTransaction”);
commit.setAccessible(true);
commit.invoke(tab);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
[/code]

Hopefully this will save you a few hours of banging your head against your keyboard!

Comments (0)
Categories: Android

TFS 2012 Update 2 Upgrade Fails – “Port in use” May 7, 2013

I’ve spent this weekend trying to upgrade to TFS 2012 Update 2 successfully, and it’s not been as smooth as it should have been.

The initial installation appears to complete fine, there are no logs or warnings that come up during the actual installation of the update. The problems all seem to come during the post-install configuration during the Upgrade Wizard.

There seems to be a few issues from a quick search of the Internets, but my particular issue was to do with configuring IIS. The message that popped up half way through the upgrade configuration, and put a stop to the rest of the configuration, was “Port in use”. This was flagged up as being part of the Creating Web Sites step, so I took a look in IIS.

To make accessing TFS easier for other departments where I work, I added a binding on the TFS site port 80 with a host header, allowing people to access the site just by going to http://tfs/.

It was this binding that threw the configuration wizard out – it attempted to add a binding to port 80, without checking the host header; tried to bind to it and failed as there was already a site running on port 80.

So to fix, I simply removed the additional bindings I put in place, and then attempted the installation again. Once the install completed, adding the bindings back in brought all services back online.

My case was made a lot easier as I run TFS in a virtual environment, and I took a snapshot of the machine before making any changes. I was able to perform the upgrade without worrying about how to recover in the event of a failure.

If you’re not running in a virtual machine, I cannot stress enough how important it is to take a backup of ALL of the TFS SQL databases before attempting this update. If it errors like this part way through the upgrade, and you don’t have a database backup to recover to, it’s going to be a long night trying to get it all working again.

Comments (0)
Tags: ,
Categories: Development

Xbox Live Gamer API October 23, 2012

I’ve been wanting to put together an internal site for people at work to use to monitor and track, and eventually challenge, each other on their Xbox Live achievements. Each time I’ve looked at how this could be possible, it’s always come down to using screen-scraping techniques to be able to get even the most basic information out of the Xbox Live systems.

Enter: Unofficial XboxAPI. A simple JSON/XML/PHP web service which allows you to query the data via simple GET requests.

Obviously, this is still using screen-scraping techniques behind the scenes, but it means I don’t have to worry about all that. :)

So I threw together a quick page (here*) using this Xbox Live API that allows me to view the basic information of a player at a time to experiment with it. From what I can see, it’s exactly what I’ve been looking for. Easy to use, complete information, and fairly responsive. It has a limit of 150 requests per hour per IP, which should be more than we’ll ever need, especially as I plan to cache the results and store them in a database for the most part.

Provided the project stays alive and working, my internal Xbox competitions site should be up soon. But for now, I urge anyone who has considered doing something like this to go and donate now!

* I know this doesn’t currently work in IE, not sure about Firefox. Works fine in Chrome though.

Comments (0)
Categories: Development

Junior interview questions September 19, 2012

Writing interview questions for a junior is an interesting task. No matter what job you’re recruiting for, there’s a lot to think about. The level of candidate you’re after needs to be able to answer the question, without finding it too easy. If it’s too easy, you’ll be overwhelmed with correct responses, and the question won’t have done anything to help you identify the potential stars, from the average 9-to-5ers.

If the question is being completed by candidates before the interview, or in some way where they are able to access the Internet in their own time, then it has to be completely un-Google-able. If it’s being completed under supervision, then it needs to be non-trivial enough to not be an only-easy-if-you-know-the-answer type of question.

Obviously, there’s a base set of questions (such as these for Senior Developers, or any of the generic questions books like this), that are asked over and over again. These types of questions are only really good to weed out the candidates who are after any job they can get hold of. If the candidate is specifically after the kind of job you’re offering, they should be able to recite the answers to 95% of these questions without batting an eyelid.

There’s an all too easy mistake to make when you’re recruiting for a role in the same career as you’re in, but at a lower level: overestimating the required knowledge of a colleague at that level. Just because you think something is easy, doesn’t mean that a junior version of you did. And just because they don’t know something now, doesn’t mean they can’t learn it quick enough to still bring a benefit to the role.

Comments (0)
Categories: Uncategorized

Microsoft reveals InPrivate’s real purpose July 16, 2012

If anyone’s seen the new IE8 ads run by Microsoft, you’ll have seen F.O.M.S, S.H.Y.N.E.S.S and G.R.I.P.E.S.

You may also have seen that there was a fourth, titled O.M.G.I.G.P. This got pulled by Microsoft, and probably rightly so. I’m not sure how this could have gotten out of Microsoft’s marketing department in the first place, but then I guess recessions make companies desperate.

At least it clears up what InPrivate browsing is actually meant for.

Watch it here.

Enjoi!

Comments (0)
Categories: Uncategorized

Installing Bing Desktop on Windows Server 2008 R2 July 2, 2012

…or any other Windows OS that it decides it won’t install on.

If there’s one thing I like about Bing, it’s the different backgrounds it has each day. In all honesty, it’s probably the only reason I use it instead of Google for a few searches a day (when I remember). Bing Desktop is a nice little app for Windows which allows those backgrounds to be set as your desktop wallpaper each day, and also serves as a nice easy jump point for your searches when you’re not already in a browser.

The main installer download for Bing Desktop is an exe container of a zip file, which holds only 2 files – an msi and another exe. This installer essentially extracts the msi and runs it.

The msi file is a standard Windows Installer file, which contains a fairly standard OS Version check. In this instance, the condition is:

[code](((VersionNT 601) AND (VersionNT 700)) OR (MsiNTProductType 1))[/code]

The culprit for not being able to install Bing Desktop on Windows Server 2008, Windows Server 2008 R2, and presumably any other Server variant of Windows is (MsiNTProductType 1).

So, you have 3 options:

  1. Download Bing Desktop, extract the files from the exe using 7-Zip or WinRar or similar, edit the MSI file using Orca to modify the OSVersionCheck to remove the offending string above, then run the MSI to install.
  2. Same as above, but remove the OSVersionCheck action entirely.
  3. Download and run the modified MSI file here.
    (This just saves you having to do one of the above steps manually).

Why Microsoft decided there was a need to stop installation of Bing Desktop on Server variants of Windows, I’ve no idea – but now you can.

And in case you’re wondering, this trick works on an awful lot of installers – just be sure there’s no valid reason for the OS version check before you do this.

BingDesk.msi (1.65 MB)

Comments (2)
Categories: Uncategorized

C# Enums – Converting from int to enum June 12, 2012

In most cases, the use of enums in C# is simple: declare an enum, give it some values, use them. One instance which seems to require more work than it should though, is passing an int value as a parameter to a method which requires an enum. This is what I would want to be able to do:

[code lang=”c-sharp”]
enum Days {
Mon, Tues, Weds, Thurs, Fri, Sat, Sun
};
static void Main(string[] args) {
DisplayDay(1); //Attempt to display “Tues”
}
static void DisplayDay(Days day) {
Console.WriteLine(day.ToString());
}
[/code]

But this results in a compiler error of: Argument type ‘int’ is not assignable to parameter type ‘Application.Program.Days’. I was fully expecting to see something available along the lines of:

[code lang=”c-sharp”]DisplayDay(Enum.Parse(1));[/code]

But alas, no. There doesn’t appear to be any generic methods for enums. So it falls back to some clunky conversions to get what I want. The code for the above example is:

[code lang=”c-sharp”]DisplayDay((Days) Enum.ToObject(typeof(Days), 1));[/code]

So a call to typeof, to allow us to grab an object with the relevant info to be castable to the enum we want. Ouch. Unless someone can call me an idiot and show me a simpler method of getting an enum from an int passed into a method, this really sucks!

Comments (0)
Categories: Uncategorized

PowerShell 32/64bit Execution Policies May 23, 2012

When it comes to bit-ness of an application, there’s generally only 2 things you need to worry about:

Am I running the right version for the OS?
Are all the components compatible with the same version?

I don’t think I’ve come across any instances of configuration settings being applied differently to different versions of the same application. But PowerShell is different.

When managing environment settings such as Execution Policies in PowerShell, the settings actually need to be changed for the right version, and the right version depends on the application calling the runtime. Shown below are the 2 different versions of the PowerShell shell which comes with Windows, after running Get-ExecutionPolicy at the same time:

Annoyingly, if these do not match up, and you run an application built for 32 bit rather than 64 bit without realising it, you will get a CmdletInvocationException:

Hope this helps someone.

Comments (0)
Categories: Uncategorized

vSphere Client White Screen Fix

There is a known issue when running vSphere Client 4.1 and accessing the console of a VM running on an ESX/ESXi 3.x host: VMWare KB: vSphere Client displays a white screen when accessing the virtual machine console

Symptoms You may observe these after installing vSphere Client 4.1: You see a blank white screen when opening the virtual machine console for a virtual machine running on an ESX/ESXi 3.x host No errors are reported on the vSphere client Virtual machine consoles to ESX/ESXi 4.0 or 4.1 virtual machines open without any issues

The resolutions to this are just a little bit tedious, and after putting it off for a couple of months, I thought I’d see if I could find another solution.

And I did.

In the VMWare forums, there is a comment which mentions that running bcdedit to disable DEP (Data Execution Prevention) resolved the issue.

DEP is a security feature switched on by default in most modern OS’s, and I’m not comfortable switching it off entirely, so I tried to just exclude the VpxClient.exe. The 4.1 vSphere client was compiled with the NXCOMPAT flag enabled, which forces DEP to be enabled, and stops you from adding the application to the exclusions list. I’ve not been able to find the exact reason, but whatever it is, it’s DEP that causes the white screen to display.

The NXCOMPAT flag can be removed from an application using the editbin utility, which comes with most versions of Visual Studio (including the Express editions).

editbin.exe /NXCOMPAT:NO [FileName]

Running the command above will allow you to add the application to the exclusions list.

If you do not have editbin available, I have wrapped the required files up in a zip file, and added a PowerShell PS1 script to perform all the required actions.

Download it here.

Just extract the files to a folder, open PowerShell as Administrator, and run the included .ps1 script. (Check the path to the VI Client is correct within the script, otherwise it won’t work).

Hope it helps!

Comments (0)
Categories: Uncategorized

Custom Configuration Section Collections

I’m sure this should be easy, but it’s taken me most of a morning of reading MSDN and tweaking code to get it to work. Most of the documentation that I have found has either been massively out of context, showing small segments of code and not explaining where it fits in or what it does; or it’s been hugely over complicated, showing complete examples with masses of boilerplate code.

I’ve been trying to get a simple collection, using tags to add a list of items, similar to how AppSettings and ConnectionStrings sections work. It was extremely easy to create a custom configuration section, with a single item and associated properties – creating a collection of items, with add/remove/clear functionality appeared to be a different matter.

Turns out, it’s actually not that difficult. 3 classes, 2 overrides, and some properties. After that, it’s just a case of registering the custom section in the configuration file in the section.

Section class

The section class inherits from ConfigurationSection, and serves as the wrapper for your configuration section in the app.config file. This is what you’ll add to the attribute to register the type in the Configuration manager:

[code lang=”csharp”]
public class ElementSection : ConfigurationSection
{
[ConfigurationProperty("Elements", IsDefaultCollection = false)]
[ConfigurationCollection(typeof(Elements),
AddItemName = "AddElement",
ClearItemsName = "ClearElements",
RemoveItemName = "RemoveElement")]
public Elements Elements
{ get { return this["Elements"] as Elements; } }
}
[/code]

Collection class

The collection class is required to tell the Configuration manager what to create and what to use to retrieve the elements. There are 2 required overrides for this class:

[code lang=”csharp”]
public class Elements : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new Element();
}

protected override object GetElementKey(ConfigurationElement element)
{
return (element as Element).Name;
}
}
[/code]

Element class

The class that contains your actual elements, all that’s required here is a property for each value you want to store against the element, which needs to be decorated with the ConfigurationProperty attribute.

[code lang=”csharp”]
public class Element : ConfigurationElement
{
[ConfigurationProperty("Name", IsRequired = true)]
public string Name
{
get { return (string) this["Name"]; }
set { this["Name"] = value; }
}
}
[/code]

app.config registration

The app.config file registration should be fairly trivial, all that’s required is the name you want to give the section, the namespace and class name, and the assembly name:

[code lang=”xml”]
<configuration>
<configSections>
<section name="ElementSection"
type="namespace.ElementSection, AssemblyName" />
</configSections>
</configuration>
[/code]

And that’s all there is to it. If anything is not clear, drop a comment and I’ll try to clarify.

Comments (0)
Categories: Uncategorized