Song of Ice and Fire References other fiction

Whilst reading the Song of Ice and Fire I keep finding references to other fiction.

To start with there are frequent mentions of Snarks (Lewis Carrol).

The singer Marillion is a secondary reference to the Scimarillion.

In the second part of book 5 there is a discussion about ways to kill dragons that seems to refer to The Hobbit.

Also in book 5 part two one of the captured ships is renamed Shrike (Hyperion) .

A blackadder is used as a heraldic device.

There is a pythonesque reference ‘fart in the general direction’ when discussing the unsullied.

There are even start wars quotes: ‘you should let him win’ and ‘you are my only hope’.

Simple Rules Engine

Here is a rules engine that is internal to the .Net Framework.

This is the kind of rule that I can use:

<RuleSet.Text Name=’Text Ruleset’ Description=’Test Ruleset’ ChainingBehavior=’None’>
<Rule Active=’True’ Name=’R1′ Description=’Checks Name’ Priority=’1′ ReevaluationBehavior=’Never’ >
<Condition>this.Name == null</Condition>
<ThenActions>
<Action>this.ValidationMessages.Add(“Name should not be empty”)</Action>
</ThenActions>
</Rule>
</RuleSet.Text>

The following is a unit test that executes the above:

[Test]
public void FileStringRule()
{
TextRuleSetSerializer rs = new TextRuleSetSerializer();
RuleSet Rules = rs.Deserialize(typeof(Person), File.ReadAllText(@”.Ruleset.Rule”) );
Person p = new Person();
RuleExecution execution = new RuleExecution(new RuleValidation(p.GetType(), null), p);

    Rules.Execute(execution);
Assert.AreEqual(1, p.ValidationMessages.Count);
}

Here is the definition of Person:

public class Person
{
public string Name { get; set;}
public int Age { get; set; }
private List<string> _ValidationMessages = new List<string>();
public List<string> ValidationMessages { get { return _ValidationMessages; } }
}

The beauty of this is that we have externalised the business rules in an efficient, readable compact form that makes no assumptions about the specific types.  The RuleEngine is passed a POCO to act as a Fact.  The Fact object is used to provide the details to the rules and collect the results.

By keeping the business rules externally to the application allows suitable changes to the logic to be made without requiring recompilation.  It is even possible to update the rules used by an application without requiring a redeploy!

However should you be prepared to take a dependency on a specific base class can I suggest that you look at the PerfectStorm.Model. This provides a base class that forms an Aggregate with a fully defined type system. It has the unusual property of being designed to permit invalid input to be entered. This allows an integer field to be set to the string XXX. This allows a single rules interface to perform complete declarative error handling – we don’t use one set of rules for parsing and another for buisiness logic. We can use rules to state what is an isn’t valid by providing an external ruleset. PerefectStorm.Model is intended to be a pure model class. It knows nothing of databases or user interfaces. It can hold data that an external class can use to map to these, but that is not it’s responsibility.

You need to be careful as to the specific goals of the rules engine. They are typically used to answer questions (Is this data valid? Could I save this to my database?) or to provide sensible defaults or to perform calculations (localised tax code calculations). These are also eminently suitable for unit testing and code generation.

Experimenting with powershell and tfs

I have been investigating with controlling powershell with tfs.

Other people have tried such as here and here.

Here is an example of creating a work item in powershell

The Tfs power tools project includes some powershell scripts yet fails to install them by default!

You need to repair the installation and then install the powershell scripts.

Even then you only get the x86 versions so you need to remember to use the x86 ISE/powershell console.

The following is the result of some experimentation with a free visualstudio.com tfs account.

It is not easy to authenticate against this so you need to map to a workspace and use the workspace to identify the server.

#This needs to use the x86 version of the ise
Add-PSSnapin Microsoft.TeamFoundation.PowerShell

[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.TeamFoundation.Client”)
[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.TeamFoundation.WorkItemTracking.Client”)

#OK you need to map the server to a local folder that is a workspace

#This returns a real tfs object
$tfs = Get-TfsServer -Path “d:devTFSTesting”

#With some powershell type trickery you can get to the other useful services.

$wit = $tfs.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])

#This shows that you can programatically get a specific work item (I only have this work item).
$wit.GetWorkItem(1)

#This demonstrates changing it
$wi = $wit.GetWorkItem(1)
$wi.Title = “Adjusted”
$wi.Save();

$wit.Projects[“TFSTesting”].StoredQueries | select Name,QueryGuid,QueryText

#Your GUID will vary.
$q = $wit.GetStoredQuery(“a6316d4a-7139-468c-b200-c9754e9de5c4″).QueryText.ToString()

#Example simple query
$wit.Query(”
Select [State], [Title]
From WorkItems
Where [Work Item Type] = ‘Product Backlog Item’
Order By [State] Asc, [Changed Date] Desc”)

#Adding a simple work item

$workItem = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem($wit.Projects[“TFSTesting”].WorkItemTypes[“Product Backlog Item”])
$workItem.Title = “Created by Windows PowerShell!”
$workItem.Save()

#More work needs to be done to ensure that the work items have the correct properties .

BOF Unicode

A coworker of mine was having trouble getting a batch file to run as part of the Azure startup process. He needed to do some kind of config to the environment.

The batch file worked if he rdp’d to the machine but failed on deploy.

When we opened the file in notepad it started with three unexpected characters.

This was the BOF unicode header, a piece of nonsense that identifies the file as being unicode, but breaks a lot of older technology that tries to use it.

Hint to microsoft: either implement transparent bypass of BOF header everywhere or stop using it.

It was an easy to save the file as UTF without the BOH header.

Lucine.Net

Tutorial:

http://www.d80.co.uk/post/2011/03/29/LuceneNet-Tutorial.aspx

The basic library can be installed via NuGet

There is a simple https://github.com/ajorkowski/AzureDataCacheDirectory that should just work.

This uses the Azure Cache service to store the Lucene Indexes.

I am planning to test this on the local emulated cache to see if it works.

This is a minor update to the supplied sample (Lucene has fixed the naming conventions to confirm to C# norms):

using Lucene.Net.Analysis;
using System.IO;

using Directory = Lucene.Net.Store.Directory;
using Version = Lucene.Net.Util.Version;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.QueryParsers;

var fordFiesta = new Document();
fordFiesta.Add(new Field(“Id”, “1”, Field.Store.YES, Field.Index.NOT_ANALYZED));
fordFiesta.Add(new Field(“Make”, “Ford”, Field.Store.YES, Field.Index.ANALYZED));
fordFiesta.Add(new Field(“Model”, “Fiesta”, Field.Store.YES, Field.Index.ANALYZED));

var fordFocus = new Document();
fordFocus.Add(new Field(“Id”, “2”, Field.Store.YES, Field.Index.NOT_ANALYZED));
fordFocus.Add(new Field(“Make”, “Ford”, Field.Store.YES, Field.Index.ANALYZED));
fordFocus.Add(new Field(“Model”, “Focus”, Field.Store.YES, Field.Index.ANALYZED));

var vauxhallAstra = new Document();
vauxhallAstra.Add(new Field(“Id”, “3”, Field.Store.YES, Field.Index.NOT_ANALYZED));
vauxhallAstra.Add(new Field(“Make”, “Vauxhall”, Field.Store.YES, Field.Index.ANALYZED));
vauxhallAstra.Add(new Field(“Model”, “Astra”, Field.Store.YES, Field.Index.ANALYZED));

using (RAMDirectory directory = new RAMDirectory())
{
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);

var writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
writer.AddDocument(fordFiesta);
writer.AddDocument(fordFocus);
writer.AddDocument(vauxhallAstra);

writer.Optimize();
writer.Close();

IndexReader indexReader = IndexReader.Open(directory, true);
using (Searcher indexSearch = new IndexSearcher(indexReader))
{
var queryParser = new QueryParser(Version.LUCENE_30, “Make”, analyzer);
var query = queryParser.Parse(“Ford”);

Console.WriteLine(“Searching for: ” + query.ToString());
TopDocs resultDocs = indexSearch.Search(query, indexReader.MaxDoc);

Console.WriteLine(“Results Found: ” + resultDocs.TotalHits);

var hits = resultDocs.ScoreDocs;
foreach (var hit in hits)
{
var documentFromSearcher = indexSearch.Doc(hit.Doc);
Console.WriteLine(documentFromSearcher.Get(“Make”) + ” ” + documentFromSearcher.Get(“Model”));
}

}
}

I have a sample app that uses the Azure Cache As A Service version:

https://github.com/chriseyre2000/Study/tree/master/azure/Lucene/

You need to supply your own cache service id and authentication string.

ITunes on Windows – Epic Design Failures

Apple are always pointed to as a company that is good at UI design.

However in reality things are somewhat different.

There are the mildly annoying problems such as the control with focus having such a subtle change of colour on the border (and no cursor) that data entry becomes much harder.

The password entry for “apple id” registration is a joke – you get the following error without having been told the password requirement:

“The password you entered is not valid. Check the password requirements and try again.”

Eventually by trial and error I was able to deduce the rules (Capital Letter + Number + Non Alpha Numeric).

Whrn you eventually get the email to confirm a request for an apple id (my wife took 5 attempts to get this to happen) it asks you to enter your apple id.

At no point are you told that this is the email address that you had supplied.

Adding a credit card fails unless you have clicked the right credit card brand image (you can infer the card type from the number).

If you have plugged your ipod in before installing itunes then you don’t get to see the ipod itself until you remove and reconnect the device.

When you change the location of where you want to store your music it will conveniently forget these changes and put them back where it wants to.

The iTunes application keeps throwing up the web browser which is confusing as hell.

Why can’t you simply treat the device as an external usb drive and allow music to be added there?

The iPod Shuffle itself is a great piece of kit.