Microsoft has provided some very good documentation on how to package fonts with WPF applications, and I’ve been following it in several different ways in different apps I’ve written. Recently I provided a feature in Posh Console which allows you to load the startup banner from an external file: StartupBanner.xaml.
Loading the banner from an external XAML file means that users can configure their own startup banner and make it look however they like, but it broke our default banner. The startup banner we’ve been using has a logo and some text which are all defined in pure XAML and uses several fonts which we had embedded in a FontLibrary.dll resource assembly. It worked great as long as the XAML was defined in the application, but as soon as we removed it to an external file and loaded it in using the XamlReader.Load method, the fonts all went to the fallback default fonts instead of our embedded ones.
Normally this might not be a big deal, but since our logo is based on the “Q” in a Quake-like font … it looks really lame without fonts.
Apparently, when you load external XAML, it can’t use the Font Resource Library resources. At this point, I can’t seem to find anything to indicate why this is the case, but I suspect it has to do with the fact that the external, loaded XAML only has partial trust, and since the font is in an external assembly instead of embedded in the partial trust content, it can’t get to it. However, it might be simpler than that: it might just be that the base URI for the externally loaded XAML is an actual file location rather than one of the pack://,,,application/ type URIs, so the slightly odd font path doesn’t resolve.
In any case, I found a way around it, which is of course, why I’m writing all of this down.
Read the rest of this entry »
So, I’ve been working on PoshConsole for awhile now, and with the help of some of the guys in #PowerShell@irc.freenode.net have been playing with trying to find ways to enhance output, like using ANSI escape sequences, and even creating an Out-WPF cmdlet which can output objects as databound WPF controls which look really good.
We have been trying to find a way to incorporate the colored and even bold/italic formatting in a way that would be compatible with the existing format-* cmdlets, and we’ve even looked at replacing out-default with a cmdlet that would be compatible with the default PowerShell host. But today I finally locked in on the import of this post on the PowerShell blog. It’s just not possible.
The format cmdlets (Format-List, Format-Custom, Format-Table, Format-Wide) output data in the form of undocumented .Net objects which are “subject to change without notice,” and are therefore basically useless. Of course, that means that if you want to replace Out-Default you have to not only replace the output, but you have to replace the formatting cmdlets, and of course the Update-FormatData cmdlet too — in fact, you have to either parse the largely undocumented format data files, or create some replacement for them to allow users to specify formatting for types you haven’t thought of…
All of this amounts to what many of you probably already knew: it’s a lot of work to create a complete PowerShell host, but it’s at least as much work to create a replacement PowerShell formatter.
This is actually a bit scary, because you can load sort-of … anything
To prove it (you’re gonna love this … I should take a video, really, but it’s time for bed, so this will have to do): check this out Beat that!
So yeah, I have this control written from an earlier project which creates a task list with live preview images. When I say “live previews” I mean actually live, like on the Vista Alt+Tab: if there’s a video playing, you can watch it in there (of course, it dies a horrible death on XP, but I have other code for that).
As a side note the TaskBar2.panel stuff is from the TINS release I made months ago, there’s several fun .panel files in there … but you have to load a bunch of the TINS assemblies first, I didn’t distinguish which ones, I just did:
Of course, in .Net 3.5 the RichTextBox has the ability to go ContentEnabled="true" which should allow those things to be actual controls you can click to switch active task, right-click to get a task menu, etc (although I haven’t tried that yet). We might just have to upgrade
Anyway, it’s past time for bed, so I’ll preempt complaints about how this isn’t ready for release yet with this quote:
I don’t have to take this abuse from you; I’ve got hundreds of people waiting to abuse me. — Bill Murray, “Ghostbusters”
One of the coolest things about scripting in PowerShell is that they’ve enabled the addition of extension methods to any class (object). Essentially, this means that you can add whatever methods This enables all sorts of utility functions that would normally end up in a library to instead be added to the base objects. Just for example, this week I was working on a script that needed to do HTTP basic authentication, which requires Base64 encoding a string. Now, that’s not very hard to do, really:
But really, that’s kind of a pain to remember, nevermind type each time. I mean, tab-completion helps, but what with all the square brackets and double-colons … So, instead, wouldn’t it be cool if I could just take my original string and call $name.AsBase64? Well, I can, with a pretty simple custom type.
We take this XML, put it in a file with the .ps1xml extension, and then call Update-TypeData MyTypes.ps1xml … Now we can call .AsBase64 or .FromBase64 on any string.
So then I ran into this simple problem. I wanted (in my script) to have the user type a password in… but not have it show up in their console. It turns out there’s a very over-engineered, and extremely elegant solution for this in PowerShell: Read-Host -AsSecureString "Prompt". It’s exactly what I wanted, in that it results in the console showing ***** as you type your password in. The only problem is, what you get out is a System.Security.SecureString which is essentially … well, useless.
So, a buddy was showing off the “say” command in the Mac OS X terminal the other day (my 3 year old daughter was vastly entertained) and I wondered what it would take to do the same thing in Windows PowerShell … it turns out the answer is, not much.
You just type this into the console:
The cool thing about this is that it’s async, unlike the Mac “say” command, so you can go on typing the next command while it’s speaking. On top of that, you can have it read a text file by just changing that 1 to a 5:
Now, being who I am, and what I am, I wasn’t content with that, so I wrote myself up a script, Out-Speech, that will speak whatever it’s given (an array of objects as an argument, or the pipeline objects … ) and exposes most of the options of the underlying Speech API.
Microsoft made several big announcements today at MIX07…
The most exciting announcement I’ve today is that Silverlight will include the Common Language Runtime (CLR) on both Windows and Mac … which means that it will allow development using any .NET-supported languages. They’re even including the open source Dynamic Language Runtime and thus IronRuby (which like IronPython is also open source).
On top of that, these features, plus support for Language Integrated Query language (LINQ) and cross-platform debugging capabilities, are available now in the Silverlight 1.1 Alpha (and will be released more publicly after Silverlight 1.0 comes out this summer?).
They also announced today that they will offer a media-hosting service for free called Silverlight Streaming! In a move that targets both Adobe’s flash and other media-hosting sites like YouTube and Revver … they will allow developers to stream high -quality video (up to DVD quality) into their Silverlight apps from Microsoft’s servers without any restrictions on branding or embedding (including use in “rich internet applications” — i.e.: outside the browser).
The current package in pre-release offers only 4GB of storage and unlimited bandwidth delivery of up to DVD quality video (700 Kbps), but their plan calls for Microsoft to provide hosting for unlimited Silverlight content and up to a million minutes of free video streaming at 700 Kpbs per site per month … that’s over 5,000 Gigabytes of bandwidth)+*+700+Kbps)+in+gigabytes of streaming per month, for free! They’ll also offer unlimited streaming for a fee, or free, but supported by advertising…
Astoria builds on ADO.NET and WCF to allows you to expose a data service for the web which can be consumed via HTTP and since it uses standard HTTP verbs (GET, POST, DELETE, etc) you can even make it accessible as a REST-style resource collection with unique URIs … and simple formats like JSON or plain XML ...
Jasper is another ADO.NET incubation project … aimed at dynamically typed .Net languages like VB.Net or IronPython … it dynamically generates data classes (instead of requiring manual, static configuration … or even code generation which must be kept up to date). It’s built on the Entity Framework (which was postponed until some time in 2008 … after Orcas ships), so it supports rich queries and object-relational mapping and automatic databinding.
The orchestration of announcements has many people buzzing about strong leadership and strategy … and the keynote by Ray Ozzie left no doubt about who’s behind that, highlighting the work Microsoft is doing to integrate all the various aspects of their strategy. Ozzie pitched Software-as-a-Service (SaaS) 2.0: web and hosted services which have “grown to embrace the uniquely valuable role of the client.”
In a move that only the undisputed king of browsers could hope to pull off, Microsoft has announced that they’ll be requiring web developers to opt in to standards-compliant web design … feel free to take a moment to check for flying pigs.
They’re also planning on making the IE object model more interoperable with other browsers and provide more client-side APIs — including local storage for AJAX apps and more extensibility in the form of a plugin API. Look for it in 2008.
I’ve been playing more with PowerShell lately, and there’s some really cool stuff in there! I though I’d post a few of my favorite discoveries. Generally speaking these are PowerShell user tips and tricks, because I’ve already been using PowerShell for a while, but since this is a “what I learned today” post, I’m not going to go back and write about the basics (besides, lots of other people are doing that already).
When you’re writing a PowerShell function, there is a method param which you can use to specify the parameters that the function accepts, including specifying their type, and their default value(s).
When you’re specifying types, you do so in square brackets like [System.Int32] but there are Type Shortcuts defined for the most common types, and even better, if you’re typing in PowerShell, you get tab-completion for them (even for the .Net types).
PowerShell includes a special type: [switch] which is for functions and scripts to take a command line parameter that is false by default (ie: it defaults to $false) and which doesn’t require any value on the command line (if you specify it, then it’s true). So for instance, if you had a script named “RandomLine” that looked like this:
You could call it by just writing RandomLine or you could suppress the message at the end (a plain string in PowerShell is equivalent to C# Console.WriteLine or a bash echo) by just specifying RandomLine -Quiet without needing to specify the value as $false.
Parameter names are not case sensitive, and don’t have to be fully typed out (as long as you type enough that the system can tell which one you mean), so you can actually call that script earlier as: RandomLine -q or RandomLine -q:$true -f:"C:\Users\Joel\Documents\Quotes\children's wisdom.txt"
Oh, and that script … depends on this other script:
Read the rest of this entry »Well, the latest news is that Visual Studio 2005 SP1 is available, which finally includes official support for running Visual Studio on Windows Vista [o.o], as well as for “Web Application” projects in VS2005 — which means you have to uninstall the previous web application project add-in.
While I’m writing about Visual Studio, and since I just had to reinstall Visual Studio and all my other tools on my new computer (yes, in Windows Vista), I figured I would point out some of the other add-ins that I depend on, as well as a few cool new downloads.
The Visual Studio Power Toys are a collection of addins and developer tools including ILMerge, VS Command Shell, the XML Notepad and more. In fact, MSBee — which I use regularly at work — is a one of the power toys. It allows you to develop applications that target the .NET Framework 1.1 in Visual Studio 2005. VS Window Manager is also a power toy, it allows you to save named layout presets which remember your window positions and auto-hide status… and even change automatically between layouts. There’s also a new power toy which sounds really nice, but that I haven’t had a chance to try yet: the Resource Refactoring tool which lets you extract hard-coded strings from code into resource files in C#, VB.NET and even web projects.
Anyway, the reason I started to mention the power toys is that they now have a Power Toys Pack Installer which aims to let you install some or all of these from a single installer interface. I just wish other people could publish their add-ins so they could be included in this thing — it sure would make this new setup process easier, especially if they could check for updates…
Another add-in I depend on is Roland Weigelt’s GhostDoc which makes keeping my documentation up-to-date much easier, especially because of his support for interfaces and inheritance. One pointer: if you install GhostDoc on Vista, (actually, this applies to 90% of these developer tools) make sure you run the installer as administrator or from a console with administrator access, because otherwise the installers sometimes fail, or worse, they appear to work but result in non-functioning installs.
I also use:
Oh, and while I’m at it … there’s a short stack of other add-ins that I still need to try out (in rough order of how excited I am about them).
Oh, and a random little link to Regulazy a regular expression tool for the rest of you (who can’t tell a \d{2} from a \w+). This isn’t an add in, but it is a really clever way to build regular expressions from a sample string that you want to match.
Technorati Tags: Develop, VisualStudio, .NET, VSAddins, Debugging, Visualizers
According to the SandCastle blog, the response to the beta of msdnwiki.microsoft.com has been very positive, with the main request being that they import more documentation (I know several of my developer friends have commented that none of the platform SDK is available there, which is where community sample code would be most appreciated). The good news is that:
Based on this feedback, MSDN is working to migrate the community content feature to their main site so that it can be expanded to the entire library, including other localized versions of the Whidbey documentation in MSDN2 by the end of this calendar year.
At that point, the only stuff that will remain on the MSDNWiki site is the machine-translated content — they offer machine translated documentation in Wiki format so that native speakers can improve the translations in languages where the market isn’t big enough for MSDN to offer an official translation of the documentation.
Microsoft’s ASP.NET team has created a tool based on the May CTP of LINQ (see the very cool what’s new video) for generating websites that display, create, and manipulate data. All you do is point Blinq at a database, and it creates a website that displays the data, allows sorting and paging and updating, deleting and creating new records, including following the relationships between tables.
The reason that’s impressive is because there’s no SQL queries to write, LINQ generates optimized queries and Blinq generates web forms and pages from the database schema. Of course, this is all in beta, and for developers only (you can’t use it in production yet).