Friday, December 15, 2006

Google Santa Tracker and Toy Hunt

It seems that you can go threasure hunting with Google Earth. You get a clue every day where to find a 'hidden' present, or maybe it's just a package that fell off the sledge in such a way that it opened. Well anyway, just go hunting and maybe learn some geography on the way.

Link to Google Santa Tracker and Toy Hunt

Tuesday, November 28, 2006

.NET 3.0 artikelserie fortsättning

Del 4 och 5 är skrivna på pellesoft och kommer att släppas inom kort. Denna gång handlar det om WPF.

Technorati tags: , ,

Thursday, November 23, 2006

Implicit UseSynchronizationContext==true may lead to deadlocks ...

Today I found a little gem on Mahjayar's blog on the use of CallbackBehavior and UseSynchronizationContext. Basically, if you have a duplex contract you might want to switch off UseSynchronization context, particularly if the client is WinForms (or WPF), or you might end up with deadlocks.

Technorati tags:

Add blogger Labels to Windows Live Writer

It seems that the "Insert Tags..." thing in Windows Live Writer is customizable enough that it is possible to add support for blogger labels by doing the following:

  • Insert tags ... -> Choose (Customize Providers...) in dropdown list
  • Add...
  • Set provider name appropriately so that you know it e.g. blogger
  • Set template to:
    <a href="http://obviously-your-blog-name.blogspot.com/search/label/{tag-encoded}"
    rel
    ="tag">{tag}</a>

  • Set tag separator to ", " (without the quotes)
  • Set htm caption to "<span class="post-labels">Labels: {tag-group}</span>" (without the quotes)

If you do that, and add tags using that provider, the tags should work exactly as when blogging via web-ui.


EDIT: it seems that the labels do not show up on the edit posts page in the web ui. I wonder if that matters?

EDIT2: it looks correct but does not work... (


Technorati tags:

Wednesday, November 22, 2006

HOWTO: Read attributes from an enumeration member

Today I needed to read custom attributes from members of an enumeration type. As the found solution did not strike me as immediately obvious, I'm posting here for future reference:

Thing foo = Thing.Bar;
FieldInfo field
= foo.GetType().GetField(foo.ToString());
object[] attrs = field.GetCustomAttributes(typeof(Description), false);


where Thing is an enumeration, defined something like:



public enum Thing {
[Description(
"Foo thing")]
Foo,
Bar,
[Description(
"Baz thing")]
Baz
}



Technorati tags: ,

Tuesday, November 21, 2006

.NET 3.0 artikelserie på gång

Har börjat skriva en artikelserie om .NET 3.0 på pellesoft.

Del 1, 2, 3 redan klara och handlar främst om WCF. Nästa i tur är ytskrap av WPF. Del 1 släpptes idag. Del 2 kommer i morgon och del 3 i övermorgon.

Technorati tags: , ,

Friday, November 17, 2006

Php and security ...

I recently had the "opportunity" to look for security problems in an inherited php application. I found the following seemingly innocent line of code:

require($_GET['menu'].'.inc');


Well let's think about it a little..



  • Imagine there is somewhere one or more users that are not all that friendly ...
  • Imagine $_GET['menu'] is something that comes from a user ...
  • Imagine that php treats the include():d/require():d code as php and not html
  • Imagine that the include():d/require():d file would not have to exist on the same server
  • Imagine that there somewhere on the Internet exists text/plain file containing php code

If that was true, then we would have a $h*tload of problems, right? Fortunately that's not true... ..right?


..oh, wait.. *all* of those are true. Oops...



Technorati tags: ,

Tuesday, November 07, 2006

Wednesday, October 18, 2006

List of Wix3 'autodetected' products

Jonathan de Halleux asked for a list of 'autodetected' products in Wix3.

Looking for something to do, I went through the sources for 3.0.2211.0 (src\ext\*\wixlib\*.wxs) for relevant properties.

NetFxExtension:
- NETFRAMEWORK10
- NETFRAMEWORK11
- NETFRAMEWORK20
- NETFRAMEWORK30
- NETFRAMEWORK11SDKDIR
- NETFRAMEWORK20SDKDIR

IisExtension:
- IISMAJORVERSION
- IISMINORVERSION

Monday, October 02, 2006

<Blink> on steroids...

One of the long-standing jokes at the office is about using the much hated <Blink> tag in XAML user interfaces. (The other one being about mapping the UI onto the inside of a sphere..)

Disclaimer: This is NOT in ANY WAY suggested for any use WHATSOEVER. We have already seen way too many blinking webpages, thank you very much. And the code is "proof-of-concept" quality..

So basically, I wanted to do a a component that I can use in XAML, making it's content blink. And just for the fun of it, I wanted the on and off durations tunable, and the same goes for the durations of the fade in and fade out between those two extremes.

So here goes nothing...

First a little test case:

<Window x:Class="Blink.Window1"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src
="clr-namespace:BlinkTest" Title="Blink" Height="300" Width="450">

<StackPanel Orientation="Vertical">
<!-- Use default blinking settings -->
<src:Blink>
<TextBlock Padding="20" Margin="20" Background="Pink">Hello World</TextBlock>
</src:Blink>
<!-- Explicitely specify blinking settings -->
<src:Blink OnDuration="1" OffDuration="1" FadeInDuration="0" FadeOutDuration="0">
<StackPanel Orientation="Horizontal" Margin="50">
<Label>Some nice text about the button</Label>
<Button>Click Me!</Button>
</StackPanel>
</src:Blink>
</StackPanel>
</Window>


And then the code for the Blink class


The using statements


using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;

We are inheriting System.Windows.Controls.Control so we have to do some cruft related to layout




protected override int VisualChildrenCount {
get { return Child != null ? 1 : 0; }
}

protected override Visual GetVisualChild(int index) {
if (index > 0 || Child == null) throw new ArgumentException("index");
return Child;
}

protected override Size MeasureOverride(Size constraint) {
Size sizeDesired
= new Size(0, 0);
if (Child != null) {
Child.Measure(constraint);
}
sizeDesired.Width
+= Child.DesiredSize.Width;
sizeDesired.Height
+= Child.DesiredSize.Height;

return sizeDesired;
}

protected override Size ArrangeOverride(Size arrangeBounds) {
if (Child != null) {
Rect rect
= new Rect(
new Point((arrangeBounds.Width - Child.DesiredSize.Width) / 2,
(arrangeBounds.Height
- Child.DesiredSize.Height) / 2),
Child.DesiredSize);
Child.Arrange(rect);
}
return arrangeBounds;
}


And for the animation to work we need a number of dependency properties for the durations




Now, all that is left is just the blinking animation. An obvious choice for

// Using a DependencyProperty as the backing store for OffDuration. This enables animation, styling, binding, etc...
public static readonly DependencyProperty OffDurationProperty;

// Using a DependencyProperty as the backing store for OnDuration. This enables animation, styling, binding, etc...
public static readonly DependencyProperty OnDurationProperty;

// Using a DependencyProperty as the backing store for RiseDuration. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FadeInDurationProperty;

// Using a DependencyProperty as the backing store for DeclineDuration. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FadeOutDurationProperty;

public double OnDuration {
get { return (double)GetValue(OnDurationProperty); }
set { SetValue(OnDurationProperty, value); }
}

public double OffDuration {
get { return (double)GetValue(OffDurationProperty); }
set { SetValue(OffDurationProperty, value); }
}

public double FadeInDuration {
get { return (double)GetValue(FadeInDurationProperty); }
set { SetValue(FadeInDurationProperty, value); }
}

public double FadeOutDuration {
get { return (double)GetValue(FadeOutDurationProperty); }
set { SetValue(FadeOutDurationProperty, value); }
}

static Blink() {
// register dependency properties
OffDurationProperty = DependencyProperty.Register("OffDuration", typeof(double), typeof(Blink), new UIPropertyMetadata(1.0));
OnDurationProperty
= DependencyProperty.Register("OnDuration", typeof(double), typeof(Blink), new UIPropertyMetadata(1.0));
FadeInDurationProperty
= DependencyProperty.Register("FadeInDuration", typeof(double), typeof(Blink), new UIPropertyMetadata(0.2));
FadeOutDurationProperty
= DependencyProperty.Register("FadeOutDuration", typeof(double), typeof(Blink), new UIPropertyMetadata(0.5));
}
thing to animate is UIElement.OpacityProperty. So that's what I'm using, and to avoid a lot of fuzz with StoryBoards and stuff I set up the animation with the help of a DoubleAnimationUsingKeyFrames.




// setup the animation
DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
animation.RepeatBehavior
= RepeatBehavior.Forever;

double currentSeconds = 0; // keep track of cumulated time
LinearDoubleKeyFrame start = new LinearDoubleKeyFrame(0,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(
0)));
animation.KeyFrames.Add(start);

currentSeconds
+= FadeInDuration;
LinearDoubleKeyFrame fadeInFrame
= new LinearDoubleKeyFrame(1,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(currentSeconds)));
animation.KeyFrames.Add(fadeInFrame);

currentSeconds
+= OnDuration;
LinearDoubleKeyFrame onFrame
= new LinearDoubleKeyFrame(1,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(currentSeconds)));
animation.KeyFrames.Add(onFrame);

currentSeconds
+= FadeOutDuration;
LinearDoubleKeyFrame fadeOutFrame
= new LinearDoubleKeyFrame(0,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(currentSeconds)));
animation.KeyFrames.Add(fadeOutFrame);

currentSeconds
+= OffDuration;
LinearDoubleKeyFrame offFrame
= new LinearDoubleKeyFrame(0,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(currentSeconds)));
animation.KeyFrames.Add(offFrame);

Child.BeginAnimation(UIElement.OpacityProperty, animation);



And here is the whole Blink.cs in its entirety once again:




using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;


namespace BlinkTest {
[ContentProperty(
"Child")]
public class Blink : Control {
UIElement m_child;

public UIElement Child {
get { return m_child; }
set {
if (m_child != null) {
RemoveVisualChild(m_child);
RemoveLogicalChild(m_child);
}
if ((m_child = value) != null) {
AddVisualChild(m_child);
AddLogicalChild(m_child);

// setup the animation
DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
animation.RepeatBehavior
= RepeatBehavior.Forever;

double currentSeconds = 0; // keep track of cumulated time
LinearDoubleKeyFrame start = new LinearDoubleKeyFrame(0,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(
0)));
animation.KeyFrames.Add(start);

currentSeconds
+= FadeInDuration;
LinearDoubleKeyFrame fadeInFrame
= new LinearDoubleKeyFrame(1,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(currentSeconds)));
animation.KeyFrames.Add(fadeInFrame);

currentSeconds
+= OnDuration;
LinearDoubleKeyFrame onFrame
= new LinearDoubleKeyFrame(1,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(currentSeconds)));
animation.KeyFrames.Add(onFrame);

currentSeconds
+= FadeOutDuration;
LinearDoubleKeyFrame fadeOutFrame
= new LinearDoubleKeyFrame(0,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(currentSeconds)));
animation.KeyFrames.Add(fadeOutFrame);

currentSeconds
+= OffDuration;
LinearDoubleKeyFrame offFrame
= new LinearDoubleKeyFrame(0,
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(currentSeconds)));
animation.KeyFrames.Add(offFrame);

Child.BeginAnimation(UIElement.OpacityProperty, animation);
}
}
}

protected override int VisualChildrenCount {
get { return Child != null ? 1 : 0; }
}

protected override Visual GetVisualChild(int index) {
if (index > 0 || Child == null) throw new ArgumentException("index");
return Child;
}

protected override Size MeasureOverride(Size constraint) {
Size sizeDesired
= new Size(0, 0);
if (Child != null) {
Child.Measure(constraint);
}
sizeDesired.Width
+= Child.DesiredSize.Width;
sizeDesired.Height
+= Child.DesiredSize.Height;

return sizeDesired;
}

protected override Size ArrangeOverride(Size arrangeBounds) {
if (Child != null) {
Rect rect
= new Rect(
new Point((arrangeBounds.Width - Child.DesiredSize.Width) / 2,
(arrangeBounds.Height
- Child.DesiredSize.Height) / 2),
Child.DesiredSize);
Child.Arrange(rect);
}
return arrangeBounds;
}

// Using a DependencyProperty as the backing store for OffDuration. This enables animation, styling, binding, etc...
public static readonly DependencyProperty OffDurationProperty;

// Using a DependencyProperty as the backing store for OnDuration. This enables animation, styling, binding, etc...
public static readonly DependencyProperty OnDurationProperty;

// Using a DependencyProperty as the backing store for RiseDuration. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FadeInDurationProperty;

// Using a DependencyProperty as the backing store for DeclineDuration. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FadeOutDurationProperty;

public double OnDuration {
get { return (double)GetValue(OnDurationProperty); }
set { SetValue(OnDurationProperty, value); }
}

public double OffDuration {
get { return (double)GetValue(OffDurationProperty); }
set { SetValue(OffDurationProperty, value); }
}

public double FadeInDuration {
get { return (double)GetValue(FadeInDurationProperty); }
set { SetValue(FadeInDurationProperty, value); }
}

public double FadeOutDuration {
get { return (double)GetValue(FadeOutDurationProperty); }
set { SetValue(FadeOutDurationProperty, value); }
}

static Blink() {
// register dependency properties
OffDurationProperty = DependencyProperty.Register("OffDuration", typeof(double), typeof(Blink), new UIPropertyMetadata(1.0));
OnDurationProperty
= DependencyProperty.Register("OnDuration", typeof(double), typeof(Blink), new UIPropertyMetadata(1.0));
FadeInDurationProperty
= DependencyProperty.Register("FadeInDuration", typeof(double), typeof(Blink), new UIPropertyMetadata(0.2));
FadeOutDurationProperty
= DependencyProperty.Register("FadeOutDuration", typeof(double), typeof(Blink), new UIPropertyMetadata(0.5));
}
}
}


The code was developed on Vista using the RC1 bits of the .NET 3.0 SDK



Technorati tags: ,

Thursday, September 28, 2006

Windows Live Writer - I18N not complete

After performing the usual* test when getting a System.FormatException it seems that the I18n has not yet been done properly in Windows Live Writer. Basically (it seems like) the code assumes . (dot) as a decimal separator somewhere, but gets a , (comma) since the Swedish (Finland) locale (sv-FI) uses comma as decimal separator.

Workaround: Change the decimal separator to a dot.

Usual test: Change the regional settings to use English (United States)

 

Technorati tags:

Hello World from Windows Live Writer

After installing the latest version of Windows Live Writer and applying the workaround for beta.blogger I'm now successfully posting from Windows Live Writer running on Vista x64 (5728)

Technorati tags: ,

Update: Did not work on first try...

 

System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str
, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseDouble(String value
, NumberStyles options, NumberFormatInfo numfmt)
at System.Double.Parse(String s
, NumberStyles style, NumberFormatInfo info)
at WindowsLive.Writer.BlogClient.Clients.AtomClient.ParseRfc3339(String dateTimeString)
at WindowsLive.Writer.BlogClient.Clients.AtomClient.Date(XmlNode node
, String xpath, DateTime defaultValue)
at WindowsLive.Writer.BlogClient.Clients.AtomClient.Parse(XmlElement entryNode)
at WindowsLive.Writer.BlogClient.Clients.AtomClient.NewPost(String blogId
, BlogPost post, Boolean publish)
at WindowsLive.Writer.BlogClient.Blog.NewPost(BlogPost post
, Boolean publish)
at WindowsLive.Writer.PostEditor.UpdateWeblogAsyncOperation.DoWork()

Saturday, September 23, 2006

Joke of the day

The potential effect of the recent (laptop) battery recalls is a brilliant topic for a comic

Monday, September 18, 2006

xcopy deployment deprecated

(Spotted at Channel9)

It seems that xcopy deployment just got deprecated:

>xcopy /?
Copies files and directory trees.

NOTE: Xcopy is now deprecated, please use Robocopy.


Robocopy shows:

>robocopy /?
------------------------------------------------------------------------------- ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------


So I guess that's the end of xcopy deployment and beginning of robocopy deployment, (or are they pushing ClickOnce deployment all the way?)

Tuesday, September 12, 2006

Oh the joys of UAC (NOT)

Tried to do a little bughunting on a WCF project, the problem specifically related to dual bindings. However, I did not get so far, since I soon found out through "trial and horror" that in Vista you are not allowed to bind to a port unless running under elevated privileges.

Yes, UAC strikes once again!

I soon found out that this is a known issue and how you should work around it. Basically you add a manifest to the exe requesting elevated privileges.




<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestversion="1.0">
<trustinfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedprivileges>
<requestedexecutionlevel level="requireAdministrator">
</requestedprivileges>
</security>
</trustinfo>
</assembly>


However, I couldn't get this working under a debugger !?! (The manifest is there as both exename.exe.manifest and exename.vshost.exe.manifest)

So, how is one supposed to debug a WCF server on Vista !?!

Monday, September 11, 2006

Uninstalling Google Toolbar on Vista

I recently installed Google toolbar to get "BlogThis" functionality. Alas, I soon discovered that as I use the new beta blogger, this functionality is not supported in the current version of the toolbar :( However, more annoyingly, the toolbar seems to break the right-click context menu..

So I wanted to get rid of the toolbar as soon as possible (at least for the time being).

Now comes the big problem, the thing won't let me uninstall it, complaining about unsufficient permissions, yada yada. Basically because of UAC even though you have admin privileges you are not running with them all of the time. A properly configured installer will ask for elevated privileges, but it seems the Toolbar installer is not clever enough to do this..

So here's how you do it:
Right-click IE icon, choose "Run as Administrator", and then proceed to uninstalling the toolbar. Needless to say, it is probably safest to not go around surfing the 'net as Administrator...

Sunday, September 10, 2006

Playing around in WPF land

With a little (ok, a lot of) help from Josh Smith and Karsten Januszewski/Andrew Whiddett I managed to put together a little ComicBook application that utilizes Asynchronous databinding, animated image transitions. It's not quite finished yet, but the parts that are left should mostly be a walk in the park (i.e. known territory). Not bad for an evenings worth of work, considering this is my first "real" WPF application.

The learning curve is steep...

I probably post more technical stuff when I get it closer to what I want it to be.

Friday, September 08, 2006

Joke of the day

Ok, I admit I'm a little bit late, but I found this (Userfriendly) comic quite amusing. :-) 

Thursday, September 07, 2006

Developing WCF without Orcas CTP

For various reasons I installed the .NET 3.0 RC1 Runtime/SDK as soon as they were available. This meant that I didn't have a CTP of Orcas to go with it. As I currently don't have any WPF stuff to do I figured I'd manage just as fine without it.

However, when I started a new project using WCF it got interesting, I could build already made WCF projects, but System.ServiceModel (and System.Runtime.Serialization for that matter) was nowhere to be found in the Add reference... dialog.

As I also do fiddle around with msbuild stuff I figured that I could work around this quite easily by firing up the project xml file (right-click the project, choose Unload project, right-click the unloaded project, choose Edit .csproj, Edit away..., then right-click project, Reload project)

and add the missing reference to the project by hand

<Reference Include="System.ServiceModel" />

Still, I thought it was kinda funny that the workaround was needed.


EDIT: This is not an issue anymore since Orcas CTP for RC1 has been released.

Scoping issues in C#

Came across some "interesting" scoping rules of C# at work today.Consider the following:

try {
int answer = 42;
} catch {
// ...
}
int answer = 42;

This one errors out with the somewhat curious error message:
Error 1 A local variable named 'answer' cannot be declared in this scope because it would give a different meaning to 'answer', which is already used in a 'child' scope to denote something else C:\Path\To\File.cs 15 17 TheProject

Out of curiosity we tried the following:

try {
int answer = 42;
} catch {
// ...
}
answer = 42;


This (rightfully IMO) errors out in the following way (the same thing happens by the way if the second assignment is within the catch block):
Error 1 The name 'answer' does not exist in the current context C:\Path\To\File.cs 15 13 TheProject

Saturday, September 02, 2006

Vista RC1 is out

As Vista RC1 was released to β testers yesterday. I naturally had to get it installed right away, so currently AllThingsMedia is happily running Vista x64 build 5600. Expect a more general release of the RC1 sometime next week..