Friday, 8 October 2010

Postgresql - SELECT FOR UPDATE example

The Postgresql documentation says:
FOR UPDATE causes the rows retrieved by the SELECT statement to be locked as though for update. This prevents them from being modified or deleted by other transactions until the current transaction ends. That is, other transactions that attempt UPDATE, DELETE, or SELECT FOR UPDATE of these rows will be blocked until the current transaction ends.
Let's see a little and easy example just to verify if this is true or not :-)

First consider this table (very very simple):
   1 CREATE TABLE "public"."example" (
2 "id" INTEGER
3 ) WITHOUT OIDS;

Now insert just one row inside this table, then use this script to create a pl/pgsql function that will act as a transaction (stored functions always run in a transaction) in our example:
   1 CREATE OR REPLACE FUNCTION "public"."for_update_test" (
2 )
3 RETURNS integer AS
4 $body$
5 DECLARE
6
7 id_query INTEGER;
8
9 BEGIN
10
11 RAISE NOTICE 'START AT: %',timeofday()::timestamp;
12
13 SELECT id FROM example LIMIT 1 INTO id_query FOR UPDATE;
14
15 RAISE NOTICE 'SELECT PERFORMED AT: %',timeofday()::timestamp;
16
17 PERFORM pg_sleep(50);
18
19 RAISE NOTICE 'END AT: %',timeofday()::timestamp;
20
21 RETURN 0;
22 END;
23 $body$
24 LANGUAGE 'plpgsql'
25 VOLATILE
26 CALLED ON NULL INPUT
27 SECURITY INVOKER
28 COST 100;

Then run the function with Select for_update_test(); inside a SQL prompt of pgAdminIII or any other environment.

After something like 25 seconds make another Select for_update_test(); in a second prompt as I did in the following:

(Please click on the image to see full size)

In the left prompt you can see that the SELECT FOR UPDATE is immediately performed after the transaction begins.

In the right prompt you can see that the SELECT FOR UPDATE is performed only after the first transaction ends.

So, actually the SELECT FOR UPDATE locks the only row of our table.

If you want you can change the SELECT FOR UPDATE adding the NOWAIT clause:
SELECT id FROM example LIMIT 1 INTO id_query FOR UPDATE NOWAIT;
and run the small experiment again. In this case the second function call will return an error because the NOWAIT clause does exactly what its name suggests: it doesn't wait if it encounters a locked row.

In the function I used the instruction timeofday()::timestamp because the NOW() function or the statement CURRENT_TIMESTAMP always return the same Date Time if used inside a transaction. More on this here http://kaiv.wordpress.com/2007/11/02/getting-current-time-inside-a-transaction/

Thursday, 7 October 2010

System.Threading.Timer and Garbage Collector

I would like to tell you the problem i ran into some time ago with the System.Threading.Timer.

I used this Timer in a software where periodically i have to retrieve data from one or more solar inverters by a serial port.

Well, at first I declared and initialized the timer in a method (the constructor but this is not relevant), so i wrote something like this:

System.Threading.Timer Tim = new System.Threading.Timer(CallbackMethod, null, 0, Milliseconds);

My program started to have a strange problem. When I ran the software it suddenly stops after a while without raising any exception and without crashing.

For a lot of time i was sure that the problem was in the callback, the place where i ask data to the inverter.

But the problem was not there. At the end i read on msdn:

Note

As long as you are using a Timer, you must keep a reference to it. As with any managed object,
a Timer is subject to garbage collection when there are no references to it. The fact that a Timer
is still active does not prevent it from being collected.


So the solution is to declare the Timer outside the method, in the same class or as a static object somewhere else. The important thing is that the Timer object does not go out of scope, otherwise the Garbage collector will remove it from the memory.

This explains also why the program wasn't raising any exception. The callback never references the Timer in no way so it just was not executed.

Sunday, 3 October 2010

How to enable wcf messages compression in Silverlight (4) and IIS 7

There are many tutorials that explain how to do this. But these are very comprehensive for
the many platforms that can be envolved.

Here i will talk only about my particular situation:

  • Silverlight 4
  • A Wcf Service with the default visual studio 2010 binding configuration:
   1 <configuration>
2 <system.serviceModel>
3 <bindings>
4 <customBinding>
5 <binding name="CustomBinding_ServizioVisualizzatore" >
6 <binaryMessageEncoding />
7 <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
8 </binding>
9 </customBinding>
10 </bindings>
11 <client>
12 <endpoint address="http://localhost:4534/Visualizzatore.Web/ServizioVisualizzatore.svc"
13 binding="customBinding" bindingConfiguration="CustomBinding_ServizioVisualizzatore"
14 contract="Servizio.ServizioVisualizzatore" name="CustomBinding_ServizioVisualizzatore" />
15 </client>
16 </system.serviceModel>
17 </configuration>

  • IIS 7 on Windows Server 2008 32 bit
Let's begin! First of all you won't have to touch your code, everything is done with one or two settings inside IIS.

IIS will send the data you asked to it( making a call to the web service) to the client in gzip format if the client says that it can manage compressed responses.

How can we see if our client Silverlight application is 'happy' to receive a gzipped response?
Well, let's install Fiddler and have a look at the http request of the service call:

(Please click on the image to see full size)
In the Request headers of the wcf call you can read 'Accept encoding: gzip, deflate'.
It means that the client is saying that it can accept a compressed response.
Below you can see (Transformer tab of the http responses pane) that the content of the response is actually gzipped as we desire.

The last thing to note is the Content-Type of our http request. It is set to 'application/soap+msbin1', we'll use it later.

Now, it's time to set some options within IIS 7:

(Please click on the image to see full size)

The screenshot (Italian language) shows the icon that you should press to open the section where you can enable static and dynamic contents compression.

After this you should open the IIS applicationhost.config file. You should find it in the 'C:\Windows\System32\inetsrv\config' directory.
Here you can add the line '' (please note "application/soap+msbin1") in the httpCompression - dynamicTypes section of the file obtaining something similar to this:
   1 <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
2 <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
3 <dynamicTypes>
4 <add mimeType="text/*" enabled="true" />
5 <add mimeType="message/*" enabled="true" />
6 <add mimeType="application/x-javascript" enabled="true" />
7 <add mimeType="application/soap+msbin1" enabled="true" />
8 <add mimeType="*/*" enabled="false" />
9 </dynamicTypes>
10 <staticTypes>
11 <add mimeType="text/*" enabled="true" />
12 <add mimeType="message/*" enabled="true" />
13 <add mimeType="application/javascript" enabled="true" />
14 <add mimeType="*/*" enabled="false" />
15 </staticTypes>
16 </httpCompression>

Now it should be all done :-). Alternatively you could also set <add mimeType="*/*" enabled="true" /> to enable compression for all kinds of content.

Thursday, 3 June 2010

Setting a breakpoint in Windbg at the beginning of the Main method of a .Net application

I thought it was easy to set a breakpoint at the beginning of the main method of a .net application.

Indeed it is not trivial and since i was in troubles, as usual, i started to dig the Internet for a help.

I found these 2 articles:
http://blogs.msdn.com/b/tess/archive/2008/06/05/setting-net-breakpoints-in-windbg-for-applications-that-crash-on-startup.aspx
and
http://blogs.msdn.com/b/mahuja/archive/2008/07/16/managed-debugging-and-inspecting-jitted-code-with-windbg.aspx

The first is by Tess Ferrandez, author of many excellent posts about the debugging of .net applications.
Unfortunately I was not able to set a breakpoint on the main method with that tecnique.It's almost sure that I'm doing something wrong since Ferrandez's experience is by far greater than mine :-) .

The second article allowed me to do what i wanted to do. The article is by Madhur.

I strongly suggest to read that article!

The only thing I can say is that it' not mandatory to follow all the steps described there.

I managed to obtain the result in this way:

1) Open Windbg.

2) Open the executable (Ctrl+E and search the .exe).

3) at the prompt type 'sxe ld:mscorjit'
this is the key of Madhur's article and tells to Windbg to set a breakpoint as soon the the jitting engine (mscorjit.dll) is loaded into memory.

4) than type 'g' to let go the Application since the breakpoint is hit.

5) type '.loadby sos mscorwks' to load the sos extension necessary to use a command of the next.

6) type '.sympath srv*;C:\Projects\ApplicationTest\ApplicationTest\bin\Debug' (changing the path accordingly with the one of your application) and then '.reload' to make the symbols informations available to the debugger.

7) type '!name2ee ApplicationTest ApplicationTest.Program.Main' changing ApplicationTest with the name of the module of your application. This command will tell you that the Main method has not been Jiited yet and to use '!bpmd -md' + the suggested method descriptor to set the desired breakpoint.

8) type the !bpmd command and then type 'g' and wait for the breakpoint being hit.

At this point the execution stops at the beginning of the main method and you can confirm this typing the command 'clrstack -a'.

What follows is the Windbg debugging session text:
   1 CommandLine: C:\Projects\ApplicationTest\ApplicationTest\bin\Debug\ApplicationTest.exe
2 Symbol search path is: srv*;C:\Projects\ApplicationTest\ApplicationTest\bin\Debug
3 Executable search path is:
4 (1568.1078): Break instruction exception - code 80000003 (first chance)
5 eax=00000000 ebx=00000000 ecx=003cf618 edx=779a64f4 esi=fffffffe edi=00000000
6 eip=779fe60e esp=003cf634 ebp=003cf660 iopl=0 nv up ei pl zr na pe nc
7 cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
8 ntdll!LdrpDoDebuggerBreak+0x2c:
9 779fe60e cc int 3
10 0:000> sxe ld:mscorjit
11 0:000> g
12 ModLoad: 72470000 724cb000 C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll
13 eax=6fe74bb8 ebx=00000000 ecx=00252ffc edx=000e0e3c esi=7ffdf000 edi=003ce500
14 eip=779a64f4 esp=003ce418 ebp=003ce46c iopl=0 nv up ei pl zr na pe nc
15 cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
16 ntdll!KiFastSystemCallRet:
17 779a64f4 c3 ret
18 0:000> .loadby sos mscorwks
19 0:000> .sympath srv*;C:\Projects\ApplicationTest\ApplicationTest\bin\Debug
20 Symbol search path is: srv*;C:\Projects\ApplicationTest\ApplicationTest\bin\Debug
21 Expanded Symbol search path is: cache*;SRV*http://msdl.microsoft.com/download/symbols;c:\projects\applicationtest\applicationtest\bin\debug
22 0:000> .reload
23 Reloading current modules
24 .........................
25 0:000> !name2ee ApplicationTest ApplicationTest.Program.Main
26 Module: 00252c5c (ApplicationTest.exe)
27 Token: 0x06000001
28 MethodDesc: 00252ffc
29 Name: ApplicationTest.Program.Main(System.String[])
30 Not JITTED yet. Use !bpmd -md 00252ffc to break on run.
31 0:000> !bpmd -md 00252ffc
32 MethodDesc = 00252ffc
33 Adding pending breakpoints...
34 0:000> g
35 (1568.1078): CLR notification exception - code e0444143 (first chance)
36 JITTED ApplicationTest!ApplicationTest.Program.Main(System.String[])
37 Setting breakpoint: bp 004C0070 [ApplicationTest.Program.Main(System.String[])]
38 Breakpoint 0 hit
39 eax=00252ffc ebx=003cef6c ecx=018d8fac edx=00000000 esi=000c6fb8 edi=00000000
40 eip=004c0070 esp=003cef44 ebp=003cef50 iopl=0 nv up ei pl nz ac po nc
41 cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000212
42 004c0070 55 push ebp
43 0:000> !clrstack -a
44 OS Thread Id: 0x1078 (0)
45 ESP EIP
46 003cef44 004c0070 ApplicationTest.Program.Main(System.String[])
47 PARAMETERS:
48 args = 0x018d8fac
49 LOCALS:
50 <no data>
51 <no data>
52 <no data>
53
54 003cf15c 6f931b6c [GCFrame: 003cf15c]
58


Monday, 31 May 2010

Simple animation sequences for Silverlight charts

In this post I would like to show a simple way to obtain an animation sequence when you load the ItemsSource of a Serie of a Chart in Silverlight (Toolkit April 2010).

I know that is available the AnimationSequence property but so far I couldn't make it work for all kinds of Series.
For example with the AreaSerie i have not been successful and it seems that I'm not the only one (http://betaforums.silverlight.net/forums/p/183878/418187.aspx#418187).

Now I'm gonna show how I changed the template of the AreaSeries to obtain our loading animations.

First of all let's see the xaml of the Usercontrol hosting the chart:
   1 <UserControl x:Class="XamlChart.MainPage"
   2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   5     xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
   6     xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
   7     xmlns:my="clr-namespace:XamlChart"
   8     mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
   9     <UserControl.Resources>
  10         <my:ChartConverter x:Key="ChartConverter"/>
  11     </UserControl.Resources>
  12     <Grid x:Name="LayoutRoot">
  13         <charting:Chart Title="My Chart"  LegendTitle="Legend">
  14             <charting:AreaSeries Title="Series 1" DependentValueBinding="{Binding y, Converter={StaticResource ChartConverter}}"
  15                 IndependentValueBinding="{Binding x, Converter={StaticResource ChartConverter}}" 
  16                 Style="{StaticResource MySerieStyle}"  >
  17                 <charting:AreaSeries.ItemsSource>
  18                     <controls:ObjectCollection>
  19                         <my:MyPoint x="5" y="6"/>
  20                         <my:MyPoint x="6" y="7"/>
  21                         <my:MyPoint x="7" y="5.3"/>
  22                         <my:MyPoint x="8" y="9"/>
  23                     </controls:ObjectCollection>
  24                 </charting:AreaSeries.ItemsSource>
  25             </charting:AreaSeries>
  26             <charting:Chart.Axes>
  27                 <charting:LinearAxis Orientation="X" Title="X Axis" Location="Bottom"></charting:LinearAxis>
  28                 <charting:LinearAxis Orientation="Y" Title="Y Axis" Location="Left" ShowGridLines="True" ></charting:LinearAxis>
  29             </charting:Chart.Axes>
  30         </charting:Chart>
  31     </Grid>
  32 </UserControl>

Here We can see at line 16: Style="{StaticResource MySerieStyle}".

With this line We say that the new Template for our Serie has 'MySerieStyle' as key.

The Template is defined in another file called 'ResourceDictionary1.xaml'.
The link between our UserControl and the 'ResourceDictionary1.xaml' file is in the App.xaml file:
 1 <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 2              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 3              x:Class="XamlChart.App"
 4              >
 5     <Application.Resources>
 6         <ResourceDictionary>
 7                 <ResourceDictionary.MergedDictionaries>
 8                         <ResourceDictionary Source="ResourceDictionary1.xaml"/>
 9                 </ResourceDictionary.MergedDictionaries>
10         </ResourceDictionary>
11     </Application.Resources>
12 </Application>

Now We can look at the Template defined in the ResourceDictionary1.xaml file:
   1 <ResourceDictionary
   2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   4     xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
   5     xmlns:visualizationToolkit="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
   6     xmlns:System_Windows_Controls_DataVisualization_Charting_Primitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"
   7     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
   8     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
   9 
  10     <Style x:Key="MySerieStyle" TargetType="chartingToolkit:AreaSeries">
  11                 <Setter Property="IsTabStop" Value="False"/>
  12                 <Setter Property="PathStyle">
  13                         <Setter.Value>
  14                                 <Style TargetType="Path">
  15                                         <Setter Property="Opacity" Value="1"/>
  16                                 </Style>
  17                         </Setter.Value>
  18                 </Setter>
  19                 <Setter Property="Template">
  20                         <Setter.Value>
  21                                 <ControlTemplate TargetType="chartingToolkit:AreaSeries">
  22                                         <Canvas x:Name="PlotArea">
  23                                                 <Canvas.OpacityMask>
  24                             <LinearGradientBrush StartPoint="0,0" EndPoint="1,0" >
  25                                                                 <LinearGradientBrush.Transform>
  26                                                                         <RotateTransform Angle="0" />
  27                                                                 </LinearGradientBrush.Transform>
  28                                 <GradientStop Color="Black" Offset="0"/>
  29                                 <GradientStop x:Name="ColorStop" Color="Black" Offset="0"  />
  30                                 <GradientStop x:Name="ColorStop2" Color="Transparent" Offset="0.1"  />
  31                                 <GradientStop Color="Transparent" Offset="1"/>
  32                             </LinearGradientBrush>
  33                         </Canvas.OpacityMask>
  34                         <Canvas.Triggers>
  35                             <EventTrigger>
  36                                 <BeginStoryboard>
  37                                         <Storyboard x:Name="storyboard">
  38                                                 <DoubleAnimation
  39                                                         Storyboard.TargetName="ColorStop" Storyboard.TargetProperty="Offset"
  40                                                         From="0" To="1" Duration="0:0:4" BeginTime="00:00:00"  />
  41                                                 <DoubleAnimation
  42                                                         Storyboard.TargetName="ColorStop2" Storyboard.TargetProperty="Offset"
  43                                                         From="0.1" To="1" Duration="0:0:4" BeginTime="00:00:00"  />
  44                                         </Storyboard>
  45                                 </BeginStoryboard>
  46                             </EventTrigger>
  47                         </Canvas.Triggers>
  48                                                 <Path Fill="{TemplateBinding Background}"  Data="{TemplateBinding Geometry}" Style="{TemplateBinding PathStyle}"/>
  49                                         </Canvas>
  50                                 </ControlTemplate>
  51                         </Setter.Value>
  52                 </Setter>
  53         </Style>
  54     

I modified the Default Template of the AreaSeries.

As usual you can obtain the default one with Expression Blend right clicking the AreaSerie of the Chart and then doing Edit Template > Edit a Copy or examing the System.Windows.Controls.DataVisualization.Toolkit dll with Reflector as in the following snapshot:

The main idea is to use a LinearGradientBrush and a StoryBoard with two (or more) animations to move the GradientStops in the desired direction and speed.

The 'LinearGradientBrush.Transform' at line 25 is not mandatory here (note Angle="0") but I used it for other kind of animation as this one that shows the AreaSerie from the bottom up:
   1 <Style x:Key="AreaSeriesBottomUp" TargetType="chartingToolkit:AreaSeries">
   2                 <Setter Property="IsTabStop" Value="False"/>
   3                 <Setter Property="PathStyle">
   4                         <Setter.Value>
   5                                 <Style TargetType="Path">
   6                                         <Setter Property="Opacity" Value="1"/>
   7                                 </Style>
   8                         </Setter.Value>
   9                 </Setter>
  10                 <Setter Property="Template">
  11                         <Setter.Value>
  12                                 <ControlTemplate TargetType="chartingToolkit:AreaSeries">
  13                                         <Canvas x:Name="PlotArea">
  14                                                 <Canvas.OpacityMask>
  15                             <LinearGradientBrush StartPoint="1,0" EndPoint="0,0" >
  16                                                                 <LinearGradientBrush.Transform>
  17                                                                         <RotateTransform Angle="90" />
  18                                                                 </LinearGradientBrush.Transform>
  19                                 <GradientStop Color="Black" Offset="0"/>
  20                                 <GradientStop x:Name="ColorStop" Color="Black" Offset="0"  />
  21                                 <GradientStop x:Name="ColorStop2" Color="Transparent" Offset="0.1"  />
  22                                 <GradientStop Color="Transparent" Offset="1"/>
  23                             </LinearGradientBrush>
  24                         </Canvas.OpacityMask>
  25                         <Canvas.Triggers>
  26                             <EventTrigger>
  27                                 <BeginStoryboard>
  28                                         <Storyboard x:Name="storyboard">
  29                                                 <DoubleAnimation
  30                                                         Storyboard.TargetName="ColorStop" Storyboard.TargetProperty="Offset"
  31                                                         From="0" To="1" Duration="0:0:4" BeginTime="00:00:00"  />
  32                                                 <DoubleAnimation
  33                                                         Storyboard.TargetName="ColorStop2" Storyboard.TargetProperty="Offset"
  34                                                         From="0.1" To="1" Duration="0:0:4" BeginTime="00:00:00"  />
  35                                         </Storyboard>
  36                                 </BeginStoryboard>
  37                             </EventTrigger>
  38                         </Canvas.Triggers>
  39                                                 <Path Fill="{TemplateBinding Background}"  Data="{TemplateBinding Geometry}" Style="{TemplateBinding PathStyle}"/>
  40                                         </Canvas>
  41                                 </ControlTemplate>
  42                         </Setter.Value>
  43                 </Setter>
  44         </Style>

The last one animation shows the Area from the center to both the sides of the Area itself. Here I used two more GradientStops and two more Animations than before:
   1 <Style x:Key="AreaSeriesCenterSides" TargetType="chartingToolkit:AreaSeries">
   2                 <Setter Property="IsTabStop" Value="False"/>
   3                 <Setter Property="PathStyle">
   4                         <Setter.Value>
   5                                 <Style TargetType="Path">
   6                                         <Setter Property="Opacity" Value="1"/>
   7                                 </Style>
   8                         </Setter.Value>
   9                 </Setter>
  10                 <Setter Property="Template">
  11                         <Setter.Value>
  12                                 <ControlTemplate TargetType="chartingToolkit:AreaSeries">
  13                                         <Canvas x:Name="PlotArea">
  14                                                 <Canvas.OpacityMask>
  15                             <LinearGradientBrush StartPoint="0,0" EndPoint="1,0" >
  16                                                                 <LinearGradientBrush.Transform>
  17                                                                         <RotateTransform Angle="0" />
  18                                                                 </LinearGradientBrush.Transform>
  19                                 <GradientStop Color="Transparent" Offset="0"/>
  20                                 <GradientStop x:Name="ColorStop3" Color="Transparent" Offset="0.4"  />
  21                                 <GradientStop x:Name="ColorStop" Color="Black" Offset="0.5"   />
  22                                 <GradientStop x:Name="ColorStop2" Color="Black" Offset="0.5"  />                                                        
  23                                 <GradientStop x:Name="ColorStop4" Color="Transparent" Offset="0.6"  />
  24                                 <GradientStop Color="Transparent" Offset="1"/>
  25                             </LinearGradientBrush>
  26                         </Canvas.OpacityMask>
  27                         <Canvas.Triggers>
  28                             <EventTrigger>
  29                                 <BeginStoryboard>
  30                                         <Storyboard x:Name="storyboard">
  31                                                 <DoubleAnimation
  32                                                         Storyboard.TargetName="ColorStop" Storyboard.TargetProperty="Offset"
  33                                                         From="0.5" To="0" Duration="0:0:4" BeginTime="00:00:00"  />
  34                                                 <DoubleAnimation
  35                                                         Storyboard.TargetName="ColorStop2" Storyboard.TargetProperty="Offset"
  36                                                         From="0.5" To="1" Duration="0:0:4" BeginTime="00:00:00"  />
  37                                                                                 <DoubleAnimation
  38                                                         Storyboard.TargetName="ColorStop3" Storyboard.TargetProperty="Offset"
  39                                                         From="0.4" To="0" Duration="0:0:4" BeginTime="00:00:00"  />
  40                                                 <DoubleAnimation
  41                                                         Storyboard.TargetName="ColorStop4" Storyboard.TargetProperty="Offset"
  42                                                         From="0.6" To="1" Duration="0:0:4" BeginTime="00:00:00"  />
  43                                         </Storyboard>
  44                                 </BeginStoryboard>
  45                             </EventTrigger>
  46                         </Canvas.Triggers>
  47                                                 <Path Fill="{TemplateBinding Background}"  Data="{TemplateBinding Geometry}" Style="{TemplateBinding PathStyle}"/>
  48                                         </Canvas>
  49                                 </ControlTemplate>
  50                         </Setter.Value>
  51                 </Setter>
  52         </Style>

The same effects just seen can be used with the other Series, for example we can look at the last animation seen applied to the ColumnSeries:
   1 <Style x:Key="ColumnSeriesStyle1" TargetType="chartingToolkit:ColumnSeries">
   2                 <Setter Property="IsTabStop" Value="False"/>
   3                 <Setter Property="Template">
   4                         <Setter.Value>
   5                                 <ControlTemplate TargetType="chartingToolkit:ColumnSeries">
   6                     <Canvas x:Name="PlotArea">
   7                         <Canvas.OpacityMask>
   8                             <LinearGradientBrush StartPoint="0,0" EndPoint="1,0" >
   9                                 <LinearGradientBrush.Transform>
  10                                     <RotateTransform Angle="0" />
  11                                 </LinearGradientBrush.Transform>
  12                                 <GradientStop Color="Transparent" Offset="0"/>
  13                                 <GradientStop x:Name="ColorStop3" Color="Transparent" Offset="0.4"  />
  14                                 <GradientStop x:Name="ColorStop" Color="Black" Offset="0.5"   />
  15                                 <GradientStop x:Name="ColorStop2" Color="Black" Offset="0.5"  />
  16                                 <GradientStop x:Name="ColorStop4" Color="Transparent" Offset="0.6"  />
  17                                 <GradientStop Color="Transparent" Offset="1"/>
  18                             </LinearGradientBrush>
  19                         </Canvas.OpacityMask>
  20                         <Canvas.Triggers>
  21                             <EventTrigger>
  22                                 <BeginStoryboard>
  23                                     <Storyboard x:Name="storyboard">
  24                                         <DoubleAnimation
  25                                                         Storyboard.TargetName="ColorStop" Storyboard.TargetProperty="Offset"
  26                                                         From="0.5" To="0" Duration="0:0:4" BeginTime="00:00:00"  />
  27                                         <DoubleAnimation
  28                                                         Storyboard.TargetName="ColorStop2" Storyboard.TargetProperty="Offset"
  29                                                         From="0.5" To="1" Duration="0:0:4" BeginTime="00:00:00"  />
  30                                         <DoubleAnimation
  31                                                         Storyboard.TargetName="ColorStop3" Storyboard.TargetProperty="Offset"
  32                                                         From="0.4" To="0" Duration="0:0:4" BeginTime="00:00:00"  />
  33                                         <DoubleAnimation
  34                                                         Storyboard.TargetName="ColorStop4" Storyboard.TargetProperty="Offset"
  35                                                         From="0.6" To="1" Duration="0:0:4" BeginTime="00:00:00"  />
  36                                     </Storyboard>
  37                                 </BeginStoryboard>
  38                             </EventTrigger>
  39                         </Canvas.Triggers>
  40                     </Canvas>
  41                 </ControlTemplate>
  42                         </Setter.Value>
  43                 </Setter>
  44         </Style>