|
Comments
|
Today's Top SOA Links
Features Enterprise .NET for Smart Devices
Enterprise .NET for Smart Devices
Jan. 1, 2000 12:00 AM
If you want to extend your existing systems as well as your knowledge of .NET development while building solutions for smart devices, the upcoming .NET CF (Compact Framework) and SDE (Smart Device Extensions) are definitely the way to go. In this article we provide an example of how to implement a mobile application that can work as an extension to your existing systems, and also show you how to extend your knowledge of .NET development. It's perhaps more true than ever that mobile solutions rarely stand alone. Most consumer-oriented applications are created to work in an offline or disconnected mode, but for enterprise solutions the increasing connectivity of new devices opens up enormous possibilities for online and "sometimes connected" applications as well. When looking at real-world business scenarios and the capabilities of current mobile devices, it's obvious that the options are greater than just offline or online. Specific user requirements such as "how often?" and "at what bandwidth?" should determine where on the scale from offline to online we need to be (see Figure 1). The more a mobile application is connected, the thinner it can be from an application logic and local storage perspective. The less it's connected, the higher the demand on the application logic and local storage. A typical online mobile application is a Web application targeted at smart device browsers like Internet Explorer for Pocket PC. With a Web application there are no deployment issues for the device, as the browser is already in place. However, most other connectivity options (from "auto-connected" all the way to "never connected") require you to have a custom application running on the device. The need for connectivity also implies that we're most often talking about extending existing systems to anyplace. Many workers are currently tied to a desk with a PC on a wire. They would like to be free to go wherever they want, yet still be able to perform their duties. Is it asking too much to help those poor people out?
Consider Some Examples
Another issue is how we can help those workers get the new tools of the trade. What if we could use the same knowledge that we already have in building our enterprise solutions? In the not too distant future, most of those solutions using Microsoft technology will be developed for .NET, and therefore it would be great if we could extend .NET and .NET development skills to build those solutions for mobile devices. As you may already know, you'll soon be able to do just that.
Build a Business Case
First of all, since time is money, we want to save time. By saving time we can get an instant payback on the investment in most mobile solutions. We can save time for the mobile worker, and most probably also for the back-office personnel who now enter submitted paper data into a system. Perhaps most importantly, we could also save the time between data entry and data usage. For example, if the time reported was submitted each day instead of each week, we could expedite invoices related to that time. Second, we'll collect the data at the source, gaining speed in our business and improving data quality. Writing data on paper, then passing it to someone else to read and enter into a system is probably the most certain way to achieve poor-quality data. Higher quality most often translates to saved time, and also to improved relationships with customers, partners, and even employees. What we're trying to say is that if you want to build a successful mobile solution, do your homework document the business case behind the solution. Most often, if you just spend some time thinking it through, it's not very hard.
Technology Overview
.NET CF is a subset of the full .NET Framework. Careful thought has been put into selecting the classes that make the most sense on a mobile device, taking into account the smaller footprint required on devices and the accompanying memory and performance restrictions. It includes a CLR targeted for smart devices. SDE is a set of extensions to VS.NET that enable you to build applications for the .NET CF. The extensions include profiles that customize VS.NET for smart device development. For example, when targeting the .NET CF, you get IntelliSense for the supported classes and only supported controls are available in the toolbox. For enterprise developers, this means that we'll now get back to the state where there's a single tool set for building applications for PCs and smart devices like Pocket PC and the coming SmartPhone 2002.
C# or VB.NET?
However, we think that all enterprise .NET developers will have to manage development in both C# and VB.NET. Various projects will be run using each, and we think that the choice will most often be made in relation to historical issues rather than technical issues like performance or productivity, or even issues like speed of development and ease of maintenance. Traditional Visual C++ developers and even Java developers will probably select C# as their premium choice, and we think that even Java developers converting to C# will have a less painful migration than Visual Basic 6 developers will have converting to VB.NET. The interesting part of .NET is not the languages, but the framework. Despite the excellent language interoperability in .NET, we don't recommend mixing languages in the same project if you can avoid it.
Time Reporting Example
The opening screen of the sample application (see Figure 2) shows a list of times reported for different activities (usually projects), which you can manipulate with the Add, Edit, and Delete buttons. You use the Save button to save all times reported and exit the application. When you tap the Add or Edit button, you're presented with a new screen (see Figure 3). Here you can report or update an activity with date, project, and hours spent. Obviously, you save with the OK button and abort with the Cancel button. The sample application allows the user to work offline using XML files. The Project ComboBox (see Figure 3) is filled from an XML file (projects.xml) and the reported time is saved in (and retrieved on startup from) an XML file (timereport.xml).
Code Walkthrough
(Authors' Note: We built our sample application using prerelease versions of Visual Studio .NET, .NET Compact Framework, and Smart Device Extension, and therefore it may not be compatible with the final release versions.) One of the core features of the .NET CF is native support for XML. The code to populate the Project ComboBox in Figure 3 is in Listing 1. As the ADO.NET DataSet has native support for XML, we can use this to load an XML file (projects.xml) containing the current projects. Each row's Name field in the DataSet (XML file) is then added to the ComboBox (cboProject). And if something goes wrong (such as that we can't open the file), we add a dummy project name instead. Finally, we select the first project as the default value. The project.xml file looks like this:
<?xml version="1.0" standalone="yes"?> In a similar way, the reported time is saved in an XML file (timereport.xml) each time the application exits. The code for the closing event of the main form looks like this:
DataSet dsTime = new DataSet(); Again, an XML file (timereportempty.xml) containing the structure of the data is used to create the DataSet. Then the DataSet is cleared and each of the rows in the ListView (lvwItems) is added to the DataSet. Finally, and most elegantly, the DataSet is saved to an XML file (timereport.xml). The timereportempty.xml file looks like this:
<?xml version="1.0" standalone="yes"?> This is a very simple way of creating the structure of a new DataSet. We could create the DataSet using code for adding a table with fields, but it would require much more typing than if we create the XML file. The resulting timereport.xml file (with the data from Figure 2) looks like this:
<?xml version="1.0" standalone="yes"?> (Authors' Note: The project.xml and timereportempty.xml files are required to be available on the device [emulator or physical] in the \Windows folder to make the sample application work. You have to download this file to the device before you run the sample. The timereport.xml file will be created on application exit, but you will get a message box telling you that it's missing on application start.) The native support for XML makes working with data in XML files very efficient, and for some applications this is the only local storage you'll ever need. For more demanding scenarios, you'll need to handle local storage through a relational database like SQL Server for Windows CE.
Communicating Between Forms
frmTimeReportItem frmItem = new We start by creating the subform (frmTimeReportItem, shown in Figure 3) and setting the public properties Date, Project, and Hours from the currently selected row in the ListView. We then show the form with the ShowDialog method and if the return value of that call indicates that we tapped the OK button, the ListView is updated from the same properties. Here's the implementation of the Project property in the frmTimeReportItem form:
public string Project The property simply gets and sets the Text property of the Project ComboBox (cboProject). To make this work, we have to make sure that the ComboBox is loaded before we access the property. That's why the code to load the ComboBox is placed in the constructor of the form class. To make the ShowDialog method return different values for different buttons, you simply set the AcceptButton and CancelButton properties of the form. This code comes from the InitializeCom-ponent method in the code generated by the forms designer:
this.AcceptButton = this.btnOK; For a complete example, you should download the sample code for this article from www.sys-con.com/dotnet/sourcec.cfm.
Lessons Learned
The version of the SDE we've used (the tech preview released at Microsoft's Professional Developers Conference in November 2001) didn't include a forms designer. But interestingly this taught us something about how easy it is to migrate a desktop Windows application to a smart device like the Pocket PC. We started to build the sample as a native Windows application, then copied the forms into a smart device project and made some minor changes and there we were with a working sample application! The minor changes in the .NET Framework and .NET CF Object Models were efficiently pointed out to us by the compiler and were easily corrected. In the version of the .NET CF that we used there was no NumericUpDown control it would've been nice for entering Hours (see Figure 3). On a mobile device like the Pocket PC, the goal is always to minimize user input, and tapping of up and down arrows rather than entering numbers from the soft keyboard (or letter recognizer) will speed data entry significantly. However, replacing the TextBox control when the NumericUpDown control becomes available is no more than a minor adjustment. The device used to test the sample was a Compaq iPAQ 3650 upgraded to Pocket PC 2002. The sample worked fine in the emulator, too. It should run on a standard iPAQ (with Pocket PC 2000) as well.
Extending Existing Systems
Conclusion
Even if this is a great first step toward extending your time reporting to "anyplace," the next logical step would be to make the synchronization with the server in a standardized way. The way we're thinking of involves another core part of .NET Web services. However, it requires that the server system be able to handle Web services. If you have a server with Windows, this is most certainly doable, and might even make a great subject for a future column. Reader Feedback: Page 1 of 1
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||