Sunday 29 April 2012

Validation In Silverlight


By default silverlight doesn't give any visual feedback when the data binding system encounters error relating to incorrect input. But internally it rejects data and user is thinking that data has been saved. Silverlight data binding engine has to notify or alert us through visual appearance when there is a violation of rule.

Lets begin :)

1. Create a silverlight application and add the following Student class to your project

public class Student
{
public string Name{get; set;}
public int Age{get; set;}
}

2.//MainPage.xaml.cs

public MainPage()
{
initializeComponent();
Student std= new Student();
LayoutRoot.DataContext =std;
}

3.//MainPage.xaml
Run the application and type string in the age field . Internal validation has happened by rejecting the  invalid input but no visual feedback.

4.ValidatesOnExceptions = True, by doing that, it will makes sure silverlight will provide visual feedback for the validation error.
<TextBox Name="txtName" Text="{Binding Name,ValidatesOnExceptions=True}"
<TextBox Name="txtAge" Text="{Binding Age,ValidatesOnExceptions=True}"

5. Again type string value in Age textbox, this appearance will come :)




Friday 27 April 2012

Silverlight Deep Zooming

The idea behind Deep Zoom is to present a “zoom-able” interface for huge images. The typical Deep Zoom image is far too large to be shown on screen at once at its native resolution.

It’s easy to create a Silverlight application that uses Deep Zoom, provided you have the  right tools. The most important is the free Deep Zoom Composer tool. The Deep Zoom Composer allows you to convert a large image into the tiled groups of images that Deep Zoom needs for its zooming interface. It also lets youtile together smaller images to create a large image that’s suitable for Deep Zoom, and it can even stitch overlapping images together automatically.

To get started, load Deep Zoom Composer, and click New Project. You’ll need to choose a project name and a project location.One folder, named Source Images, holds the original versions of all the pictures you import. The second folder, named Working Data, holds the dozens of image files that are generated when you lay these pictures out into a Deep Zoom image set.

Note : Deep Zoom project can only be opened in Deep Zoom composer. You must export the image set to generate a Silverlight project.

1.To get the pictures you want, click the Import button in the panel at right, browse to the correct file, and click OK. Importing large pictures can be slow, so be prepared to wait.

2.until you’ve imported all the pictures you need.

3.Click the Compose button. and lay out your pictures.
 
4.To add, drag picture  from the panel at the bottom.
 
5.Click the Export button. Deep Zoom Composer gives several export options The two most useful are to export your image set to DeepZoomPix or to create a Silverlight project.

6.To create a Silverlight project, click the Custom tab in the panel at the right. In the“Output type” box, choose Silverlight Deep Zoom

7. In the Name text box, enter a name for your project. If you want to export the project to a different folder, change the path in the Location text box.

8.Choose “Export as a collection” to create a Deep Zoom image set.
 
9.In the “Image settings” box , choose either PNG or JPEG.
 
10.Click Export to create the image set and Silverlight project.

Showing a Deep Zoom image in a Silverlight application is fairly easy. In fact, all you need is the MultiScaleImage element, as shown here:

<MultiScaleImage x:Name="msi" Height="600" Width="800"/>

Wednesday 25 April 2012

Silverlight Video Support

When it comes to video, Silverlight supports the follow standards:

• Windows Media Video 7 (WMV1)
• Windows Media Video 8 (WMV2)
• Windows Media Video 9 (WMV3)
• Windows Media Video Advanced Profile, non-VC-1 (WMVA)
• Windows Media Video Advanced Profile, VC-1 (WMVC1)
• H.264 video and AAC audio (also known as MPEG-4 Part 10 or MPEG-4 AVC)

First, create a MediaElement for the file you want to play :

<MediaElement x:Name="fireMovie" Source="fire.wmv" Height="200" Width="200"></MediaElement>

Often, you can recognize Windows Media Video by the file extension .wmv. Other video formats – for example, MPEG and QuickTime–need not apply. The last two formats in this list–VC-1 and H.264–are widely supported.

WMV files you use in your Silverlight application will be a final product based on larger, higher-quality original video files. Often, the original files will be in a non-WMV format.

To get the right results when preparing video for the Web, you need the right tool. Expression Encoder is a remarkably polished and powerful tool.

Key features:

Simple video editing : You can cut out sections of video, insert a lead-in, and perform other minor edits.

Overlays : You can watermark videos with a still or animated logo that stays superimposed over the video for as long as you want it to.

Silverlight-ready : allows you to create a fully skinned Silverlight video player.

To encode a video file in Expression Encoder, follow these steps :

1.To specify the source file, choose File Import. Browse to the appropriate media file, select it, and click Open.

2.To specify the destination file, look at the group of tabs on the right side of the window, and select the Output tab. In the Job Output section, you can specify the directory where the new file will be placed, and its name.

3.To choose the bit rate, look in the Presets tab (in the top-right corner of the window) and expand the Encoding for Silverlight section. If you’re using progressive downloads, you need to select a format from the Variable bitrate group.

4.After you choose an encoding, the relevant information appears in the Video section of the Encode tab.

5.To encode your video, click the Encode button at the bottom of the window, in the Media Content panel.

Tuesday 24 April 2012

Silverlight Audio Support

Adding audio to a Silverlight application is fairly easy, because you can throw in just about any MP3 file. Using a video file is more work. Not only must you make sure you’re using one of the supported WMV formats, but you also need to carefully consider the quality you need and the bandwidth your visitors can support.

For audio, Silverlight supports the following :

• Windows Media Audio (WMA) [versions 7, 8, and 9]
• MP3

All the audio and video functionality is built into a single class: MediaElement. A simple MediaElement tag is all you need to play a sound. For example, add this markup to your user interface :

<MediaElement Source="test.mp3"></MediaElement>

The startup behavior of the MediaElement is determined by its AutoPlay property. If this property is set to false, the audio file is loaded, but your code takes responsibility for starting the playback at the right time :

<MediaElement x:Name="media" Source="test.mp3" AutoPlay="False"></MediaElement>

When using this approach, you must make sure to give the MediaElement a name so that you can interact with it in code. Generally, interaction consists of calling the Play(), Pause(), and Stop() methods.
We can change the Position property to move through the audio.
Here’s a simple event handler that seeks to the beginning of the current audio file and then starts playback : 

private void cmdPlay_Click(object sender, RoutedEventArgs e)
{
media.Position = TimeSpan.Zero;
media.Play();
}

The two check boxes on the page are the last ingredient in this media player and one of the simplest details. The Mute check box sets the corresponding IsMuted property of the MediaElement :
private void chkMute_Click(object sender, RoutedEventArgs e)
{
media.IsMuted = (bool)chkMute.IsChecked;
}

Handling errors :
MediaElement doesn’t throw an exception if it can’t find or load a file. Instead, it’s up to you to handle the MediaFailed event. Fortunately, this task is easy. First, tweak your MediaElement tag as shown here :
<MediaElement ... MediaFailed="media_MediaFailed"></MediaElement>
Then, in the event handler, you can use the
ExceptionRoutedEventArgs.ErrorException property to get an exception object that describes
the problem. Here’s an example that displays the appropriate error message:
private void media_MediaFailed(object sender, ExceptionRoutedEventArgs e)
{
lblErrorText.Text = e.ErrorException.Message;
}

The MediaElement exposes a number of properties that allow you to control your playback.
Volume : Sets the volume as a number from 0 (completely muted) to 1 (full volume). The default value is 0.5.set IsMuted to true for temporarily muting.

Balance : Sets the balance between the left and right speaker as a number from -1 (left speaker only), 1(right speaker only) and 0 by default.

Position : Provides a TimeSpan object that indicates the current location in the media file.

<Slider Grid.Column="1" x:Name="sliderVolume" Minimum="0" Maximum="1" Value="0.5"
ValueChanged="sliderVolume_ValueChanged" ></Slider>

<Slider Grid.Row="1" Grid.Column="1" x:Name="sliderBalance" Minimum="-1" Maximum="1"
ValueChanged="sliderBalance_ValueChanged"></Slider>

When the user drags the thumb in the slider, the change is applied to the MediaElement :
private void sliderVolume_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
media.Volume = sliderVolume.Value;
}

private void sliderBalance_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
media.Balance = sliderBalance.Value;
}

The Mute check box sets the corresponding IsMuted property of the MediaElement :
private void chkMute_Click(object sender, RoutedEventArgs e)
{
media.IsMuted = (bool)chkMute.IsChecked;
}

Linq To Sql

LINQ to Sql  interact and provides query capability to relational database.

Architecture of LINQ to sql consists of :

Object Model - It consists of Data Context and Data Entities. Data entities are the partial classes generated by Linq to sql. Data context define connection to the database.It maps data entities with databae tables and
fills the objects into generic collection type called Table<>. It also maps Stored Procedures and user defined functions.
 
Object Relational Designer  

Runtime
 
Key Features of Linq to sql :-

1)Generating Object Model From db -  Linq to Sql connects to sql server db and creates ObjectModel by dragging  and dropping tables from the server explorer.

2)Stored Procedures and user defined functions support - linq to sql supports stored procedures and user-defined functions by generating corresponding methods in DataContext.

3)Framework compatibilities - linq to sql is part of .Net framework 3.5 and higher.

Strengths :-

1)Linq to sql queries are well-integrated with programming lang. this helps in avoiding Sql Injection attacks.

2)Uniform syntax for working with various data sources like xml, relational datastores like sql server.

3)Improve app. dev by proving Intellisense, compile time syntax checking and debugging support.

4)Support compiled queries and stored procedure to enhance the overall performance of db operations.

Weakness:-

1)Linq to Sql only works with Sql Server Db.

2)From main object, navigation to foreign key, reference object is not possible.

3)It supports only bottom-up design i.e database to object oriented and not the other way.

Summary :-

It overcome several drawbacks of Ado.Net by providing single uniform type query language to query relational and non relational datastores in obj oriented manner. User friendly object oriented syntax, highly
optimized for MS sql server.