Moving profile folders to another drive

I use the Run app in windows an awful lot. I know the new start menu in Vista/7 offer a more advanced indexed version of the run command but I just can’t shake the habit. Also it doesn’t do the common folders a developer is looking for, such as Desktop, Temp folder etc etc.

The main problem with it after you have moved all of the profile folders to another drive, is that you cannot get to folders like the desktop, Windows just cannot find them anymore. I know you could probably go into the registry and start hacking around and telling Windows where else to go for the user folders but that just never sat quite right with me.

So here is a neat little trick I found, goto the user folder (C:\Users\Logaan) and create a shortcut with the same name as the folder you wish to get to.

Its so simple and I cannot believe that I found this years ago.

Its so cool you can even create links to other folders that you cannot usually get to in this fashion.

Enjoy.

Composite WPF Presentation Model item template

Neat little template I designed for use at work which is an improvement over the ViewModel code snippet.

Download PresentationModel item template

How to use

It is a bit unusual the way I have written this. Instead of specifying the file name for the item, it is the view name that is to be used.

When prompted for the ViewName, specifying “MainWindow” will create:

A xaml user control called MainWindowView.xaml.

An interface called IMainWindowView.

An interface called IMainWindowViewModel.

A class called MainWindowViewModel.

(Some of this is very similar to the ViewModel code snippet)

Interface Properties

Basically rip-offs of the prop and propg code snippets you get with Visual Studio but without the scope or accessor keywords.

iprop

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>iprop</Title>
			<Shortcut>iprop</Shortcut>
			<Description>Code snippet for an automatically implemented property on an interface</Description>
			<Author>Alex Boyne-Aitken</Author>
			<SnippetTypes>
				<SnippetType>Expansion</SnippetType>
			</SnippetTypes>
		</Header>
		<Snippet>
			<Declarations>
				<Literal>
					<ID>type</ID>
					<ToolTip>Property type</ToolTip>
					<Default>int</Default>
				</Literal>
				<Literal>
					<ID>property</ID>
					<ToolTip>Property name</ToolTip>
					<Default>MyProperty</Default>
				</Literal>
			</Declarations>
			<Code Language="csharp"><![CDATA[$type$ $property$ { get; set; }$end$]]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>

ipropg

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>ipropg</Title>
			<Shortcut>ipropg</Shortcut>
			<Description>Code snippet for an automatically implemented property with a 'get' accessor for interfaces</Description>
			<Author>Alex Boyne-Aitken</Author>
			<SnippetTypes>
				<SnippetType>Expansion</SnippetType>
			</SnippetTypes>
		</Header>
		<Snippet>
			<Declarations>
				<Literal>
					<ID>type</ID>
					<ToolTip>Property type</ToolTip>
					<Default>int</Default>
				</Literal>
				<Literal>
					<ID>property</ID>
					<ToolTip>Property name</ToolTip>
					<Default>MyProperty</Default>
				</Literal>
			</Declarations>
			<Code Language="csharp"><![CDATA[$type$ $property$ { get; }$end$]]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>

How to learn Programming

Read a fantastic article on Life Hacker on how to teach yourself computer programming: http://lifehacker.com/5401954/programmer-101-teach-yourself-how-to-code

My only comment would be pick a language that is based on C-like syntax (rather than use Python or VB) because although the syntax may seem harder, the syntax is more transferrable to other languages and it would give you a head start.

In my personal experience, a book only served as a reference. I found books that taught me how to do something soon became too basic for my needs and often there are plenty of guides on the internet that is a good replacement. Instead you will find much of my library consists of reference books, hint, tips and advanced topics.

CyTS library stalling

On our guild website, we have a block in the portal that shows who is currently on teamspeak. This uses the CyTS library to connect and get such information and occasionally it would cause the portal to stop loading.

In each case I would get home, load it up and not find any problems at all. Well today was a different matter, I was able to pin point the exact issue. For some reason the library connects to the server but then stalls when receiving information from the server.

I should tell you know, this is not a perfect fix but it does the job. I did look into other options like switch socket blocking on and off and such other approaches, but it seems that if fgets reads more than 1 byte, it stalls. This is a bug in PHP that has hung around for a while.

I have changed the _readcall function to read the first byte, check it for failure then continue with the rest.

function _readcall()
{
	if (!is_resource($this->sCon))
		return false;

	// HACK : Workaround to fail fast
	$first = fgets($this->sCon, 1);

	if($first === false)
		return false;

	$sRead = '';
	do
	{
		$cRead = $first.fgets($this->sCon);
		$first = '';

		$sRead .= $cRead;
	} while ($cRead != CYTS_SYN && $cRead != CYTS_OK && strtoupper(substr($cRead, 0, 5)) != "ERROR");
	return $sRead;
}

View model property

Because I am so lazy :P

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>View model property snippet</Title>
			<Shortcut>vmprop</Shortcut>
			<Description></Description>
			<Author>Alex Boyne-Aitken</Author>
			<SnippetTypes>
				<SnippetType>Expansion</SnippetType>
			</SnippetTypes>
		</Header>
		<Snippet>
			<Declarations>
        <Literal>
          <ID>name</ID>
          <ToolTip>Property name</ToolTip>
          <Default>Field</Default>
        </Literal>
        <Literal>
          <ID>field</ID>
          <ToolTip>Field name</ToolTip>
          <Default>field</Default>
        </Literal>
        <Literal>
          <ID>type</ID>
          <ToolTip>Type</ToolTip>
          <Default>object</Default>
        </Literal>
			</Declarations>
			<Code Language="csharp">
        <![CDATA[
    $type$ $field$;
    public $type$ $name$
    {
        get { return $field$; }
        set
        {
            if ($field$ == value)
                return;

            $field$ = value;
            SendPropertyChanged("$name$");
        }
    }
			$end$]]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>

MSBuild creating lots of temp files

UPDATE:

I found a msdn forum post with exactly the same issue: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/42647eff-ecb8-412c-a884-a152b6fdd40d

It turns out that it is NOT msbuild but it is SN.exe leaving the temp files behind when resigning assemblies. I suppose you could easily come to this conclusion when watching the build and those files are flashing by so quickly.

On reflection a custom task will not help either…

This post has more details on the issue with a link to a hot fix for Server 2003: http://blogs.msdn.com/pfedev/archive/2008/10/24/sn-exe-and-empty-temp-files-in-temp.aspx

If you are using Server 2008 I would not recommend installing it.

Continue reading ‘MSBuild creating lots of temp files’ »

Simpler version of the 7-Zip backup

I have tested the 7-Zip backup I had constructured that I posted about a while back and I have come to realise that it is a tad bit too complicated. I even went through the process of creating a proxy application to try and get it to be a bit more cleverer but in the end I simplified it down to just 4 parts; the logic, settings and file lists.

Backup.cmd

@ECHO OFF

ECHO 7-Zip backup script
ECHO Written by Alex Boyne-Aitken
ECHO Last update: 07/11/2009
ECHO.

ECHO TRACE: Parse arguments: '%~f1'
IF EXIST %~f1 GOTO labelBegin

ECHO.
ECHO ERROR: Settings file not found!
GOTO labelWaitEnd

:labelBegin

ECHO.
ECHO TRACE: Reading settings
FOR /F "eol=# tokens=1,2 delims==" %%i IN (%~f1) DO (
SET %%i=%%j
ECHO TRACE: %%i = '%%j'
)

SET varTimeStamp=%DATE:~-4%-%DATE:~3,2%-%DATE:~0,2%-%TIME:~0,2%-%TIME:~3,2%
SET varTargetBackupSet=%varBackupPath%\%varTimeStamp%-backup.zip

ECHO.
ECHO TRACE: Backup set: '%varTargetBackupSet%'
ECHO TRACE: Command line: '"%varPathToSevenZip%\7z" a -t%varArchiveType% "%varTargetBackupSet%" @"%varInclusionsFile%" -xr@"%varExclusionsFile%"'

ECHO.
ECHO TRACE: Executing backup
"%varPathToSevenZip%\7z" a -t%varArchiveType% "%varTargetBackupSet%" @"%varInclusionsFile%" -xr@"%varExclusionsFile%"

IF /I NOT "%varWaitAtEnd%" == "true" GOTO labelEnd

:labelWaitEnd
PAUSE
:labelEnd

Settings.txt

# The path to the where the 7z.exe executable is
varPathToSevenZip=C:\Program Files\7-Zip

# The path where to store the backup sets
varBackupPath=D:\Backups

# The file path to the inclusions file
varInclusionsFile=D:\Logaan\Documents\Tools\7ZipBackup\Settings\Inclusions.txt

# The file path to the exclusions file
varExclusionsFile=D:\Logaan\Documents\Tools\7ZipBackup\Settings\Exclusions.txt

# Whether to wait at the end of the backup
varWaitAtEnd=true

# Type of backup archive to create
varArchiveType=zip

Exclusions.txt

*.svn

Inclusions.txt

D:\Logaan\Documents
D:\Logaan\Favorites
C:\Users\Logaan\Desktop
D:\Logaan\Saved Games

How to use it

Place the batch file and settings files in a folder somewhere.

Update the setttings file with the correct paths.

Pass the path to the settings file to the backup batch file.

C:> backup D:\Logaan\Documents\Backup\settings.txt

Or create a scheduled task.

Edit Action

Closeable TabItems using CompositeWPF

On a project I am working on at the moment, I needed to allow the user to open and close views. As I was using the Composite Application Block injecting views into a tab control was really easy. Closing them was not.

To remove a view from a region you need two things, the RegionName and the View.

This article helped me a lot when engineering this approach:

http://blogs.infosupport.com/blogs/willemm/archive/2008/07/31/Creating-closeable-tabitems-for-use-in-CompositeWPF.aspx

However the RegionManager.GetRegionName did not work against the TabItem. I always got null, I am assuming this is a change that was made during the time the article was posted. Using the TabControl however worked.

But you cannot easily bind to two things (the TabControl and the TabItem).

To achieve my goal I used the XAML from the article and changed it little

<DataTemplate x:Key="CustomTabHeader">
<StackPanel Orientation="Horizontal">
<ContentPresenter>
<ContentPresenter.Content>
<Binding Path="Content.Model.HeaderText">
<Binding.RelativeSource>
<RelativeSource Mode="FindAncestor"
AncestorType="{x:Type TabItem}"/>
</Binding.RelativeSource>
</Binding>
</ContentPresenter.Content>
</ContentPresenter>
<Button Margin="8,0,0,0"
Command="{Binding Path=Model.CloseTabCommand.Command, ElementName=ThisControl}"
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type TabItem}}}"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center">
<Grid>
<Canvas Width="8" Height="8">
<Line X1="2" X2="6" Y1="2" Y2="6" Stroke="Black" StrokeThickness="1"/>
<Line X1="6" X2="2" Y1="2" Y2="6" Stroke="Black" StrokeThickness="1"/>
</Canvas>
</Grid>
</Button>
</StackPanel>
</DataTemplate>

<Style TargetType="TabItem">
<Style.Setters>
<Setter Property="HeaderTemplate"
Value="{StaticResource CustomTabHeader}"/>
</Style.Setters>
</Style>

The only difference is where I go for my commands and header text. In my project I have an interface that describes a headed content item.

The change really is in the code for closing the view:

class CloseTabCommand : CommandModelBase
{
private readonly IRegionManager regionManager;

public CloseTabCommand(IRegionManager regionManager)
{
this.regionManager = regionManager;
}

public override void OnExecute(object sender, ExecutedRoutedEventArgs e)
{
var tabItem = (TabItem)e.Parameter;
var tabControl = (TabControl) e.Source;

var regionName = RegionManager.GetRegionName(tabControl);

regionManager.Regions[regionName].Remove(tabItem.Content);
}
}

In the end the solution boiled down to being really simple. You still bind to the tab item but the source is the tab control.

There will be some drawbacks to this approach. If a key binding is setup for this command then the source could change, so care should be taken.

But this works and it will do for the time being until I think of a better solution.

Project Validator

As an idea that compliments the previous validator I built, this msbuild task will search for all the projects in a given path and check that they are all building to the correct path.

Download source

To use just define two properties: SearchPath, which is the parent folder to start looking in. It will search all subfolders as well by default. And BuildFolder, which is the desired target for building to.

All it does is very simple substring matching to check that it is valid.

For example, if I build a project to ..\bin\Debug and ..\bin\Release and the specify my build folder is ..\bin then both paths are valid. But if one of the build targets was set to something like ..\foo then it would be invalid

Again, this validator could be extended to check other parts of the project files.