Tuesday, October 20, 2009

Sell Used Zumex For Sale

Business Application example for Silverlight 3. NET and RIA Services. - Part 4: SEO, export to Excel and Excluding browser

Part 4: SEO, export to Excel and Excluding Browser

This exercise requires (everything is free and will remain):

1 - VS2008 SP1 (including Sql Express 2008)
2 - Silverlight 3.0
3 -. NET RIA Services July'09 Preview (for this exercise, this is optional)

The original English is available here: Part 4: SEO, Export to Excel and Out of Browser
The online application is available here: http://www.hanselman.com/abrams/ # / Home


You can download the complete solution here: MonApplication.zip

Today we will discuss the various views and logic of our application. Different views



Now, let's put a different view to our application. One of the key elements to achieve different views are deep links. See how to add it to our application.



First, we need to add a Textbox to show the deep connection to each of our great employees. To do this, add the following code just after the closing tag of DataForm .



Add event SelectionChanged our Datagrid.


And
's login in the code behind ...





Now we must make the page smart enough to know this deep connection :



Now run the application, make a copy and paste this address in a browser that will show exactly this record.



Ok, now that we have a deep connection, what can we do with it? Well, we can send this link by email, instant messaging, include it in a blog, etc..

But what if we want the search engines are able to find records in our site? It turns out there for this a standard format called sitemap ( http://sitemap.org/ ). You can see a concrete example here: http://amazon.com/robots.txt .

To add it to our application, do a right click on our web project, Add New Item, Search Sitemap.



This adds robots.txt and sitemap.aspx to our project. Before proceeding further, we will use the Default.aspx page your homepage. To do this, we will make a copy / paste the entire contents of the file in BusinessApplicationTestPage.aspx Default.aspx. Once done, check that the first two lines of the latter are well read:



Then go to Project , MonApplication.web Properties ... Make sure you have MonApplication.web highlighted.



Finally, go to the Web tab and delete the field Start Action - Specific Page



This in order that the application uses rather Default.aspx page instead BusinessApplicationTestPage.aspx your homepage.
Finally, changing the method dataGrid1_SelectionChanged to no longer refer to BusinessApplicationTestPage.aspx as follows:



This being done, see how to customize the file sitemap.aspx. Note that we use a new ASP.NET datasource control which is designed to work with the class DomainService. This gives us access to the server to the same logical application of ASP. NET and Silverlight

Let us in sitemap.aspx file to add the following code:



One last thing to do is to allow the server side to access the ID of the employee. In Default.aspx.cs , add:


Now, right clicking on sitemap.aspx , made View in browser.



And here's the result:



Change the address by Robots.txt and you should get this:



If you copy and paste an address sitemap, you can see that it works perfectly.



Ok, this works perfectly. Now, search engines can find any entity in our application. But that search engines will find it really like that? Search engines are powerful for analyzing html, but dynamic content such as those we have here or Ajax sites are more difficult to treat for them. The art of this type is called SEO Optimization for search engines (SEO, Search Engine Optimization in English, we will use here the term SEO ).

Let us in our Default.aspx page . Since we have modeled our application logic in a class DomainService, it is easy to add a standard HTML view. Just add the following code in the tag object in Default.aspx.



We also need a method domain GetSuperEmployee to support this code. So back in our SuperEmployeeDomainService.cs and add:


Now we must turn our Silverlight browser because search engines do not have this plugin.



and perform a refresh the page on a deep bond ...



Rather nice, eh? Now the search engines (with or without Silverlight) can access the data.

But does this work really? Try the following searches:

Super Alfred Employee (Yahoo) Super

Used Alfred (Google)

Well, this is a server view, let's try a different view on the client side ... We will export this data in Excel!

To do this, we will add the file excelTemplate.txt to the project root attacks. (You can download this file here: http://pagesperso-orange.fr/aristidi/files/excelTemplate.txt )

Then we'll add a button in our file Home.xaml to export to Excel:



Finally, we will write the Excel file ... notice that everything is secure, the user must select the destination file. The developer will no longer have access to the site file. Now in our Home.xaml.cs file, add the following method:



Finally, let's run the application again (after having thought to reactivate Silverlight in your browser).




This
create an Excel file where we have chosen.



Let's open it and do a little formatting.



And now for the final out of the browser ...

's select properties on the client application:



Editons parameters:



Let's start the application. Perform a right click and select "Install Application ...."






Let's add a link on the desktop ...



And it remains for us to launch the application!

Thursday, October 15, 2009

Driver For Dual Mode Camera

Business Application example for Silverlight 3. NET and RIA Services. - Part 3: Authentication

Part 3: Authentication

This exercise requires (everything is free and will remain):

1 - VS2008 SP1 (including Sql Express 2008 )
2 - Silverlight 3.0
3 -. NET RIA Services July'09 Preview (for this exercise, this is optional)

The English original is available here: Part 2: Rich Data Query
Application Online is available here: http://www.hanselman.com/abrams/ # / Home

You can download the complete solution here: MonApplication.zip

Today we'll talk authentication.

's note: this session is only a basic understanding of the opportunities offered. NET and Silverlight RIA Services. A further session will be a future article.

Business applications often have access to sensitive data. It is important that you can audit, restrict and control access to your data. Let's see how. NET and Silverlight RIA Services operate to achieve this. Using the model

Silverlight Business Application is super easy ... by default it is connected to the authentication system ASP. NET offers a customizable user management system.

I will demonstrate using forms authentication, you can also use Windows authentication by a slight modification.



For this demo, I'll do demonstration of creating a new user, but if you already have a user base, you can use.

's note: for this session, remember to start the application with CTRL + F5.











Note that we have rules for functional validation.

Now the application knows who you are ...



Note that everything on the user experience on the client is fully customizable as all source code is included in the project. But the default template is not bad for many applications.

Now that we are connected, do something about these user data. For example, let us ensure that only registered users can access data from great employees. Editons class SuperEmployeeDomainService (SuperEmployeeDomainService.cs) on the server to add the attribute RequiresAuthentication . There are other attrubuts as roles and the ability to manage in your code if you want.



Now if we run the application and we do not we connect, we have no data. Note that this validation is done client side for a rich user experience and once again on the server to ensure security.



When we are connected ...



... and when we're not.

Is A Sewn In Good For Ypur Hair

exercises available in PDF

I do not know about you, but sometimes when I learn something on my PC, I like having the book on his lap. So, I started converting articles in pdf format. For now, only Chapter 2 is available. I would put the asser or Chapter 1 online quickly. Then, as and when I publish the translations on both this blog and in both pdf.
Well, actually it was not long, the first 3 chapters are available in PDF. To download
year in pdf format, click on the link suitable to the right ...

Wednesday, October 14, 2009

Go Bottomless Topless

Business Application example for Silverlight 3. NET and RIA Services. - Part 2: Data Access Application Example

Part 2: Data Access

This exercise will lead us to access data with Silverlight. This exercise requires

(everything is free and will remain):

1 - VS2008 SP1 (including Sql Express 2008)
2 - Silverlight 3.0
3 -. NET RIA Services July'09 Preview (for this exercise, this is optional)

The English original is available here: Part 2: Rich Data Query
The online application is available here: http://www .hanselman.com / abrams / # / Home

You can download the complete solution here: MonApplication.zip

First, retrieve the base northwnd.mdf available here: northwnd.mdf
Let us place there in the directory MonApplication.web / AppData.


conducting a right-click MonApplication.web and add a new item.




Come in and select Data ADO.NET Entity Data Model and call it Northwind.edmx .



A new window pops up asking us to choose what kind of model we want. Select Generate from database .




In the window option in Data Source, select and choose Change Microsoft SQL Server Database File.




boutonBrowse click on the Database File Name and select the base northwnd.mdf .





We can click the button Test Connection to make sure everything goes smoothly.



Let's click OK , and a new window appears. Next click on .



On the next window, we will select the table that interests us, namely, here, you must check SuperEmployees (dbo) . Validate our choice by clicking Finish .



At this stage it is necessary to compile the solution again to take everything into account. To do this, do a right click on our solution and select Build Solution . Here, we created our data access layer.





Now, once everything is in place, we can talk about access to data. Almost all business applications need data access. We will first start with the web project. For this example, I used an Entity Framework data model, but works fine RIA Services with any type of data from objects or XML, web services in Linq to Sql.

Now the question is: how do we access this data from our Silverlight client? Traditionally, most enterprise applications start with a model of two-thirds. This creates many problems in terms of flexibility and scalability ... Moreover, this does not simply with the Silverlight client architecture / web.



As a result, developers are moving more in the world n-tier. It is very easy. NET RIA Services to create n-tier services that are flexible and scalable built on WCF and ADO.NET Data Services.



these services. NET RIA model the logic of our application UI-third and encapsulate access to our various data such as data POCO (Plain Old CLR Object), as Azure Cloud Services , S3, etc.. via REST, etc.. One great feature of this is that you can migrate a SQL Server database to a remote service without Azure have to change anything in the application logic.

Let us now how it is easy to create these services RIA.

conducting a right-click the server project (MonApplication.web) and select add a new class Domain Service. Call the new class SuperEmployeeDomainService.cs .





In the wizard, select our data source (here NORTHWNDEntities ). Note that we could choose a class LINQ2SQL a POCO class, etc.. Let us also check the boxes Enable Client Access SuperEmployees, Enable editing Generate and associated classes for MetaDir .



In the newly created class, we have a draft of all methods to access our data. We should of course modify our application. For the next steps we will use the method GetSuperEmployees (), so we'll have to modify it as follows:








Now basculons on the client side. First, compile the solution again to client side to access directly. These projects are linked.

's perform a drag and drop the DataGrid the toolbox in our view Home.xaml , just after the TextBlock , before closing StackPanel.



's modify the xaml and then added as follows:





Now in code behind (ie, in the file Home.xaml.cs ), add the clause

using MonApplication.Web . Note that

Interestingly MonApplication.Web that is defined on the server ... We can now access the proxy server client DomainService locally.
























In line 1 we created our SuperEmployeeDomainContext ... This is the SuperEmployeeDomainService client side. Note the naming convention here.

On line 2, we bind data to datagrid that we created earlier. Finally, line 3, we load the data using the method GetSuperEmployees () we defined on the server.
Note that it is all done asynchronously and we do not have to worry about the complex world of asynchronisation.



And here's the result! We have all our starters, but in the real world, do not we want to paginate and ensure that the server sort and filter the results? Let's see how.

First, completely erase the lines of code that we added in code behind (ie, the three lines in our file Home.xaml.cs). Then, in our view Home.xaml , add a DomainDataSource by dragging and dropping from toolbox.



Then publish the code to be inserted. First add the namespace in our application.


















In 1, we have the game namespace.

In 2, we call the method GetSuperEmployeesQuery DomianContext the specified 4.

In 3, we set the size of the load 20. This means that we will download data every 20.

Now let's tie it all in DataGrid and display a small loading indicator.

To do this, we first add a namespace to access the progress indicator.



Then we will modify our views as follows:

Note: when doing a drag and drop a control on the view, the namespace is automatically added. So let's add the DataPager in this way.


At line 27, we see the Datagrid which is linked to property DDS.Data. Then we see a DataPager line 31, which is linked to the same data source. This we lavish interface paging.
line 31 Note that we choose to display ten records at a time. Finally, we include all in a control Activity to show progress.

What's good with the controls Activity the Datagrid and DataPager is that they can be used with any data source as WCF services, REST services, etc..

Support F5 and see the result ...



Note that we load 20 records at a time, but we do not only display 10. So if we go one page, it will be managed solely by the customer, but if we move more, we make a call server and we upload more than 20 recordings. Also note that sorting works well. And where is the code that handles the sorting? Have we wrote the code on the client side or server? Not at all, this is the magic of Linq, it all happens automatically and the result falls.

We can already add a group function. Pou this we will first add a namespace as follows:



Then we joutons code:



And here's the result:



Now add a filter. First, add a Label and TextBox .



Finally, add these filters to our DomainDataSource:



When we press F5, we get a filter box and when you type something in it We're doing a server side filtering of results.



Now, suppose we want to create an input field automatically rather than a simple text box. The first thing we must do is get all possible origins. Note that we obtain from the server (the client may in fact not all have to the extent we load the data in groups of 20, we do pagination, etc.).. To do this, we'll add a method in our DomainService. In the file SuperEmployeeDomainService.cs , first add this class:




Then the method in the class that returns SuperEmployeeDomainService Origins:



In our view Home.xaml , replace the TextBox by AutoCompleteBox like this:



Then add the code to load it all behind:



Let's start with the F5 and everything we should get this:



OK to update data

Now, we certainly have an application that can display data in a sophisticated business applications but also require d authorize the update data. Let's see how. First, replace the xaml below, under DomainDataService. This will provide us with a beautiful view Master-detail.

(Please go here for the full text of Home.xaml ).
Now, run the application with F5 and then we get this:



If one tries to modify a record in the detail view, we see an asterisk notifying us that this entry is amended and what should be returned to the server. If you edit one or more entries and you cancel these changes, the asterisk disappear.



Now we must connect the "Send" button. To do this in your file Home.xaml.cs , add the following delegate:



First, we must validate the item that is being edited, then we just send the changes. These changes are grouped by lot and sent to the server. Then our Update method is called. Note that the asterisk disappears.

That is done, but what about the validation data? Base, we have a validation type level (if it is an integer, a string, etc..). For example, if we fill the EmployeeID field with a string, we get an error (Note: for this to work, you must run your project without debugging by pressing CTRL-F5).



Now, we go a little further. To do this, we edit SuperEmployeeDomainService.metadata.cs on the server. It is important to do this on the server, so the system performs all the checks in the first instance to provide a good experience user and a second time on the server to verify data integrity. When your Update method is called on your DomainService, you can be sure that the validation was made. Here

what we can do validations:



Now we must rebuild the solution for these changes to take effect. Launching the application with CTRL-F5 and we see our validation rules that work.


Note that we can navigate between the errors and that the focus is on the error selected.

So much for the validation data. But what is it about adding data?

To do this, we will use the new child window ( ChildWindow ) Silverlight 3.

Make a right click View, Add ..., New Item . Select Silverlight Child Window and name AddNewWindow .



Lions this window to a button to enable its display. First, add a button to the main form (Home.xaml) to display the new window :



Then the lions-in code behind ( Home.xaml.cs ):

First, add the clause Using:





Then write our event as follows:







And here's the result:



We see this new window is already equipped with an OK button and a Cancel button that is already functional (although they do not make much). We have only to add a DataForm . For this, we have only to resume as we have defined for the update data in our view master / detail. (You can download this file here .)



Now behnind in code, we must proceed with these steps. First, not omit to add our calluses Using.

We will put this class declaration:




Initialize the builder ...




And manage the OK button:


is the result:



Well, now we will reflect this change locally ( Home.xaml.cs ):

First, we will subscribe event AddNewButton_Click an event that will detect the close window AddNewWindow:


And we will create the delegate:




And voila! Our application is fully functional. Note that the changes are passed on to the remote database, once the window closed AddNewWindow, we have to click the send button.