header bg
 

Sl.ayer's layer

It looks like you're writing a blog...

Hosting BlogEngine blog on AppHarbor

by Sl.ayer 21. June 2011 03:28

I’ve being thinking about giving cloud hosting a try since Azure went into beta. But, the price of a single instance on Azure with a SQL database makes it completely impractical for a blog with less than 100 unique visits a day. Good news: you can now jump into cloud without breaking the bank.  Mountain View startup AppHarbor will give you one instance with 20MB SQL database for free!  AppHarbor cloud hosting comes with a twist -- instead of a traditional deployment mechanism than you locally compile your project, build the deployment package, and push it to the cloud, AppHarbor gives you a Git source repository from which it builds the solution on every commit, and deploys results of the successful builds to the site.

When I started the process of deploying BlogEngine on AppHarbor, I had some doubts about whether BlogEngine could work in the cloud environment. I can now say that it can, with some minor caveats. Due to the transient nature of application deployment in the cloud, all data should be stored in the database, external CDN, or must be checked into the source repository. If you want to embed image into your blog post, you must upload it to the external CDN first, and then link that location from your article. You can use DropBox as CDN as long as your site traffic is light, or you can get cloud storage for cheap from Amazon or Azure.

Installing BlogEngine on AppHarbor was surprisingly easy; in all, it took about two hours including downloading BlogEngine’s sources, installing the Git client, reading instructions, and going through a few failed builds. Here is a brief overview of the steps I made to get a copy of my blog deployed to AppHarbor:

  • Download BlogEngine’s source code from Codeplex
  • Move lib directory to BlogEngine directory and update references in the BlogEngine.Core project. (It is quite possible that if you don’t follow this step, everything would work just fine, but I did it, so I mention it here.)
  • Copy SQLServer.NET_4.0_Web.Config file from the BlogEngine.NET\setup\SQLServer directory (or if you prefer to go with MySQL database, MySQL.NET_4.0_Web.Config from BlogEngine.NET\setup\MySQL) to BlogEngine.NET directory and rename it to Web.config (delete existing web.config first)
  • Update target framework in the BlogEngine.NET project properties from .NET Framework 3.5 to .Net Framework 4. (Without this step, the build failed for me.)
  • Create new account on AppHarbor.com (if you don’t have one already)
  • Create new application
  • Add database to your application. Select SQLServer or MySQL depending on the web.config file you chose in the step above. Set connection string name to ‘BlogEngine’
  • Connect to the database with SQL Server Management Studio (or MySQL equivalent) using information provided on the database page. Load MSSQLSetup2.0.0.0.sql (or MySQLSetup2.0.0.sql) and execute it
  • Go back to your application page and follow the instructions on how to check in BlogEngine sources using Git client (get git client first if you don’t have one)
  • At this point build should successfully complete and you should be able to follow the link to your application and see BlogEngine’s front page
  • Follow instructions on the BlogEngine site to configure you fresh install
  • Import existing posts using BlogML and you’re done

One bit of strange behavior that I noticed was that absolute links would fail to load, due to the requests being made on a port other than 80. Apparently this is a known issue that I’ve fixed by modifying AbsoluteWebRoot property in Utils.cs. Update: Link to metaweblog.axd (RsdHandler.cs) needed fixing too.

So far, I am pretty happy with my experience with AppHarbor. It could be some time before I can move my site entirely to AppHarbor, but I am willing to give it a try. Meanwhile, check out my blog on AppHarbor http://ypblog.apphb.com.

What you need to know about DropShadow to create great Silverlight applications

by Sl.ayer 31. July 2010 02:42

Blur and DropShadow effects offer easy way to enhance your application’s visual appeal. But they come with a big price tag, and if used incorrectly, could destroy user experience instead of improving it. In order to make the best use of these effects in Silverlight, it is important to understand how they work behind the curtain.

When Silverlight runtime renders an element with an effect (whether built-in or custom pixel shader), it first renders that element and all of its children into an off-screen bitmap. Then, using that bitmap as the input for the pixel shader effect, the output of the pixel shader is finally rendered to the screen.

What’s interesting about the Blur effect is that unlike custom effects that can only have one pass, it executes in two passes. The first pass blurs the image horizontally, while second pass finishes with a vertical blur. This is called separable blur, and it saves a significant amount of computation in exchange for using extra memory and fill rate.blur

The cost of separable blur with radius N (N tap filter) can be estimated as: 2 writes + 2 * N reads + 2 * N multiplies + 2 * (N – 1) additions per pixel. So, applying 9 tap blur effect to a 400 x 400 pixel element will take 3,200,000 memory operations and 4,800,000 arithmetic operations. Now you can see how applying the blur effect to a large element can choke even a high-end CPU. And yes, Silverlight 4 executes all effects, including blur and drop shadow, onto the CPU. The Windows Phone 7 version of Silverlight is an exception, because it doesn’t support custom pixel shaders, and executes Blur and Drop Shadow effects on the phone’s GPU.

The DropShadow effect is a little more complicated then the Blur effect. It starts in the same way as any other effect by rendering the element into a memory bitmap. Then an alpha mask is separated from the bitmap and blurred using the exact same two-pass method I described for blur. Finally, the bitmap and the blurred alpha mask combined to create an element with drop shadow.shadow

Because DropShadow uses a blur filter, it will suffer the same performance problems as the Blur effect. Furthermore, DropShadow uses even more memory and more fill rate, making it very taxing on both the CPU and memory bandwidth. It is important to understand that the cost of applying the DropShadow effect depends entirely on the size of the element, regardless of how much or how little of the actual shadow can be seen.

As I mentioned before, applying an effect to an element with children will cause the complete visual sub-tree to be rendered into the bitmap and processed by pixel shader. This has an important implication – the easiest way to drive CPU utilization to 100% is to add a drop shadow to the large form with one tiny animated control.

This last bit of information about effects is not performance related, but still important to know. Applying an effect to a text element or its parent forces Silverlight to use its standard anti-aliased text rendering instead of ClearType. This is the second reason why you should not add effects to the top level controls.

Things you can do to improve performance

The recommendations I provide below hold true for all effects, but they are especially important for expensive effects such as DropShadow.

1. Use effects sparingly. This will not only improve your application’s performance, but it will also increase the impact from using them.

2. Avoid adding drop shadow to elements with children, especially if children are interactive or animated. In most cases, it should be possible to redesign the visual hierarchy in such a way that drop shadow is applied to an element without children.

3. Use alternative methods to achieve similar visual result. For example, drop shadow can be often approximated with the help of linear gradients. Pre-rendering the effect for static elements can offer big performance savings as well.

4. If you need to animate large element with a drop shadow, turn effect off before starting animation and turn it back on at the end. You will be surprised how much smoother animation will feel.

5. Consider creating a “fast” theme for your application with all nonessential effects removed. Netbook owners and mobile users will love you for this.

Fun with TipBubble. Styling TabControl

by Sl.ayer 22. July 2010 01:55

I was thinking of some fun ways to use the TipBubble control, aside from the obvious. Here’s an idea, how about using TipBubble to style TabControl?TabStyle

Achieving the result you see on the image above is quite simple. Just make a copy of the default TabItem style and replace the TemplateTopSelected grid with the code below.

<Grid x:Name="TemplateTopSelected" Canvas.ZIndex="1" Visibility="Collapsed">
    <tip:TipBubble
        BorderBrush="{TemplateBinding BorderBrush}"
        BorderThickness="1,1,1,0"
        CornerRadius="3,3,0,0"
        TipPosition="0.5"
        TipSide="Bottom"
        TipFill="#FcD400"
        TipSize="10"
        Margin="0 0 0 -8">
        <tip:TipBubble.Background>
            <LinearGradientBrush
                EndPoint="0,0" StartPoint="0,1"
                ColorInterpolationMode="ScRgbLinearInterpolation">
                <GradientStopCollection>
                    <GradientStop Color="#FFE97F" Offset="1" />
                    <GradientStop Color="#FcD400" Offset="0" />
                </GradientStopCollection>
            </LinearGradientBrush>
        </tip:TipBubble.Background>
        <ContentControl
            Cursor="{TemplateBinding Cursor}"
            Height="Auto" Width="Auto"
            x:Name="HeaderTopSelected"
            FontSize="{TemplateBinding FontSize}"
            FontWeight="Bold"
            Foreground="#333" IsTabStop="False"
            HorizontalContentAlignment="Center"
            VerticalContentAlignment="Center"
            Margin="6,4,6,4"/>
    </tip:TipBubble>
</Grid>

Repeat this operation for TemplateBottomSelected, TemplateLeftSelected, and TemplateRightSelected to get the complete style. Remember to modify TipSide, Margin BorderThickness and CornerRadius to correspond with each template (i.e. tab on the bottom, tip on the top; tab on the left, tip on the right etc.)

TipBubble Tutorial

by Sl.ayer 19. July 2010 18:40

TipBubble is one of the controls that comes with the Free Bubbles library (it is called this because its most obvious use is for making tooltips).

Below is a quick overview of TipBubble properties.

TipSide

TipSide property controls which side of the bubble to show the tip. It can be set to Bottom, Top, Left or Right.

TipSide

 

TipPosition

TipPosition property controls positioning of the tip on the side of a bubble. It accepts values from the 0 to 1 range, with 0 corresponding to top or left, 0.5 center, and 1 right or bottom.

TipPosition

TipSize TipSize

TipSize property allows you to change the size of the tip. Since the tip is made from an equilateral triangle, TipSize is the size of all of its sides.

TipFill

TipFill property defines the Brush used to fill the tip. Typically, TipFill should use the same Brush as Background property.

TipStrokeThickness

TipStrokeThickness defines the width of the stroke around the tip. In most cases, it should be the same as the corresponding side of the BorderThickness property.

Background, BorderBrush, BorderThickness, Padding…

All common control properties behave in the same way as you would expect for all other controls.

Examples

Basic TipBubble

ColorBbl

  <tip:TipBubble Background="#FF7FBC65" 
                 TipFill="#FF7FBC65" 
                 TipSide="Left" 
                 TipPosition="0.5" 
                 TipSize="10" 
                 Padding="10 5" 
                 BorderThickness="3" 
                 BorderBrush="#FF89EE78" 
                 TipStrokeThickness="2" > 
      <TextBlock Foreground="White"> 
          Background="#7FBC65" 
          <LineBreak/> 
          BorderBrush="#89EE78" 
      </TextBlock> 
  </tip:TipBubble> 

TipBubbble With Complex Content

Effect

  <tip:TipBubble Background="#FF7FBC65"
                 TipSide="Left"
                 TipPosition="0.5"
                 TipSize="10"
                 TipFill="#FF7FBC65"
                 BorderThickness="3"
                 BorderBrush="#FF89EE78"
                 TipStrokeThickness="2" >
      <Grid>
          <Rectangle Margin="5"
                     Fill="#FF6FCD52"
                     RadiusX="2"
                     RadiusY="2">
              <Rectangle.Effect>
                  <BlurEffect Radius="9" />
              </Rectangle.Effect>
          </Rectangle>
          <TextBlock Foreground="White"
                     Margin="12 6"
                     FontWeight="Bold">
              Complex Content Element
              <LineBreak/>
              with blured Background
          </TextBlock>
      </Grid>
  </tip:TipBubble>

ToolTip stlyed using TipBubble

ToolTip style (sans animations)

  <Style TargetType="ToolTip" x:Key="tipBubbleStyle">
     <Setter Property="Padding" Value="8"/>
     <Setter Property="BorderThickness" Value="1"/>
     <Setter Property="Template">
        <Setter.Value>
           <ControlTemplate TargetType="ToolTip">
              <bubbles:TipBubble
                 BorderThickness="0"
                 Padding="10"
                 TipSide="Bottom"
                 TipPosition="0.2"
                 TipFill="LimeGreen"
                 TipStrokeThickness="0"
                 CornerRadius="5"
                 Content="{TemplateBinding Content}">
                 <bubbles:TipBubble.Background>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                       <GradientStop Color="Yellow" Offset="0.0" />
                       <GradientStop Color="Red" Offset="0.25" />
                       <GradientStop Color="Blue" Offset="0.75" />
                       <GradientStop Color="LimeGreen" Offset="1.0" />
                    </LinearGradientBrush>
                 </bubbles:TipBubble.Background>
              </bubbles:TipBubble>
           </ControlTemplate>
        </Setter.Value>
     </Setter>
  </Style>

Styled ToolTip

  <Grid Width="250" Height=”100” Background="#eee">
     <ToolTipService.ToolTip >
        <ToolTip Placement="Top" Style="{StaticResource tipBubbleStyle}">
           <TextBlock Foreground="#fff" Background="#7000">
              <Run FontWeight=”Bold”>TipBubble</Run> is fun…
           </TextBlock>
        </ToolTip>
     </ToolTipService.ToolTip>
  </Grid>

heart

Free Comic Bubble Control

by Sl.ayer 16. July 2010 05:17

freeI’ve been working on my Silverlight Comic Creator application for a pretty long time now. One of the more difficult tasks was creating speech bubble control that is customizable, easy to use and one that looks like it belongs in the comic. Well, today I am releasing my free Comic Bubble control to the public, so your application can have cool speech bubbles too without having to do all the heavy lifting.

You can add comic bubble to your Silverlight application in a few easy steps:

1. Download Free Comic Bubble Library

2. Add FreeBubbles.dll to your project references

3. Add custom namespace to the top parent control

<UserControl x:Class="BubblesApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:bubbles="clr-namespace:FreeBubbles;assembly=FreeBubbles"

4. Add Bubble control to your XAML

  <bubbles:Bubble Text=”Hello”
          FontFamily="Arial"
          FontSize=”22”
          OutlineThickness="2"
          AllowEdit="True"
          TailPoint=”30 70” />  

 

5. Customize Bubble’s appearance by changing its properties

License

Comic Bubble Control is free for use in any non-commercial project. Send me a link to your project; I would love to see the creative ways that this control can be used.

“Scratch”, WriteableBitmap Sample

by Sl.ayer 21. December 2009 04:37

Screen I have a new addition to my samples gallery. This sample was inspired by a question I answered on the silverlight.net community forums. The idea of creating a “scratchable” surface intrigued me, so I decided to make a full-blown sample utilizing WritabeBitmap.

It took me about 8 hours from start to finish to implement the sample. Most of it I spent fussing over the application’s look-and-feel and getting the brushes to work properly. Some of my failed experiments with brushes produced very interesting, almost impressionistic-looking, results.

The ideas I considered for development, but not included in the sample: changing brush shape depending on stroke’s velocity; rotating brush based on the angle of the stroke; and multi-touch support.

Hosting Silverlight application in Facebook iframe

by Sl.ayer 17. December 2009 04:24

If you’re building a Silverlight application for Facebook, you have two choices: (1) build a stand alone application and use Facebook Connect for authentication, or (2) create a canvas application that will appear on a Facebook site and use the parameters passed to iframe to establish a session. The former is well covered in the Facebook Toolkit documentation, but I couldn’t find any examples of how to embed a Silverlight application within a Facebook iframe. It took a few days worth of research and experiments to get it right and I hope this post will be helpful to anyone who is working on Silverlight canvas application for Facebook.

Embedding Silverlight into Facebook canvas

I know three ways of embedding Silverlight application into a Facebook canvas.Fbss

(1) Select the IFrame option for Render Method in Canvas section of the application settings and embed the Silverlight application inside the iframed page using standard methods (object tag, silverlight.js, etc.).  (2) Use <fb:iframe> tag in fbml based canvas. (3) Use fbml tag <fb:silverlight>. The <fb:silverlight> tag would be the preferred method, but according to the Facebook wiki, the tag is not implemented at this time. That leaves only options 1 and 2 available – embed Silverlight in iframe.  Whether you go with IFrame canvas or use <fb:iframe> tag in fbml, the following steps are the same:

More...

Styled Silverlight buttons

by Sl.ayer 17. December 2009 00:23

Button

I spent some time recently going through some of my older projects and consolidating different button styles I’ve designed over time into a single project.

You can see the results in this Silverlight sample application.

Color picker control for Silverlight

by Sl.ayer 19. August 2009 02:54

colorpickr

I am a bit of a fan of colors and consequently of color pickers. First release of Silverlight didn’t provide much help with control development and my first color picker was very simple: four sliders, one for each of the color components of RGBA color.

With release of Silverlight 3.0 developers have a choice of the color pickers made by the enthusiasts and companies specializing in Silverlight controls.

Unfortunately, the only kind of color pickers I could find are based on SV+H model. I figure it is due to Microsoft products favoring that type of color picker. Personally, I prefer HS+V color pickers, commonly used in Adobe products, so I had to sit down and build one myself.

Color picker was my first custom control and quite expectedly I ran into some issues during development, but it was a good learning experience.

Color picker is free to use in any projects. Have fun.

header bg