Entries from June 1, 2012 - June 30, 2012

Friday
Jun292012

VisioAutomation 2010 and VisioAutomation.VDX available as NuGet packages  

I've released NuGet packages for both VisioAutomation 2010 and VisioAutomation.VDX. NuGet makes it so much simpler for developers to consume my libraries I suspect I'll stop publishing the binaries to CodePlex entirely in favor of the NuGet method.

This now means I've published 3 packages:

  1. VisioAutomation 2010
  2. VisioAutomation.VDX
  3. VisioCSharpSamples

I've got a few more packages on the way next week. Afterwards, it's time for me to explore if Chocolately is useful for my projects.

Monday
Jun252012

Programmatically Generating HTML5 in C# without the Xml Declaration and using the correct html DTD - using XmlWriter, XmlDocument, and XDocument  

Below a look at a simple “hello-world” example of HTML5:

<!DOCTYPE html>
<html>
  <head />
  <body>
    <p>Hello World</p>
  </body>
</html>

If you have ever generated HTML5 programmatically in C#, you may have noticed that by default you will get an unwanted Xml declaration (in red below) and the html DOCTYPE is not present.

Using System.Xml.XmlWriter

First, let's try using System.Xml.XmlWriter:

 var w = System.Xml.XmlWriter.Create("document_xmlwriter.htm");
w.WriteStartDocument();
w.WriteStartElement("html");
w.WriteStartElement(
"head");
w.WriteEndElement();
// </head>
w.WriteStartElement("body");
w.WriteStartElement(
"p");
w.WriteString(
"Hello World");
w.WriteEndElement();
// </p>
w.WriteEndElement(); // </body>
w.WriteEndElement(); // </html>
w.WriteEndDocument();
w.Close();

This code snippet will produce the following HTML. Note that I have manually indented the output to make it easier to read.

<?xml version="1.0" encoding="utf-8"?>
<html>
  <head />
  <body>
    <p>Hello World</p>
  </body>
</html>

Fortunately, it is very easy to alter the example to do exactly what we need. It merely involves using the XmlWriterSettings class to omit the Xml declaration and adding the doc type manually.

var settings = new System.Xml.XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.Indent = true;

var w = System.Xml.XmlWriter.Create("document_xmlwriter.htm", settings);

w.WriteStartDocument();
w.WriteDocType("html", null, null, null);
w.WriteStartElement("html");
w.WriteStartElement("head");
w.WriteEndElement(); // </head>
w.WriteStartElement("body");
w.WriteStartElement("p");
w.WriteString("Hello World");
w.WriteEndElement(); // </p>
w.WriteEndElement(); // </body>
w.WriteEndElement(); // </html>
w.WriteEndDocument();
w.Close();

 

Using System.Xml.Linq.XDocument and XmlWriter

 

In order to achieve the same effect with System.Xml.Linq.XDocument we will need to use XmlWriter.

var d = new System.Xml.Linq.XDocument();
d.AddFirst(new  System.Xml.Linq.XDocumentType("html", null, null, null));

var html_el = new System.Xml.Linq.XElement("html");
d.Add(html_el);

var head_el = new System.Xml.Linq.XElement("head");
html_el.Add(head_el);

var body_el = new System.Xml.Linq.XElement("body");
html_el.Add(body_el);

var p_el = new System.Xml.Linq.XElement("p");
body_el.Add(p_el);

var text_el = new System.Xml.Linq.XText("Hello World");
p_el.Add(text_el);

var settings = new System.Xml.XmlWriterSettings();
settings.OmitXmlDeclaration = true;

var w = System.Xml.XmlWriter.Create("document_xdocument.htm", settings);
d.Save(w);
w.Close();

 

Using System.Xml.XmlDocument

Life is a little easier with System.Xml.XmlDocument because the Xml declaration is not output by default, so we only need to specify the DTD.

var d = new System.Xml.XmlDocument();

var dt = d.CreateDocumentType("html", null, null, null);
d.AppendChild(dt);

var html_el = d.CreateElement("html");
d.AppendChild(html_el);

var head_el = d.CreateElement("head");
html_el.AppendChild(head_el);

var body_el = d.CreateElement("body");
html_el.AppendChild(body_el);

var p_el = d.CreateElement("p");
body_el.AppendChild(p_el);

var text_el = d.CreateTextNode("Hello World");
p_el.AppendChild(text_el);

d.Save("document_xmldocument.htm");

 

 

 

 

Thursday
Jun212012

Visio C# Automation Samples with NuGet  

Because I have been seeing the occasional requests for C# sample code (via sites like StackOverflow), this week I explored how we can use NuGet to make live much simpler. So I've published a new NuGet package called VisioCSharpSamples.

WALKTHROUGH

First, install NuGet: http://nuget.org/ 

Second, create an simple C# project in Visual Studio 2010 or Visual Studio 2012. The screenshots below show Visual Studio 2012 RC. In this case, let's pick a simple console application.

If you examine the Solution Explorer, you'll see the expected result.

Snap034

Now select Tools > Library Package Manager > Package Manager Console

Snap035

One the console loads, ensure that the Package source is pointing to the official NuGet feed

Snap036

 

Then type in the following:

Install-Package VisioCSharpSamples

You'll see that the latest version of the samples is installed

Snap037

Let's look at the Solution Explorer to confirm what happened.

Snap038

 

Notice that a reference to Microsoft.Office.Interop.Visio was added.

Also, there is a folder called VisioCSharpSamples that contains several C# code files.

Currently, there's a static class called Samples that contains some static methods. The simplest is called HelloWorld found in the HelloWorld.cs file.

Snap039

Of course, you can now simply call HellWorld() from your program and quickly get started transforming this hello world into something more complex.

QUICK SUMMARY

  • NuGet makes it easy to get libraries into your projects in either source or binary form
  • I've published a NuGet package called VisioCSharpSamples that contains some useful source code snippets
  • Suggestions for additional samples are welcome

 

 

 

 

Tuesday
Jun122012

The Slick New Bariol Font Family by atipo  

I haven't before found a typeface with a rounded look that I enjoyed, That changed today when I discovered Bariol. It's very readable and its rounded quality does not detract from its gravitas –  unlike for example Helvetica which I think looks too playful. I could easily see Bariol replacing Segoe UI for my presentations.

Also Bariol is very affordable. You can get Bariol Regular for free simply by tweeting or posting about it on Facebook. The Light, Thin, and Bold variants are avalable individually or at a package and you an pay as little as €1 for each or €3 for the entire package. For the record, I paid €20 for the package. 

 

Snap011

 

Bariol Regular

Snap015

 

 

Bariol Light

Snap014

 

 

Bariol Thin

Snap013

 

 

Bariol Bold

Snap012

 

Thursday
Jun072012

Wacom tablets and Windows 8 Release Preview: What you need to know  

PLEASE READ: The Windows and Wacom Tablet Nightmare is Over

 

[UPDATE ON 2012–08–18] This article describes Windows 8 Release Preview to see the latest information regarding Windows 8 RTM and Wacom go here: http://viziblr.com/news/2012/8/18/windows-8-rtm-and-wacom-tablets-better-but-flawed.html

I described the issues I found with the Windows 8 Consumer Preview back in March 2012: First Look: Windows 8 and Wacom Tablets. It got worse. But those were early days, with the release of the Windows 8 Release Preview recently, it's time to see how things have evolved. And critically, for those of you who are tempter to switch over to the Windows 8 Release Preview as your primary OS, you'll want to know what the experience will be like.

A BRIEF HISTORY AND SUMMARY

Everything perfect back in the XP days. Vista introduced some unwanted default behaviors that you could easily disable in the control Panel. Windows 7 forced kept the unwanted behaviors but forced consumers to modify their registry to get thinks working again. Especially if you were using Windows 7 Home Premium you had a tough time. But at least some help was available to restore sanity.

Summary: Windows 8 Release Preview shows some improvements but remember those registry key changes that fixed the problems –  They don't work anymore. If using your Wacom tablet is very critical to you, skip the Release Preview.

GOOD NEWS: THE CURSOR WHEN USING THE STYLUS

When using the stylus, Consumer Preview cursor showed a tiny dot instead of an arrow. See the image below.

Snap000070

It's back to an arrow in the Windows 8 Release Preview

 

POTENTIALLY GOOD NEWS: TABLET PC INPUT PANEL

Windows Vista and Windows 7 would respond to the presense of the Wacom tablet with the Tablet Input Panel.

Snap000071

And then we had to go disable it.

The situation is better in Windows 8 Release Preview. The tablet does not appear by default. This could be a bug, but I hope it remains unfixed.

 

POTENTIALLY GOOD NEWS: FLICKS

In Windows 7 we would see the Flicks icon in the notification area and the Flicks would be enabled by default. We had to disable both the icon and the flicks behavior in the control Panel.

Snap000072

In Windows 8, the flicks icon lo longer appears in the notification area.

Snap000073

Curiously, the Control Panel indicates that flick recognition is enabled, however it doesn't actually recognize any flicks. I don't know if this behavior is deliberate or accidental in the Windows 8 Release Preview. To be safe, I disabled the flicks.

 

VERY BAD: PRESS-AND-HOLD

Remember that press-and-hold ring that would appear in Windows 7.

Snap000074

You can try to disable it in the Control Panel all you'd like, it is always enabled. This seems like a straightforward bug, which I would expect will be fixed before Windows 8 releases.

 

VERY BAD: DYNAMIC FEEDBACK FOR THE PEN

Ah the hated ripples… they are back and also they cannot be disabled –  even if you set the registry correctly to disable them.

Snap000078

Again this seems like a basic bug that will be fixed.

 

VERY BAD: BASIC INTERACTION WITH UI COMPONENTS

There seem to be some occasional odd issues when using doing things like selecting items in comboboxes and trying to resize columns in gridviews. Sometimes clicks and drags simple “disappear”. I often have to use the mouse or the keyboard to complete the action.

This is the third issue that will be very frustrating because it affects consumers' use of “normal” non-creative apps.

 

PARTING THOUGHTS

I don't doubt the problems will be addressed which should put us back to slightly better position than we had in Windows 7. Of course if they could re-enable the “disable dynamic feedback” option that we last saw in Vista, that would be even better.