Sunday, April 17, 2011

New Features Announced for Silverlight 5

1) Improved media support and rich UI capabilities:

Hardware Decode and presentation of H.264 improve performance for lower-power devices to render high-definition video using GPU support.

TrickPlay allows video to be played at different speeds and supports fast-forward and rewind. At up to twice the speed, audio pitch correction allows users to watch videos while preserving a normal audio pitch.

Improved power awareness prevents the screen saver from being shown while watching video and allows the computer to sleep when video is not active.

Remote-control support allows users to control media playback.

Digital rights management advancements allow seamless switching between DRM media sources.

 

2)Building next-generation business applications:

Silverlight 5 text (bottom) has improved clarity.

Fluid user interface enables smoother animation within the UI. Inter-Layout Transitions allow developers to specify animations to apply when elements are added, removed or re-ordered within a layout. This provides smoother user experiences when, for example, items are inserted into a list.

Text improvements make it possible to build rich magazine-style text layouts:

  • Multicolumn text and linked text container allow text to flow around other elements.
  • Tracking/leading set precisely how far apart each character is for full creative control.
  • Text clarity is improved with Pixel Snapping.
  • Text layout performance is significantly improved.
  • OpenType support has been enhanced.

Support for Postscript vector printing enables users to create reports and documents, including the ability to create a virtual print view different from what is shown on the screen.

Applications can now work the way users expect with added support for double-click and Combobox type ahead.

Model View ViewModel (MVVM) and Databinding enhancements allow more work to be done more easily via XAML:

  • Debugging support now allows breakpoints to be set on a binding, so you can step through binding failures.
  • Implicit DataTemplates allow templates to be created across an application to support a particular type by default.
  • Ancestor RelativeSource allows, for example, a DataTemplate to bind to a property on the control that contains it.
  • Binding in style setters allows bindings to be used within styles to reference other properties.
  • The DataContextChanged event is being introduced. Markup extensions allow code to be run at XAML parse time for both properties and event handlers, enabling cutting-edge MVVM support.
3) Networking and Windows Communication Foundation enhancements:
  • Reduced network latency by using a background thread for networking.
4) Silverlight 5 performance improvements include:
  • Reduced network latency by using a background thread for networking.
  • XAML parser improvements that speed up startup and runtime performance.
  • Support for 64-bit operating systems.

 

5) Graphics improvements:

  • Graphics Processing Unit (GPU) accelerated 3-D application programming interface (API) provides rich graphics on the Web for building advanced data visualizations and rich user experience (UI).
  • Immediate mode graphics API allows direct rendering to the GPU.
  • Hardware acceleration is enabled in windowless mode with Internet Explorer 9.
Silverlight 5 extends features of the ‘Trusted Application’ model to the browser for the first time. These features, when enabled via a group policy registry key and an application certificate, mean users won’t need to leave the browser to perform complex tasks:
  • Host HTML content as a Web browser control within the Silverlight application. HTML pages, such as help content or e-mail, can be integrated within the application.
  • Read and write files to the user’s My Documents folder, making it easier to find media files or create local copies of reports.
  • Launch Microsoft Office and other desktop programs. Users can open Microsoft Outlook and create an e-mail message, or send a report to Word utilizing the power of Office.
  • Access devices and other system capabilities by calling into application COM components. Users can access a USB security card reader or a bar-code scanner.
  • Enjoy full keyboard support in full screen, which enables richer kiosk and media viewing applications.
  • Call existing unmanaged code directly from within Silverlight with PInvoke

Thursday, February 3, 2011

SQL Script for getting last day of the month

Created a sample script for showing last day of the month..

SELECT     (CASE   MONTH(GETDATE())
                WHEN 1 THEN 31
                WHEN 2 THEN (CASE YEAR(GETDATE())%4 WHEN 0 THEN 29 ELSE 28 END)
                WHEN 3 THEN 31
                WHEN 4 THEN 30
                WHEN 5 THEN 31
                WHEN 6 THEN 30
                WHEN 7 THEN 31
                WHEN 8 THEN 31
                WHEN 9 THEN 30
                WHEN 10 THEN 31
                WHEN 11 THEN 30
                WHEN 12 THEN 31
        END) AS LastDayOfMonth

 

Thursday, September 16, 2010

Firefox addon for View state size of ASP.Net page

ViewstateSize is a Firefox add-on which displays the size of the viewstate on the current asp.net page you are seeing.

Details about this add-on is available in the following link

https://addons.mozilla.org/en-US/firefox/addon/5956/

Sunday, June 13, 2010

COM Interop with silverlight 4.0

Silverlight 4 has a feature for accessing COM components which is installed /available in client machines.
I will walk through how to access a Excel application through silvelight .
For developing this application , we need VS 2010 , Silverlight 4 SDK.
Create a silverlight project using VS2010
image
Take the properties of SL project under silverlight tab for enabling Out Of Browser support.
image
We need to check ‘require elevated permission’ under Out of browser settings button.
Now am creating a datagrid(dgName) in MainPage.xaml and binding some data.
below code is used for setting datasource to datagrid.
private void UserControl_Loaded(object sender, RoutedEventArgs e)
       {
           ModelClass m = new ModelClass();
           dgName.ItemsSource = m.SetDataSource();
       }
image
preview : data grid.
Now i am putting a button which invokes ‘excel’ application and write all the data from the above data grid to the excel app.
private void Button_Click(object sender, RoutedEventArgs e)
       {
           dynamic excelObj = AutomationFactory.CreateObject("Excel.Application");
           excelObj.Visible = true;
           // add a workbook to the instance  
           dynamic workbook = excelObj.workbooks;
           workbook.Add();
           dynamic sheet = excelObj.ActiveSheet;
           sheet.Name = "Sample Sheet";
           // get the active sheet  
           dynamic cell = null; int i = 1;
           // iterate through our data source and populate the excel spreadsheet 
           foreach (ModelClass item in dgName.ItemsSource)
           {
               cell = sheet.Cells[i, 1]; // row, column   
               cell.Value = item.ID;
               cell.ColumnWidth = 25;
               cell = sheet.Cells[i, 2];
               cell.Value = item.Name;
               i++;
           }
       }
we are using AutomationFactory ( static class under System.Windows.Interop) for invoking Excel app . we can use this class for invoking apps like ‘Outlook’ , ‘Text to Speech’ COMs’.
‘dynamic’ is object whose operations will be resolved at run time.Intellisence will not be available while coding using ‘dynamic’ object.
image
I am attaching a sample application , can be download from here

Sunday, June 6, 2010

Bing Map integration with ASP.Net



Describes a sample application for showing your location using bing map api.
Step 1 .
Create an ASP.Net web site.
Step 2.
Include <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script> in header part of aspx page.
Include these functions for initializing and locating bing map
<script type="text/javascript">
      var map;       
      function LoadMap() {
          map = new VEMap('myMap');
          map.LoadMap();
      }
      function StartGeocoding(address) {
          map.Find(null,    // what
                      address, // where
                      null,    // VEFindType (always VEFindType.Businesses)
                      null,    // VEShapeLayer (base by default)
                      null,    // start index for results (0 by default)
                      1,    // max number of results (default is 10)
                      null,    // show results? (default is true)
                      null,    // create pushpin for what results? (ignored since what is null)
                      null,    // use default disambiguation? (default is true)
                      null,    // set best map view? (default is true)
                      GeocodeCallback);  // call back function
      }
      function GeocodeCallback(shapeLayer, findResults, places, moreResults, errorMsg) {
          // if there are no results, display any error message and return
          if (places == null) {
              //alert((errorMsg == null) ? "There were no results" : errorMsg);
              return;
          }
          var bestPlace = places[0];
          // Add pushpin to the *best* place
          var location = bestPlace.LatLong;
          var newShape = new VEShape(VEShapeType.Pushpin, location);
          //var desc = "Latitude: " + location.Latitude + "<br>Longitude:" + location.Longitude;
          newShape.SetTitle(bestPlace.Name);
          map.AddShape(newShape);
      }
      function locate()
      {
        var obj= document.getElementById('txtAddress');
        if(obj !=null)
        {
        LoadMap();
        StartGeocoding(obj.value);
        }
      }
</script>
Step 3 .
Create a div area for displaying map control.
add a text box for accepting address and a button for invoking locate() JS function included in the page.


Sample application can be downloaded from here

Monday, May 31, 2010

Creating a Basic Application Using the Silverlight Map Control





Create a Silverlight Project

To begin, create a Silverlight project in Visual Studio.
  1. Open Visual Studio 2008.
  2. Select File the main menu.
  3. Select New, and then Project from the menu.
  4. In the New Project dialog box, under the language of your choice (for example, Visual C#), select Silverlight.
  5. Select a Silverlight Application from the available templates and then click OK.
    clip_image002
  6. When asked, make sure the Host the Silverlight application in a new Web site option is checked. Because of URL access restrictions in Silverlight, your Web page must be hosted using the HTTP scheme for it to be able to access Bing Maps tiles. For more information about Silverlight URL access restrictions, see http://msdn.microsoft.com/en-us/library/cc189008(VS.95).aspx.
    clip_image003
Display a Map

Next, reference the map control dlls in your project and display the default map in your application.
  1. With the Silverlight project selected (not the Web project), select Project then Add Reference from the Visual Studio main menu.
  2. In the Add Reference dialog box, click the Browse tab.
  3. Browse to the location of your Bing Maps Silverlight Control installation. Open the Libraries folder, select the Microsoft.Maps.MapControl.dll and the Microsoft.Maps.MapControl.Common.dll files and click OK.
  4. Add the map control assembly to MainPage.xaml of your Silverlight project by creating a namespace in your UserControl. The MainPage.xaml now looks like this:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl">
<Grid x:Name="LayoutRoot">
</Grid>
</UserControl>
  1. Once the map control assembly is referenced, then you can add the map element <m:Map/> to your page. Put this element within the Grid.
  2. To authenticate your use of the map control, you also need to set credentials. To do this, add a CredentialsProvider attribute to the <m:Map/> element. Set the CredentialsProvider attribute to the Bing Maps Key that you obtained from the Bing Maps Account Center. Your final MainPage.xaml looks like this:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl">
<Grid x:Name="LayoutRoot">
<m:Map CredentialsProvider="your key"/>
</Grid>
</UserControl>
  1. Run your Silverlight Map Control application to display a default map.
Change the Map Mode using XAML

To customize the map or other UIElements, you can set properties in your MainPage.xaml file.
  1. To change the mode, or style, of the map, set the Mode of the map element to “Aerial”. Your MainPage.xaml now looks like this:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl">
<Grid x:Name="LayoutRoot" Background="White">
<m:Map CredentialsProvider="your key" Mode="Aerial" />
</Grid>
</UserControl>
Now run your project to see the map in Aerial mode.
Change the Map Mode using C#

Alternatively you can use Visual C# to change the map mode.
  1. Start by giving your map element a name so that you can access this element from within C#. Your MainPage.xaml will look like this:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl">
<Grid x:Name="LayoutRoot" Background="White">
<m:Map CredentialsProvider="your key" Name="myMap" />
</Grid>
</UserControl>
  1. Then in your MainPage.xaml.cs file, reference the map control namespace with a using statement.
  2. Finally, set the map mode when the MainPage is constructed. Your MainPage.xaml.cs file now looks like:
using System.Windows.Controls;
using Microsoft.Maps.MapControl;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
myMap.Mode = new AerialMode();
}
}
}
  1. Now run your project to see the map in Aerial mode.

You can download sample application Click here

Sunday, May 9, 2010

Methods for Debugging SQL Server queries

 

 

There are three ways to debug SQL Server 2005 queries

  • Direct DataBase debugging.
  • Application debugging
  • Debugging from a DB project

Debugging a Stored Procedure via Direct Database Debugging
Direct Database Debugging is the simplest way to debug a SQL Server 2005 stored procedure. From Visual Studio's IDE you can opt to step into a stored procedure and then step through each of its statements one at a time, inspecting and changing T-SQL variables and parameters within the stored procedure. The download at the end of this article includes a SQL Server 2005 Express Edition version of the Northwind database. I added a stored procedure called DoThings that takes a @CategoryID parameter as input and then displays all products in that category whose price is greater than the average if at least 25% of the products in the category cost more than the average. If less than 25% of the products cost more than the average, then all of the products in the category that cost less than the average are displayed. A silly stored procedure for sure, but it has a number of T-SQL statements and variables and an input parameter, all of which will help illustrate some of the debugging features.

To step into the DoThings stored procedure, navigate to the Server Explorer window, drill down into the stored procedures, right-click on the DoThings node and choose the "Step Into Stored Procedure" option from the context menu. (Note: SQL Server debugging support is only available in the Team Systems and Professional editions of Visual Studio.)

This will start the debugger and execute the stored procedure. Since DoThings expects a @CategoryID value passed in, a dialog box prompts us to provide this value. Enter the value 1 and click OK.

Execution will start at the first statement. You can step from statement-to-statement using the Step Into or Step Over commands (F11 or F10 on the keyboard, respectively), as well as add parameters and variables to the Watch window. The screenshot below shows the stored procedure while being stepped through. The yellow arrow in the margin in the left indicates what statement is currently being executed. The Watch window shows the values and types of @CategoryID and @AvgPrice.

After the stored procedure completes, the results can be viewed through the Output window.

As you can see, Direct Database Debugging is very easy to launch, use, and understand. Simply right-click on a stored procedure from the Server Explorer, choose the "Step Into Stored Procedure" option, and you're off and running.

Debugging a Database Object from a Running Application
Direct Database Debugging makes it easy to debug a stored procedure directly from within the Visual Studio IDE. In some cases, however, we would rather start debugging a database object when it is called from an ASP.NET application. This would allow us to better understand when a particular database object was invoked and its state.

This style of debugging is referred to as Application Debugging. To use this style of debugging we need to perform the following steps:

  • Add breakpoints to the database object(s) that you want to debug. A database object will only be debugged if it contains a breakpoint. For example, you cannot "Step Into" a stored procedure from application code that calls the stored procedure. Rather, you must explicitly set a breakpoint within the stored procedure itself.
  • Configure the application to debug SQL Server objects. As we will see shortly, this is as simple as checking a checkbox.
  • Update the connection string to disable connection pooling. Connection pooling is a performance enhancement that allows an application to connect to a database from an existing pool of connections. This feature, if enabled, does not correctly construct the debugging infrastructure needed on the connection taken from the pool. Since connection pooling is enabled by default, we must update our connection string to disable connection pooling during the timeframe that application debugging is being used. (After you've completed debugging the SQL Server objects via application debugging be sure to reinstate connection pooling.)
Let's tackle each of these steps one at a time.

First, open the DoThings stored procedure in Visual Studio and set a breakpoint on the first statement (DECALRE @AvgPrice money). One task down, two to go!

To configure the ASP.NET application to support SQL Server debugging, right-click on the Project name in the Solution Explorer and choose the Property Pages from the context menu. This will bring up the dialog box shown below. Go to the Start Options tab and check the "SQL Server" checkbox in the Debuggers section. Two tasks down, one to go!

Lastly, we need to update the connection string used by the application to disable connection pooling. To accomplish this simply tack on the attribute Pooling=false to you existing connection string. Assuming the connection string information is defined within Web.config's <connectionStrings> section, you would update the connection string value like so:

<connectionStrings>
    <add name="NorthwindConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;User Instance=True; Pooling=false" providerName="System.Data.SqlClient"/>
</connectionStrings>

All three tasks have now been completed! To test the application debugging, create an ASP.NET page that invokes the DoThings stored procedure. The demo available for download at the end of this article has such a page. When debugging the ASP.NET application and visiting this page, the breakpoint in the stored procedure is hit and control is delegated to the debugger. Once in the debugger we can step through the stored procedure's statements and view and edit the parameter values and variables through the Watch window, just like with Direct Database Debugging.

 

This post is based on http://blogs.msdn.com/sqlclr/archive/2006/06/29/651644.aspx and 4guysfromrolla