Posted by mehfuzh on Mar 30, 2009 in
C & C++,
C#,
Dotnet |
View Original Article
In this post, i will show how you can generate SQL programmatically from M. Now, so far i have learnt that MGrammer is a contract that converts user’s input into MGraph. Now, Oslo by default comes with MSchema. Through MSchema you can define a type and extend it with MGraph to populate your repository. Here, i will use MSchema to define an entity object , then MGraph and finally run this through a custom SQL generator in C# to get my DDL statement similar to what you can generate by using intellipad that comes with Oslo SDK.
Let’s define a Contacts M
module Contacts {
type Person {
Id : Integer32;
Name: Text;
Age: Integer32;
} where identity Id;
People : Person*
{
{Id = 1, Name="Steve",Age=36},
{Id = 2, Name="Kazi",Age=30}
};
Employee : Person*
{
{Id = 1, Name="Nike",Age=29}
};
}
So, “Person” is a type with ID,Name and Age respectively that is under “Contacts” module with two different MGraph which are “People” and “Employee” that will generate separate create table statements of “Person” type.
Internally , M is represented somewhat like

Parsing the M all starts with Microsoft.M.Parser.SourceParser. In my sample M to SQL project, i used it like
SqlGenerator generator = SqlGenerator.Load(new StringReader(code));
string sql = generator.Generate();
Inside Load…
SourceParser parser = new SourceParser();
syntaxTerm = (CompilationUnit)parser.ParseTerm(reader, "buffer.m");
...
...
/// check if the parse was successful
if (!parser.LastParseSuccessful)
{
/// do some error processing for invalid schema.
}
Now, once we have a valid grammar, our next step is to get the modules from ISytaxTerm implementation, for each module we have to process the MGraph for the specified type.
foreach (IModuleDeclaration declaration in syntaxTerm.Modules)
{
builder.AppendSetExtactAbort();
builder.AppendGo();
builder.AppendBeginTransaction();
builder.AppendGo();
builder.AppendSetANSINulls();
builder.AppendGo();
builder.AppendCreateSchema(declaration.Name.Value);
builder.AppendGo();
builder.Append(ProcessMembers(declaration.Name.Value, declaration.Members));
builder.AppendCommitTransaction();
builder.AppendGo();
}
This shows the basic skeleton of how the output will look like. ProcessMembers is the actual place that generates the entity from type and associates Insert statements. Only, during the MGraph initialization type is realized. Therefore, the table name is equal to the extent name not to the type name.
Inside ProcessMembers …
/// There will be three declaration
/// -TypeDeclaion
///- ExtentDeclaration
///- ExtnetDeclaration
foreach (IDeclaration declaration in declarations)
{
if (declaration is TypeDeclaration)
{
typeDeclaration = (TypeDeclaration) declaration;
}
if (declaration is ExtentDeclaration)
{
/// use the type declaration from previous step.
builder.Append(ProcessExtent(name, typeDeclaration, (ExtentDeclaration) declaration));
}
}
TypeDeclaration is narrowed down to ParameteriedExpression , which has different operations for the declaring type, which is tracked by DeclartionReference.Name (“$Operator$Where”, “$Operator$Identity” , etc). Therefore, to process constraint and data types separately, we need to switch them for operation type. Now, the question is how the MGraph is referred from the type specified. The JSON like string is basically translated to GraphExpression. Like for the “Person” type , we have three properties. GraphExpression.Successors.Count will be equal to numeric value 3 and each of those which are GraphExpression themselves will have only one successor which is a M.Literal. This will actually contain the property name, type and value for parent type ref.
GraphExpression graphExpression = (GraphExpression) extentDeclaration.InitialValue;
if (extentDeclaration.InitialValue != null)
{
foreach (GraphExpression successor in graphExpression.Successors)
{
int index = 0;
foreach (var expression in successor.Successors)
{
if (expression is GraphExpression)
{
GraphExpression node = (GraphExpression) expression;
Literal literal = (Literal) (node).Successors[0];
/// process fragment
}
index++;
}
/// process the final statement
}
That’s all to get started. All the code has been taken from a MSqlProvider that i created while learning M. The technology is itself in bleeding edge so things will change and i will share my updated knowledge forward. You can further enhance MSQLProvider to run the result in configured database along with the mx.exe that comes with Oslo SDK.
You can download the source here to play around and see it live.
Enjoy!!


Tags: MGrammer, Oslo
Posted by cibrax on Mar 27, 2009 in
Miscelleneous |
View Original Article
Streaming large content such as media content, images or files is a common scenario for RESTful services. If a scenario like this is not well addressed or implemented on the service side, there is a high risk of consuming server resources like memory or CPU in a matter of seconds. This usually happens when the complete content is loaded in memory before it is transferred to the service consumer.
The WCF REST Starter kit introduced a new mechanism for addressing this scenario, an “AdapterStream” utility class, which basically pushes small pieces of content (and thus, only small memory buffers are used) to the client application as it becomes necessary.
The kit also comes with an example “PushStyleStreaming” that shows this class in action
Stream GetImage(string text)
{
if (string.IsNullOrEmpty(text))
{
throw new WebProtocolException(HttpStatusCode.BadRequest, "text must be specified", null);
}
Bitmap theBitmap = GenerateImage(text);
WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
return new AdapterStream((stream) => theBitmap.Save(stream, ImageFormat.Jpeg));
}
In the code above, the AdapterStream is used to transfer an image to a service consumer. As you can also notice in that code, that class receives a lambda expression or Action<T> delegate in the constructor. That provides some flexibility at the moment of generating the final stream that will be sent to the client application.
Another example that uses an TextWriter for generating text content,
new AdapterStream((writer) =>
{
writer.WriteLine("You said: ");
writer.WriteLine(text);
writer.WriteLine("Didn't you?");
writer.Flush();
}, Encoding.UTF8);
In addition to this feature, you might also want to have a better control of service usage by restricting the throttling settings. This is a good thing about REST services implemented with the WCF stack. Other implementations such as the ASP.NET MVC rely on the ASP.NET for handling this aspect, where these settings are applied only at application domain level (For all services running in the same app).

Tags: REST, REST Starter Kit, WCF
Posted by bryantlikes on Mar 24, 2009 in
C#,
Dotnet |
View Original Article
This is another nugget of gold gleaned from the Climbing Mt Avalon workshop, although I believe this one came from Jonathan Russ. He was talking about a bunch of threading tricks in WPF and showed how if you wanted to run some code after everything was initialized you could use the BeginInvoke method of the Dispatcher object. Since there are many places in my code where I want to execute something when the control loads, but only once (since the loaded event gets fired whenever the object gets re-added to the visual tree) I end up writing a lot of code like:
public partial class Page : UserControl
{
private bool initialized = false;
public Page()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
if (!initialized)
{
// do some initialization work
initialized = true;
}
}
}
This works, but it isn’t perfect and there seems to be a lot of issues with the timing of the loaded event. So based on what Jonathan was saying, you could instead just put a call into BeginInvoke in the contructor like so:
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
Dispatcher.BeginInvoke(Initialized);
}
private void Initialized()
{
// do some initialization work
}
}
So what is this actually doing? BeginInvoke puts a message in the message pump that is running under the covers of everything (note: I’m not a C++ programming so I don’t really fully understand message pumps so this is an over simplification). Because it is last in line in the queue of messages to process, it gets executed after all the other initialization code which has already lined up. If you debug this you will see it actually gets called after the Loaded event gets called. However, this code is the first thing to execute once everything has been loaded and setup which is usually when I want my code to execute.
So this is a much better way to handle initialization code since you aren’t adding event handlers that really only need to fire once and it executes once everything is fully initialized.


Tags: Silverlight, WPF/E
Posted by Bryant Likes on Mar 24, 2009 in
C#,
Dotnet |
View Original Article
This is another nugget of gold gleaned from the Climbing
Mt Avalon workshop, although I believe this one came from Jonathan
Russ. He was talking about a bunch of threading tricks in WPF and showed how if
you wanted to run some code after everything was initialized you could use the BeginInvoke
method of the Dispatcher object. Since there are many places in my code where I want
to execute something when the control loads, but only once (since the loaded event
gets fired whenever the object gets re-added to the visual tree) I end up writing
a lot of code like:
public partial class Page
: UserControl { private bool initialized
= false; public Page() { InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded); } void Page_Loaded(object sender,
RoutedEventArgs e) { if (!initialized) { //
do some initialization work initialized = true; }
} }
This works, but it isn’t perfect and there seems to be a lot of issues with
the timing of the loaded
event. So based on what Jonathan was saying, you could instead just put a call
into BeginInvoke in the contructor like so:
public partial class Page
: UserControl { public Page() { InitializeComponent(); Dispatcher.BeginInvoke(Initialized);
} private void Initialized() { //
do some initialization work } }
So what is this actually doing? BeginInvoke puts a message in the message pump that
is running under the covers of everything (note: I’m not a C++ programming so
I don’t really fully understand message
pumps so this is an over simplification). Because it is last in line in the queue
of messages to process, it gets executed after all the other initialization code which
has already lined up. If you debug this you will see it actually gets called after
the Loaded event gets called. However, this code is the first thing to execute once
everything has been loaded and setup which is usually when I want my code to execute.
So this is a much better way to handle initialization code since you aren’t
adding event handlers that really only need to fire once and it executes once everything
is fully initialized.

Tags: Silverlight
Posted by bryantlikes on Mar 23, 2009 in
C#,
Dotnet |
View Original Article
In my last post I blogged about using Attached Properties to get around the limitation that only Dependency Properties can be animated. One astute commented noted that he was guessing this could be applied to animations as well and the answer is yet it can. However, it requires one extra step that makes it a little less appealing.
Also I mentioned in my last post, I got this idea from the Climbing Mt Avalon workshop at MIX which has now been posted online and I would recommend watching if you’re doing Silverlight or WPF work. And now on to the code…
Typically if you want to animating something like the width of a grid in a column that isn’t animatable either because it isn’t a double, color, or another easily animatable type, then you would declare a dependency property on your own host class, usually a UserControl, and then animate that instead. A good example is this blog post on the subject which is what I’ve referred to many times.
However, if we take the attached property route instead of putting the code in our user control, we could declare our own attached property to do the work for us. Here is a simple example:
public static class Attachments
{
public static readonly DependencyProperty ColumnWidthProperty =
DependencyProperty.RegisterAttached("ColumnWidth",
typeof(double), typeof(Attachments),
new PropertyMetadata(
new PropertyChangedCallback(OnColumnWidthChanged)));
public static void SetColumnWidth(DependencyObject o, double value)
{
o.SetValue(ColumnWidthProperty, value);
}
public static double GetColumnWidth(DependencyObject o)
{
return (double)o.GetValue(ColumnWidthProperty);
}
private static void OnColumnWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((ColumnDefinition)d).Width = new GridLength((double)e.NewValue);
}
}
Once we have this code we can now simply animate the attached property like so:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SilverlightApplication1"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.Resources>
<Storyboard x:Name="expandBlue">
<DoubleAnimation Storyboard.TargetName="blue"
To="300" Duration="0:0:1" />
<DoubleAnimation Storyboard.TargetName="red"
To="100" Duration="0:0:1" />
</Storyboard>
<Storyboard x:Name="expandRed">
<DoubleAnimation Storyboard.TargetName="red"
To="300" Duration="0:0:1" />
<DoubleAnimation Storyboard.TargetName="blue"
To="100" Duration="0:0:1" />
</Storyboard>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="blue" local:Attachments.ColumnWidth="200" />
<ColumnDefinition x:Name="red" local:Attachments.ColumnWidth="200"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Fill="Blue" MouseLeftButtonDown="Blue_MouseLeftButtonDown" />
<Rectangle Grid.Column="1" Fill="Red" MouseLeftButtonDown="Red_MouseLeftButtonDown"/>
</Grid>
</UserControl>
Unfortunately if you try the above code (after adding in the mouse event handlers) it won’t work. Why not? Well there seems to be an issue with animating custom attached properties when setting the target property directly in code (actually you’ll notice I left that out above. However, there is a way around it which I found over on Ed’s blog which is to set the target property in code. So here is the code behind with the work around:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
Storyboard.SetTargetProperty(expandBlue.Children[0], new PropertyPath(Attachments.ColumnWidthProperty));
Storyboard.SetTargetProperty(expandBlue.Children[1], new PropertyPath(Attachments.ColumnWidthProperty));
Storyboard.SetTargetProperty(expandRed.Children[0], new PropertyPath(Attachments.ColumnWidthProperty));
Storyboard.SetTargetProperty(expandRed.Children[1], new PropertyPath(Attachments.ColumnWidthProperty));
}
private void Blue_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
expandBlue.Begin();
}
private void Red_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
expandRed.Begin();
}
}
Once we set the target property via code, then everything works great. However, that is a pain and makes things a lot less clean. But still I think this is a useful approach to animating the properties that are not easily animatable.


Tags: Silverlight, UX, WPF/E
Posted by bryantlikes on Mar 18, 2009 in
C#,
Dotnet |
View Original Article
I need to find the forum post where this question was asked, but I’ll have to do that later since I’m at MIX09 and searching the forums is low on my list. But I wanted to share a cool hack that I came across in the Climbing Mt Avalon (it was definitely a climb, not a hike). One of the many cool things that was shared was a tidbit by Jaime Rodriguez about using Attached Properties.
The question in the forums was how you can style the VerticalScrollBarVisibility property on a TextBox. The problem is that since this property isn’t a DependencyProperty so it can’t be styled. You can test this out by trying the following Xaml:
1: <UserControl x:Class="Attachment.Page"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: Width="400" Height="300">
5: <UserControl.Resources>
6: <Style TargetType="TextBox" x:Key="test">
7: <Setter Property="FontSize" Value="24" />
8: <Setter Property="VerticalScrollBarVisibility" Value="Visible" />
9: </Style>
10: </UserControl.Resources>
11: <Grid x:Name="LayoutRoot" Background="White">
12: <TextBox Text="This is a test" Style="{StaticResource test}" />
13: </Grid>
14: </UserControl>
If you try to run this it will fail. So how can we set this property in style? Well, a trick you can use is to set your own attached property and then have the property set the VerticalScrollBarVisibility property on the TextBox for you. Here is a very quick example that I cooked up (using Robby’s code snippet):
1: namespace Attachment
2: {
3: public static class Attachments
4: {
5: public static readonly DependencyProperty MyVsbvProperty =
6: DependencyProperty.RegisterAttached("MyVsbv",
7: typeof(ScrollBarVisibility),
8: typeof(Attachments),
9: new PropertyMetadata(OnMyVsbvChanged));
10:
11: public static void SetMyVsbv(DependencyObject o, ScrollBarVisibility value)
12: {
13: o.SetValue(MyVsbvProperty, value);
14: }
15:
16: public static ScrollBarVisibility GetMyVsbv(DependencyObject o)
17: {
18: return (ScrollBarVisibility)o.GetValue(MyVsbvProperty);
19: }
20:
21: private static void OnMyVsbvChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
22: {
23: ((TextBox)d).VerticalScrollBarVisibility = (ScrollBarVisibility)e.NewValue;
24: }
25: }
26: }
Very unintuitive name and my casts could be bad since there are no type checks, just an example. So here when the attached property is changed we change the property on the TextBox that the property is declared on. So if we change our style to use the attached property instead of the actual property it will work:
1: <UserControl x:Class="Attachment.Page"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: xmlns:local="clr-namespace:Attachment"
5: Width="400" Height="300">
6: <UserControl.Resources>
7: <Style TargetType="TextBox" x:Key="test">
8: <Setter Property="FontSize" Value="24" />
9: <Setter Property="local:Attachments.MyVsbv" Value="Visible" />
10: </Style>
11: </UserControl.Resources>
12: <Grid x:Name="LayoutRoot" Background="White">
13: <TextBox Text="This is a test" Style="{StaticResource test}" />
14: </Grid>
15: </UserControl>
So there you have it. If you need to style a property on a control that isn’t a dependency property you can use this method to get around that limitation. There are a bunch of other uses for this that I’ll be blogging when I have another minute.
Enjoy!


Posted by Bryant Likes on Mar 18, 2009 in
C#,
Dotnet |
View Original Article
I need to find the forum post where this question was asked, but I’ll have to
do that later since I’m at MIX09 and searching the forums is low on my list.
But I wanted to share a cool hack that I came across in the Climbing
Mt Avalon (it was definitely a climb, not a hike). One of the many cool
things that was shared was a tidbit by Jaime
Rodriguez about using Attached Properties.
The question in the forums was how you can style the VerticalScrollBarVisibility property
on a TextBox. The problem is that since this property isn’t a DependencyProperty
so it can’t be styled. You can test this out by trying the following Xaml:
1: <UserControl
x:Class="Attachment.Page"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: Width="400" Height="300">
5: <UserControl.Resources>
6: <Style
TargetType="TextBox" x:Key="test">
7: <Setter
Property="FontSize" Value="24" />
8: <Setter
Property="VerticalScrollBarVisibility" Value="Visible" />
9: </Style>
10: </UserControl.Resources>
11: <Grid
x:Name="LayoutRoot" Background="White">
12: <TextBox
Text="This is a test" Style="{StaticResource
test}" />
13: </Grid>
14: </UserControl>
If you try to run this it will fail. So how can we set this property in style? Well,
a trick you can use is to set your own attached property and then have the property
set the VerticalScrollBarVisibility property on the TextBox for you. Here is a very
quick example that I cooked up (using Robby’s
code snippet):
1: namespace Attachment
2: {
3: public static class Attachments
4: {
5: public static readonly DependencyProperty
MyVsbvProperty =
6: DependencyProperty.RegisterAttached("MyVsbv",
7: typeof(ScrollBarVisibility),
8: typeof(Attachments),
9: new PropertyMetadata(OnMyVsbvChanged));
10:
11: public static void SetMyVsbv(DependencyObject
o, ScrollBarVisibility value)
12: {
13: o.SetValue(MyVsbvProperty, value);
14: }
15:
16: public static ScrollBarVisibility
GetMyVsbv(DependencyObject o)
17: {
18: return (ScrollBarVisibility)o.GetValue(MyVsbvProperty);
19: }
20:
21: private static void OnMyVsbvChanged(DependencyObject
d, DependencyPropertyChangedEventArgs e)
22: {
23: ((TextBox)d).VerticalScrollBarVisibility
= (ScrollBarVisibility)e.NewValue;
24: }
25: }
26: }
Very unintuitive name and my casts could be bad since there are no type checks, just
an example. So here when the attached property is changed we change the property on
the TextBox that the property is declared on. So if we change our style to use the
attached property instead of the actual property it will work:
1: <UserControl
x:Class="Attachment.Page"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: xmlns:local="clr-namespace:Attachment"
5: Width="400" Height="300">
6: <UserControl.Resources>
7: <Style
TargetType="TextBox" x:Key="test">
8: <Setter
Property="FontSize" Value="24" />
9: <Setter
Property="local:Attachments.MyVsbv" Value="Visible" />
10: </Style>
11: </UserControl.Resources>
12: <Grid
x:Name="LayoutRoot" Background="White">
13: <TextBox
Text="This is a test" Style="{StaticResource
test}" />
14: </Grid>
15: </UserControl>
So there you have it. If you need to style a property on a control that isn’t
a dependency property you can use this method to get around that limitation. There
are a bunch of other uses for this that I’ll be blogging when I have another
minute.
Enjoy!

Tags: Silverlight
Posted by bryantlikes on Mar 11, 2009 in
C#,
Dotnet |
View Original Article
Yesterday I was working through another question in the Silverlight Forums about how to upload video to Silverlight Streaming via code. At first I tried to reference the Video.Show application, but there is a lot of code there and it doesn’t help if you just want to upload a bunch of videos to the same application. So I ended up taking some of the code from Video.Show and some of the code from the SDK/API and created a very simple Utility class to help with the process.
You can download the code on the Code Gallery site. It is very simple in that there is no error handling and I didn’t create a Silverlight version yet. I did implement GET, POST, PUT, MKCOL, and DELETE as well as creating the functionality to package a bunch of videos into a single zip which can be posted all at once.
A few examples from the code, first creating a directory and PUTting a file in it:
WebDavClient client = new WebDavClient("Your AppID", "Your Key");
// get those from http://silverlight.live.com
client.CreateFolder("MyVideos");
client.PutFile("MyVideos","C:\\videos\reallyCoolVideo.wmv");
Next, packaging up a bunch of videos and POSTing the zip as an application:
WebDavClient client = new WebDavClient("Your AppID", "Your Key");
// get those from http://silverlight.live.com
client.PackageAndPostFiles("MyVideos","C:\\videos\firstCoolVideo.wmv","C:\\videos\anothercoolVideo.wmv");
Let me know if you’d like to see a Silverlight version (be easy to implement) or if there are any other features you’d like added.
Enjoy!


Tags: Silverlight, WPF/E
Posted by bryantlikes on Mar 10, 2009 in
C#,
Dotnet |
View Original Article
This question has come up in the forums a few times so I thought it would be worth a blog post. Most people are pretty familiar with debugging a Silverlight application running locally during development, but what people many times don’t realize is that you can also attach your debugger to a xap file that is hosted remotely. This MSDN article touches on this briefly, but doesn’t really go into details on how it works.
The important thing to understand about Silverlight is that it runs the .NET code on the client machine, not on the server. The code runs in the browser process, so if you’re going to debug it you need to attach to that process. The one caveat is that the xap on the server must be the same as the compiled xap on your development machine. In other words, you can’t debug the remote xap after you’ve made changes locally and haven’t deployed them.
As an example I will demonstrate remotely debugging the Twilight badge on my blog.
First I open the Twilight.sln and since I’ve made a few changes in the last week I’ll deploy the latest xap file from my project to my server at http://blogs.sqlxml.org/wpfe/twilight.xap.
Next, now that I am sure the xap file on the server has the same code as my solution, I can set a breakpoint on Line 36 (using version 1.5.2) where the Twitter javascript callback calls into Silverlight with the latest list of tweets:
Now instead of hitting F5 to start debugging my application, I’ll open a new instance of Internet Explorer (or you could use Firefox to debug that as well) and navigate to my blog since that is where the xap shows up. Back in Visual Studio I click Debug –> Attach to Process and select the iexplore.exe process which is Internet Explorer (or firefox.exe if you’re debugging Firefox).
NOTE: Make sure you click highlight iexplore.exe or firefox.exe and then click the Select button and choose Silverlight as the type of code you wish to debug.
Once I click attach I can go back to my Internet Explorer window and hit refresh to force the breakpoint to get hit. If everything was setup correctly you should get taken back to Visual Studio where your breakpoint is highlighted and you can now step through your Silverlight code.
So why is this useful? Well a lot can change in your application when you start hosting it on a real server instead of in your localhost. For one, you now have to access services running on the server and you are subject to a lot more security checks that were ignored on your localhost. So I find this to be a useful tool for troubleshooting things when they work locally but break once I deploy out to a server.
One last thing, you can also set this up to remotely debug code running on the Mac.


Tags: Silverlight, Visual Studio, WPF/E
In marketing and advertising, a ‘call to action’ is a message or statement which encourages the prospect to perform a specific action. Most of the time this involves buying a product, making a donation, subscribing to a newsletter or requesting for more information. The specific action to take is defined by the marketer in accordance with his/her goals.
If you think about it, call-to-actions are really a natural result of most human interactions. You call a friend to chit-chat and before you hang up, you ask her to have lunch together tomorrow. She thinks about her schedule for a moment and says “Sure, let’s do that”.
It’s just a way to conclude a moment of interaction. It’s telling the other party ‘what’s next’ and how to continue. If used alongside exceptional content, the call to action no longer becomes a gentle request but an imperative that requires your immediate commitment.
I often feel that way when I’m reading well written brochures from charity organizations. And it works the same way (sadly) for get-rich-quick scams that prey on the human desire for happiness, of which wealth is widely seen as the best means. If the message is overwhelming enough, people will generally do whatever it is you want them to do.
Even in day to day interactions, people react to call to actions that are coherent with what they are currently feeling or thinking. It flows on from an initial encounter: Here is how you can get even more of the same. Here is how you can continue down the path of success. Here is how you can share your love (or hate) for this brand.
We have a predilection for sharing information: We often tell people about our good or bad experiences with products or places, sometimes even if no one asks for our opinion. If you want someone to spread the word about your content or service, ask them directly. They will do it even if you don’t give them an incentive. This is what I believe from experience.
Modesty and pride are usually the main obstacles. You don’t want to come off as too conceited and you’re too proud to beg. So you publish free content and give away free tools without asking for anything in return. Maybe its just a hobby for you and you don’t care. That’s cool. But if you’re interested in reputation or revenue, this won’t help you at all.
There’s Nothing Wrong With Asking for Help

I’ve been using Ozh’s Admin Drop Down Menu, a Wordpress plugin that arranges the current admin area menus in a horizontal, instead of a vertical format. This is a great feature that helps me work faster and better with Wordpress websites.
In the settings menu for this plugin, you’ll find a series of call to actions:

People have a few options of what to do after installing and using the plugin. Two of them involves increasing its social proof (rating and sharing the plugin) and one is a revenue generator (donations). Generally, people are more willing to part with compliments (free) than money (cost involved) so I would imagine that most would pick the first two options.
The plugin has a perfect 5 star score (with 316 ratings) at the Wordpress plugin directory, which as some will know, is a rare feat for any plugin that has over 100 ratings. Impressive stuff, although part of its success is also due to the simplicity of the plugin itself.
This is a free tool. Some would have just installed it and forgot about sharing if they were not prompted to do so. We have things on our mind, goals to fulfill, people to meet and jobs to do. Call to actions break through the clutter and say ‘do this now’. Don’t let your prospect’s interest or satisfaction fade beneath the noise of other things that demand their attention.
If you give away free content, you should not only ask why you are doing so but learn to embed call to actions in some of them. Don’t be too modest or proud to tell someone what you want them to do for you. And never underestimate the power of reciprocity. It’s an influential social norm that you can use to your advantage when marketing online.
Enjoyed this post? Subscribe to dosh dosh today (It’s free!)
Tell People What You Want Them to Do for You
Social Bookmark
Tags: Blogging Tips, Internet Marketing, web resources