Jan 23 2012

Send an email with a “.ics” appointment as attachment in ASP.NET

Category: .NET | ASP.NET | ASP.NET MVC | C#Bil@l @ 10:06

 

I stumbled the other day by an informative yet simple article for my friend MVP Kris van der Mast (http://blog.krisvandermast.com/) explaining thoroughly how to send an email with an attachment of type “.ics” file that could be loaded automatically into your Microsoft Outlook and get its place among your other appointment seamlessly.

To read more, follow this link: How to send a mail with an ics appointment as attachment with System.Net.Mail

 

HTH,
Regards

Tags:

Jan 10 2012

ASP.NET MVC 4–Display Modes-Mobile Views

Category: Bil@l @ 10:39

With the advent of ASP.NET MVC 4, there has been a major focus on developing ASP.NET MVC applications targeting Desktop and Mobile browsers. The key point to look at is the Display Modes feature that ASP.NET engine makes use of to detect and differentiate between different browsers (mobile and desktop ones) and accordingly serve each browser with the right content or “Views”. I started two days ago playing around with the ASP.NET MVC 4 Developer Preview and faced some obstacles in running an ASP.NET MVC 4 on some Mobile Browser emulators (Opera Emulator, FireFox User agent switcher, etc …). I got them solved by now, read more Smile

To serve different Mobile browsers, ASP.NET MVC needs to be aware of all those mobile browsers in order to recognize that a request is coming from this or that mobile browser in addition to differentiating between mobile and desktop browser requests in general. To keep ASP.NET MVC aware of the different mobile browsers there are online services that you, a .NET developer, can utilize.

  1. The first service is 51degrees.mobi, you can read more about integrating 51degrees.mobi into an ASP.NET MVC 4 application by reading this article: 51Degrees.mobi and ASP.NET MVC 4
  2. The other service is WUFRL.NET, you can read more about integrating WUFRL.NET into an ASP.NET MVC 4 application by reading this article: WUFRL.NET and ASP.NET MVC 4 Display Modes

The above should help you setup the basic framework to start serving Web Content targeting Mobile and Desktop browsers. The next step is to start the actual development and building of the content. A good start might be visiting the ASP.NET MVC 4 Mobile Features whitepaper and go through the sample application explained.

 

HTH,

Regards

Tags:

Oct 4 2011

Microsoft Tech Days 2 - Beirut 2011

Category: Bil@l @ 10:31

Microsoft Tech Days 2 - Beirut 2011

Tags:

Sep 16 2011

Integrate a Parameterized Telerik Report in Visual Studio LightSwitch Application

Category: Bil@l @ 10:35

 

This article is cross posted on my LightSwitchHelpWebsite Blog

Introduction

This installment shows the steps needed to integrate a parameterized Telerik report inside a Visual Studio LightSwitch application.

A parameterized Telerik report is a normal report accepting one or more parameters upon which it will filter the data displayed inside it. The tricky part is centered around the communication between LightSwitch and Telerik report to receive or send parameter values, when the report is being loaded inside a LightSwitch Screen.

Prerequisites

This installment assumes you already have at least a basic knowledge in Telerik reporting. In case you are new or need additional information, you can visit: Telerik Rreporting.

Creating the Report and WCF projects to integrate them with LightSwitch application is also outside the scope of this installment. You can read the following informative articles:

To run the sample code at the end of this installment, you need to have the following installed on your system:

  • Visual Studio Professional or more
  • LightSwitch Tools
  • Microsoft SQL Server 2008 Express or higher
  • AdventureWorks Database is available

Solution

To start with, create a new LightSwitch application and make sure you are viewing it in the “Logical View”:

views 

Right-click “Data Source” and click on “Add Data Source”:

2011-09-15_1342

 

Select “Database” and hit “Next >”

2011-09-15_1345

In your case, you need to select “Server Name” and then select the “AdventureWorks” database. Once done, hit on “OK”.

2011-09-15_1349

Select “PurchaseOrderHeader (Purchasing)” table then enter a name for the “Data Source Name” field. In this case, it is “AdventureWorksData”. Hit “Finish”.

The “Data Source” is now created and should be something similar to the following:

2011-09-15_1352

Now, we need to create a new Screen, right-click on “Screens” folder select “Add Screen”:

2011-09-15_1354

Select “Editable Grid Screen”, as for the “Screen Name” enter a name of your choice and finally select for the “Screen Data” the “PurchaseOrderHeader” Table. Finally, hit OK button.

Press “F5” to run the application:

2011-09-15_1442

Now that the application is up and running. It is time to integrate the Telerik report. Having read the above two articles on using Telerik Reporting in LightSwitch applications, you would have noticed that the integration requires creating a C# Class library to hold the Telerik report and a WCF application to expose it. Assuming both projects are ready, let’s create a Silverlight Custom Control in the LightSwitch application to bring in the Report to display inside a LightSwitch screen.

 

Switch the LightSwitch application to “File View”:

fileview

Add the following library references to both “Client” and “ClientGenerated” projects. If for some reason you can’t see the “ClientGenerated” project, make sure to “Show All Files”.

  • Telerik.ReportViewer.Silverlight

Right-click the “Client” project and add a new “Silverlight User Control” call it “PurchaseOrderReport.xaml”, then make use of a ReportViewer control as follows:

<UserControl x:Class="IntegratingReportsToLightSwitchApp.PurchaseOrderReport"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"     
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
        xmlns:telerikReporting="clr-namespace:Telerik.ReportViewer.Silverlight;assembly=Telerik.ReportViewer.Silverlight"
    d:DesignHeight="300" d:DesignWidth="400">
    
    <Grid x:Name="LayoutRoot" Background="White">
        <telerikReporting:ReportViewer x:Name="myReportViewer" 
                                       ReportServerUri="http://localhost:6963/ReportService.svc"
                                       HorizontalAlignment="Stretch" 
                                       VerticalAlignment="Stretch"
                                       Report="ReportLibrary.Report1, ReportLibrary" />
    </Grid>
</UserControl>

With a Telerik ReportViewer control, you need to specify the following major properties:

  • ReportServerUri: URL for the WCF service hosting the Report class library
  • Report: The fully qualified name of the Report as “Namespace.ReportClassName, AssemblyName”

Compile the application and everything should compile smoothly without any mentioned errors.

Back to “Logical View”, create a new Screen:

2011-09-15_1541

Make sure to select “Details Screen”, then enter a name for the “Screen Name” and finally select “PurchaseOrderHeader” Table and select “Use as Default Details Screen”. Hit OK. The Screen designer opens:

2011-09-15_1543

First of all you notice the existence of “PurchaseOrderHeaderPurchaseOrderID” screen parameter. Since this screen was created as a “Details Screen” meaning that when LightSwitch needs to open this screen it has to provide it with an ID for which the screen would load the header details for. Remember this parameter as we are going to make use of it soon.

Also notice the “Rows Layout” node. Click on the down arrow and select “Custom Control”. Keep the same node selected, on the “Properties” pane inside Visual Studio, locate “Custom Control” field:

2011-09-15_1548

Click on “Change” to select the source of the Custom Control:

2011-09-15_1549

Select the Silverlight User Control that you have created previously, then click on “Add Reference”, finally hit OK. This way you would have set the source of the Custom Control. By default, the Data Context of the newly added User Control is the “Screen” object itself.

Now back to the Screen that contains the editable grid for “Purchase Order Header”, locate the “Purchase Order ID” label, select the checkbox “Show as Link” and select as a “Target Screen”, the “PurchaseOrderHeaderDetail” from the dropdown list:

 2011-09-15_2252

With the last configuration, the “Purchase Order ID” field now shows as a link inside the Grid of data. Clicking the link triggers LightSwitch to instantiate a new instance of the “PurchaseOrderHeaderDetail” screen, the screen which contains the custom control, in our case, the Telerik Report custom user control.

Back to the SilverlightUser Control “PurchaseOrderReport.xaml” code behind:

  1: public PurchaseOrderReport()
  2:         {
  3:             InitializeComponent();
  5:             this.myReportViewer.RenderBegin += new Telerik.ReportViewer.Silverlight.RenderBeginEventHandler(myReportViewer_RenderBegin);
  6:         }
  8:         void myReportViewer_RenderBegin(object sender, Telerik.ReportViewer.Silverlight.RenderBeginEventArgs args)
  9:         {
 10:             var paramValue = " ";
 12:             var dataContext = (IContentItem)this.DataContext;
 13:             var screen = (IScreenObject)dataContext.Screen;
 14: 
 15:             screen.Details.Dispatcher.BeginInvoke( () =>
 16:                 {
 17:                     paramValue = (screen as PurchaseOrderHeaderDetail).PurchaseOrderHeaderPurchaseOrderID.ToString();
 19:                     // Bind the parameters
 20:                     args.ParameterValues["PurchaseOrderID"] = paramValue;
 21:                 });
 23:         }

At line #5, the code is subscribing to the Telerik Report Viewer’s “RenderBegin” event. This event occurs when rendering of the Report begins.

The RenderBegin event handler starts by:

  1. Retrieving the DataContext of the current Silverlight User Control which is of type “IContentItem” (line #12)
  2. Once an instance of “IContentItem” is retrieved, accessing the “Screen” object that this User Control is bound to, could be achieved as shown above at line #13.
  3. Since the code above is executing in a different thread other than that of the Screen, what is needed is to flip execution context thread to that of the Screen and this can be achieved as shown in line #15.
  4. Inside the “BeginInvoke”, the code at line #17, downcasts the Screen object Data Context, to an instance of the “PurchaseOrderHeaderDetail” screen. It then accesses the value of the “Parameter” on that screen using its name, “PurchaseOrderHeaderPurchaseOrderID”
  5. To supply a parameter to the Telerik Report, all you have to do is add to the “ParameterValues” NameValueDictionary a new entry specifying as key the Report’s Parameter Name and as value, the “Purchase Order ID” property located on the Screen object and that has been populated by LightSwitch (being a public parameter) when a Purchase Order’s ID was clicked on screen.

The Telerik report will render with a specific value for the “Purchase Order ID”.

What actually happens is the following:

  1. User clicks a “Purchase Order ID” link on the grid of purchase rders
  2. LightSwitch takes the ID of the purchase order clicked, instantiates a new instance of the “Purchase Order Header Detail” screen passing to its constructor the value of the “Purchase Order ID” as a parameter
  3. “Purchase Order Header Detail” screen starts rendering the Silverlight custom control
  4. At the beginning of the rendering process, the code retrieves the value of “PurchaseOrderHeaderPurchaseOrderID” on the Screen to know what parameter to send to the Telerik Report.

Clicking on any of the purchase orders results in displaying the following Telerik report:

report

 

That’s it for this installment. Telerik reporting is very efficient and rich, combining it with LightSwitch applications, gives you the opportunity to develop complex and useful apps with Visual Studio LightSwitch.

See you in the coming installment :)

HTH,
Regards

Tags: , , , ,

Sep 10 2011

Tips/Tricks: Implementing Silverlight-Converter-Like Behavior in LightSwitch Application

Category: Bil@l @ 21:56

 

 

In Sivlerlight, the concept of a Value Converter is present to help a Control "adjust" the Data coming in from the Source before it gets displayed on the UI layer. In LightSwitch, value converters are not present. Until LightSwitch team decides to allow us to specify not only the Data Binding property but also a Converter instance, the below workaround could help.

The snapshot below represents a "List and Details Screen" for an Appointment Entity together with the Appointment Items related:

 

The "List and Details Screen" displays a list of "All Appointments" stored in the Database. Upon selecting a single Appointment, the Appointment Details + Appointment Items are also shown.

 

Point A: Represents the "Category" field of the Selected Item on screen. 

Point B: Represents a "Data Item" (As LightSwitch calls it) added to the screen. In other words, it is just a Property on the screen.

Point C: A data field placed on the screen details section to show the "Category" of the selected Appointment.

 

Originally, "Category" property in Point C is bound to "Category" field in Point A. This means, whatever is being stored in "Category" field in the Database for a single Appointment, it will automatically show on screen. However, there are some occasions where we want to:

  • Concatenate text as both "Suffix" or "Prefix" to the Data coming from the Database
  • Do a checking if source data is empty to display "Empty" or "None" etc ...
  • etc ...

 

As was mentioned at the beginning of this post, there is no Value Converters in LightSwitch to do the job of manipulating the source data before showing it on screen. Hence, the Screen Property workaround!

The solution goes as follows:

  1. Define a new Property on screen (adding a new Data Item) call it "Category" as shown in Point B
  2. Bind the field "Category" in Point C to property "Category" in Point B
  3. Implement the InitializeDataWorkspace method. This method is called just before the screen data is retrieved. In the body of this method, initialize the "Category" property on screen to whatever value you prefer. In our case "None".
  4. Implement the Appointments' Query SelectionChanged event handler. This handles the event of changing selection in the list of "Appointments" on screen.

 

"Show me the green" :). The code follows:

 

        partial void AllAppointments_InitializeDataWorkspace(List<IDataService> saveChangesTo)
        {
            // Initialize the property to "None"
            this.Category = "None";
        }
        partial void Appointments_SelectionChanged()
        {
            // If there is no SelectedItem return
            if (this.Appointments.SelectedItem == null)
                return;
 
            // Initialize Category to whatever is returned from Database
            this.Category = this.Appointments.SelectedItem.Category;
 
            // If the data stored in Database is Null or Empty, then set the Category property
            // value to "None"
            if (String.IsNullOrEmpty(this.Appointments.SelectedItem.Category))
            {
                this.Category = "None";
            }
        }

The code is self-explanatory.

 

That's it. When the screen loads, if the "Category" field of the SelectedItem i.e. selected Appointment is Null or Empty, it gets displayed by a value of "None".

 

HTH,

Best Regards

Tags: , ,

Sep 9 2011

LightSwitch Code Snippets

Category: Bil@l @ 09:28

I found few LightSwitch code snippets that I would like to share with you:

 

LightSwitch Code Samples

Tags: , ,

Sep 8 2011

Exploring LightSwitch Architecture

Category: Bil@l @ 10:30

Source: http://msdn.microsoft.com/en-us/lightswitch/gg491708

 Exploring LightSwitch Architecture

Go deeper and explore the architecture of a LightSwitch application. LightSwitch applications are built on a classic three-tier architecture, on top of existing .NET technologies and proven architectural design patterns. See how LightSwitch works under the covers.

LightSwitch Architecture


Tags: , ,

Aug 11 2011

Visual Studio LightSwitch Training Kit

Category: Bil@l @ 09:38

Now  you can download the Visual Studio LightSwtich Training Kit: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=23746

 

Enjoy it!

Tags: ,

Jun 14 2011

Debugger Canvas

Category: Bil@l @ 11:40

Debugger Canvas is a new user experience for the debugger in Visual Studio Ultimate. It pulls together the code you’re exploring onto a single pan-and-zoom display. As you hit breakpoints or step into code, Debugger Canvas shows just the methods that you’re debugging, with call lines and local variables, to help you see the bigger picture.

 

Download and learn more on Debugger Canvas at DevLabs: Debugger Canvas

 

HTH,
Regards

Tags: , , , , ,

Jun 9 2011

How to Install PHP 5.3 FastCGI on Windows 2008 IIS 7 / 7.5

Category: Bil@l @ 13:48

I have tried recently to install PHP 5.3.6 over IIS 7.5 running on a machine of Windows Server 2008 R2. While checking out the instructions on how to properly do that, I passed by those two articles that I would like to share with you, in case you are in the same position of installing PHP over IIS 7 or 7.5:

 

 

Hope this helps,

Regards

Tags: , , ,