I’ve been working extensively on enterprise mobility projects lately. These applications integrate into large SAP based systems and when testing the system it can get very tedious to set up some temporary data from the backend. I’m also working with some not-so-technical testers that get intimidated by the Visual Studio or the SQL Server Management Studio. This led me to writing an open source project called SQL Compact Query Analyzer
Here’s some details I pulled directly off the CodePlex site
Project Description SQL Server Compact Edition Database Query Analyzer
Features:
- Create new database - Automatically refresh database upon executing create/alter/drop table queries - Displays database information (database version, filename, size, creation date) - Displays schema summary (number of tables, columns, primary keys, identity fields, nullable fields) - Displays the information schema views - Displays column information (database type, clr type, max length, allows null, etc) - Displays index information (column name, is unique, is clustered) - Execute SQL Queries against a SQL Server Compact Edition database - Execute multiple SQL queries (delimited by a semi colon ;) - Easily edit the contents of the database - Display query result as XML - Shrink and Compact Databases - SDF file association with SQL Compact Query Analyzer for launching directly by opening the SDF in Windows Explorer - Displays thumbnails for IMAGE fields - Generates Schema and Data Scripts - Supports password protected databases - Supports SQLCE 3.0, 3.1, 3.5 and 4.0
Coming Soon: - Purge database content - Create, edit, and drop tables UI - Create, edit, and delete table references and indexes UI - Support for SQL Server Compact Edition 2.0
Screenshots
- Displays database and schema information and executes multiple SQL queries directly
More than a year ago, I published a project on CodePlex called SQL Compact Code Generator. Unfortunately, I never managed to find the time to do some work on it and the project was set on a very long hold. A year after I suddenly really needed such a tool and decided that I should put in some hours on the project.
I'm currently working on a large enterprise project where changes to the database schema is done rather frequently, to avoid the pain of updating my data layer after every change I decided to use my code generator.
Here's some details I pulled directly off the CodePlex site.
Project Description Contains a stand alone GUI application and a Visual Studio Custom Tool for automatically generating a .NET data access layer code for objects in a SQL Server Compact Edition database.
Features:
Visual Studio 2008 and 2010 Custom Tool Support
Creates entity classes for each table in the database
Generates data access code that implements the Repository Pattern
Generates methods for Create, Read, Update and Delete operations
Generates SelectBy and DeleteBy methods for every column in every table
Generates a Purge method for every table to delete all records
Generates Count() method for retrieving the number of records in each table
Generates CreateDatabase() method for re-creating the database
Generates xml-doc code comments for entities and data access methods
Generates Entity Unit Tests
Generates Data Access Unit Tests
Generates .NET Compact and Full Framework compatible code
Support for SQL Compact Edition version 4.0
Multiple test framework code generation (MSTest, NUnit, xUnit)
Transaction support per DataRepository instance (Begin, Commit, Rollback)
Code generation options to enable/disable unit test code generation
Windows Phone 7 "Mango" support for generating a LINQ to SQL DataContext
Yesterday, I found myself using an old piece of code that I wrote ages ago. It's something I've used every now and then for past few years. Since I myself find it useful, I might as well share it. All the code does is display a Notification Bubble in Windows Mobile. To do this you use the Notification class in the Microsoft.WindowsCE.Forms namespace. Even though the Notification class is very straight forward and easy to use, I created a helper class so that I only need to write one line of code for displaying a notification bubble: NotificationBubble.Show(2, "Caption", "Text");
///<summary>
/// Used for displaying a notification bubble
///</summary>
publicstaticclassNotificationBubble
{
///<summary>
/// Displays a notification bubble
///</summary>
///<param name="duration">Duration in which the notification bubble is shown (in seconds)</param>
I've been working on an application with 2 pages, a main page and a content page. The content page contains a Pivot control with a few pivot items. The main page does nothing but navigate to the content page and suggest which pivot item to display. The only reason the main page exists is to display the information in the pivot item headers in a more graphical and elegant way.
For some reason I can't set the displayed pivot index to be the third item. I wanted to do this on the OnNavigatedTo event of the content page but whenever I attempt doing so an exception is thrown. Every other pivot item works fine, which I think is really weird.
To load the content page, I navigate to the page by passing some information of the pivot index I wish to be displayed. Something like this:
If the value of index in the code above is set to 2 then I get an exception, any other valid value works fine. A value out of range (less than 0 or greater than 5) throws an out of range exception which is the behavior anyone would expect.
To work around this limitation, you can handle the Loaded event of the page and update the pivot selected index from there. Here's an example how to do it:
if (NavigationContext.QueryString.TryGetValue("index", out value))
{
pivotIndex = 0;
int.TryParse(value, out pivotIndex);
}
}
}
I'm not sure if this limitation is by design or it's a bug in the control. Either way I managed to get it to work the way I wanted it to. Hopefully I'm not the only one who ran across this and that you found this information useful.
I'm really getting carried away with playing with image manipulation in WPF. Here's a short post on how to darken an image using the WriteableBitmap class.
The process is fairly simple, I manipulate each pixel by decrementing each RGB value with the provided level
Now I'm just getting carried away with playing with image manipulation in WPF. Here's a short post on how to brighten an image using the WriteableBitmap class.
The process is fairly simple, I manipulate each pixel by incrementing each RGB value with the provided level
After having such fun trying to find optimal ways of manipulating images in WPF I decided to write another short post on image manipulation. This time I'd like to demonstrate how to alpha blend 2 images using the WriteableBitmap class.
I'm probably not the best one to explain how alpha blending is done but here's the idea in a nutshell. I get the RGB values of every pixel for the each image and write them to a new bitmap where I manipulate each color information by applying the following formula:
I've been playing with the Windows Presentation Foundation today and I had a task where I needed to convert an image to gray scale to do some image analysis on it. I've done this a bunch of times before using GDI methods or by accessing the BitmapData class in .NET. For this short post I'd like to demonstrate how to manipulate images using the WriteableBitmap class.
The easiest way to convert an image to gray scale is to set the RGB values of every pixel to the average of each pixels RBG values.
R = (R + B + G) / 3
G = (R + B + G) / 3
B = (R + B + G) / 3
Here's a code snippet for manipulating a BitmapSource object using the WriteableBitmap class into a gray scale image:
Another way to to convert an image to gray scale is to set the RGB values of every pixel to the sum of 30% of the red value, 59% of the green value, and 11% of the blue value. Hope you find this useful.
This is a task that pretty much every mobile device can do, or at least any mobile phone can do. In this short post on multi-platform mobile development I would like to demonstrate how to send an SMS or launch the SMS compose window in a mobile application.
I'm going to demonstrate how to use the messaging API's of the following platforms:
Android
Windows Phone 7
Windows Mobile 5.0 (and higher) using .NET Compact Framework
Windows Mobile using the Platform SDK (Native code)
Android
There are 2 ways of sending SMS from an Android application: Launching the Compose SMS window; Through the SmsManager API. I figured that since this article is supposed to demonstrate as many ways as possible for sending SMS that I create a helper class containing methods that I think would be useful or at least convenient to have.
Here's a SMS helper class for Android that I hope you would find useful.
/**
* Helper class for sending SMS messages
*
* @author Christian Resma Helle
*/ public class Sms { private final static String SENT_ACTION = "SENT"; private final static String DELIVERED_ACTION = "DELIVERED"; private Context context; private PendingIntent sentIntent; private PendingIntent deliveredIntent;
/**
* Creates an instance of the SMS class
*
* @param context Context that owns displayed notifications
*/ public Sms(Context context) { this.context = context;
registerForNotification(); }
private void registerForNotification() { sentIntent = PendingIntent.getBroadcast(context, 0, new Intent(SENT_ACTION), 0);
deliveredIntent = PendingIntent.getBroadcast(context, 0, new Intent(DELIVERED_ACTION), 0);
context.registerReceiver(messageSentReceiver, new IntentFilter(SENT_ACTION));
context.registerReceiver(messageDeliveredReceiver, new IntentFilter(DELIVERED_ACTION)); }
/**
* Opens the Compose SMS application with the recipient phone number displayed
*
* @param phoneNumber recipient phone number of the SMS
*/ public void composeMessage(String phoneNumber) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
context.startActivity(intent); }
/**
* Opens the Compose SMS application with the recipient phone number and message displayed
*
* @param phoneNumber recipient phone number of the SMS
* @param text message body
*/ public void composeMessage(String phoneNumber, String text) { Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body", text);
intent.putExtra("address", phoneNumber);
intent.setType("vnd.android-dir/mms-sms");
context.startActivity(intent); }
/**
* Opens the Compose SMS application with the multiple recipient phone numbers and the message displayed
*
* @param phoneNumber recipient phone numbers of the SMS
* @param text message body
*/ public void composeMessage(String[] phoneNumbers, String text) { StringBuilder sb = new StringBuilder(); for (String string : phoneNumbers) { sb.append(string);
sb.append(";"); } composeMessage(sb.toString(), text); }
/**
* Send an SMS to the specified number
*
* @param phoneNumber recipient phone number of the SMS
* @param text message body
*/ public void sendMessage(String phoneNumber, String text) { sendMessage(phoneNumber, text, false); }
/**
* Send an SMS to the specified number and display a notification on the message status
* if the notifyStatus parameter is set to <b>true</b> *
* @param phoneNumber recipient phone number of the SMS
* @param text message body
* @param notifyStatus set to <b>true</b> to display a notification on the screen
* if the message was sent and delivered properly, otherwise <b>false</b> */ public void sendMessage(String phoneNumber, String text, boolean notifyStatus) { SmsManager sms = SmsManager.getDefault(); if (notifyStatus) { sms.sendTextMessage(phoneNumber, null, text, sentIntent, deliveredIntent); } else { sms.sendTextMessage(phoneNumber, null, text, null, null); }
}
/**
* Send an SMS to multiple recipients and display
*
* @param phoneNumber recipient phone number of the SMS
* @param text message body
*/ public void sendMessage(String[] phoneNumbers, String text) { sendMessage(phoneNumbers, text, false); }
/**
* Send an SMS to multiple recipients and display a notification
* on the message status if notifyStatus is set to <b>true</b> *
* @param phoneNumber recipient phone number of the SMS
* @param text message body
* @param notifyStatus set to <b>true</b> to display a notification on the screen
* if the message was sent and delivered properly, otherwise <b>false</b> */ public void sendMessage(String[] phoneNumbers, String text, boolean notifyStatus) { StringBuilder sb = new StringBuilder(); for (String string : phoneNumbers) { sb.append(string);
sb.append(";"); } sendMessage(sb.toString(), text, notifyStatus); }
private BroadcastReceiver messageSentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case Activity.RESULT_OK:
Toast.makeText(context, "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(context, "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(context, "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(context, "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(context, "Radio off", Toast.LENGTH_SHORT).show(); break; }
}
};
private BroadcastReceiver messageDeliveredReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case Activity.RESULT_OK:
Toast.makeText(context, "Message delivered", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED:
Toast.makeText(context, "Message not delivered", Toast.LENGTH_SHORT).show(); break; }
}
}; }
Before your Android application can send SMS it needs the right permissions for it. Add the SEND_SMS permission your AndroidManifest.xml
Here are some examples on how to use the SMS helper class defined above from within an Activity class:
Sms sms = new Sms(getApplicationContext());
// Send an SMS to the specified number sms.sendMessage("+4512345678", "Multi-platform Mobile Development");
// Send an SMS to the specified number and display a notification on the message status sms.sendMessage("+4512345678", "Multi-platform Mobile Development", true);
// Send an SMS to multiple recipients sms.sendMessage(new String[] { "+4512345678", "+4598765432" }, "Multi-platform Mobile Development");
// Send an SMS to multiple recipients and display a notification on the message status sms.sendMessage(new String[] { "+4512345678", "+4598765432" }, "Multi-platform Mobile Development", true);
// Opens the Compose SMS application with the recipient phone number displayed sms.composeMessage("+4512345678");
// Opens the Compose SMS application with the recipient phone number and message displayed sms.composeMessage("+4512345678", "Multi-platform Mobile Development");
// Opens the Compose SMS application with the multiple recipient phone numbers and the message displayed sms.composeMessage(new String[] { "+4512345678", "+4598765432" }, "Multi-platform Mobile Development");
Windows Phone 7
This platform unfortunately doesn't provide as vast a API collection compared to Android and Windows Mobile. To send an SMS in Windows Phone 7, you will have to use the SMS Compose page in the built-in messaging application. To launch this we call the Show() method in SmsComposeTask.
Here's how to use SmsComposeTask
SmsComposeTask launcher = newSmsComposeTask();
launcher.To = "+45 12 34 56 78";
launcher.Body = "Multi-platform Mobile Development";
launcher.Show();
Windows Mobile 5.0 (and higher) using .NET Compact Framework
Sending an SMS in this platform is just as easy as doing so in Windows Phone 7. Windows Mobile provides native API's for the Short Messaging System, these methods are exposed as C type methods in a DLL called sms.dll. Aside from the SMS API, the platform also offers another API called the Messaging API (CE MAPI) for sending SMS, MMS, and Emails. Microsoft has provided managed wrappers for these and many other API's to make the life of the managed code developer a lot easier.
To send an SMS in Windows Mobile 5.0 (and higher) we use the SmsMessage object. There are 2 ways of accomplishing this: Using the Send() method of the SmsMessage class; Sending the SMS using the Compose SMS application
Here's a snippet on how to send SMS using the Send() method
The code above depends on 2 assemblies that must be referenced to the project:
Microsoft.WindowsMobile.dll
Microsoft.WindowsMobile.PocketOutlook.dll
It is also possible to P/Invoke the SMS API through sms.dll, but this requires a slightly more complicated solution. In the next section, I will demonstrate how use the SMS API in native code. This should give you an idea on how to use the SMS API if you would like to go try the P/Invoke approach.
Windows Mobile using the Platform SDK (Native code)
Probably not very relevant for most modern day managed code developers but just to demonstrate as many ways to send SMS in as many platforms as possible I'd like to show how to send SMS in native code using the Windows CE Short Message Service (SMS) API.
Here's a sample C++ helper class for sending SMS using the Platform SDK
The code above requires the that the project is linked with sms.lib, otherwise you won't be able to build.
Here's a snippet of how to use the SMS helper class defined above:
SmsMessage *sms = new SmsMessage(L"+14250010001", L"Multi-platform Mobile Development");
sms->Send();
delete sms;
For those who don't know what +14250010001 is, this is the phone number of the Windows Mobile emulator. For testing SMS functionality on the emulator, you can use this phone number.
That's it for now. I hope you found this article interesting.
Here's the first installment on my series on multi-platform mobile development articles. A common practice on displaying information to a mobile device user is a list. A list is one of the best ways to display a group of information allowing the user to easily select which specific details he/she wishes to display.
A good example of decent list implementations is the Inbox on pretty much all mobile devices. Most Inbox list implementations display sender, title, date, size, and a preview of the message body. A good list is not only bound to textual information but also visual. Most Inbox implementation displays the information using bold fonts if the message is unread
In this article I would like to demonstrate how to implement customized list based UI's on the following platforms:
Windows Phone 7
Windows Mobile using .NET Compact Framework
Android
Let's get started...
Windows Phone 7
This is definitely the easiest platform to target, in fact this is by far the easiest platform I've ever worked with. Development times on this platform are a lot shorter than any other platform I've worked with. I've been working with Windows CE based phones for the last 7 or so and I definitely think that this is the best Windows CE based OS ever. There unfortunately a few down sides like lack of a native code API and limited platform integration, but considering the performance and development ease, it is for most cases worth it. The best part with designing UI's for Windows Phone 7 is that I don't have to care about the design very much, I just ask my designer / graphic artist to shine up my XAML file and I can concentrate on the code.
A Visual Studio 2010 project template is actually provided by default for creating a list based UI makes things easier. This project template is called a Windows Phone Databound Applicaton, the description goes "A project for creating Windows Phone applications using List and Navigation controls". This project creates 2 pages, one for displaying the list, and the other for displaying details of this list.
The code examples for Windows Phone 7 uses the Model-View-ViewModel. This pattern is heavily used and I guess one can say an accepted standard in developing Windows Phone 7 applications. I'm not gonna go deep into the pattern in this article, so I assume that you do a bit of home work on MVVM.
To display a list Windows Phone 7 we use the ListBox control in XAML. This will represent the View.
Our ViewModel is implemented in code. A ViewModel class should implement the INotifyPropertyChanged interface for the View to be able to respond to changes in the ViewModel.
This is actually a pretty decent platform and offers a huge selection of low level API's for platform integration. The OS also offers full multi tasking and the ability to create applications that run behind scenes. The down side of course to all that fun stuff is that you have to do a lot of things the hard way. Implementing a decent list based UI in this platforms can be done in 2 ways: Using the Windows CE custom drawing service; Creating an Owner Drawn List Control. Both require writing a few hundred lines of code.
For this example we create an Owner Drawn List. For those who are not familiar what that means, we draw the entire control from scratch, manually. We create a class that inherits from System.Windows.Forms.Control (the base class of all UI components) and override the drawing, resizing, and input methods. It's a bit tedious, but most of the code in owner drawn controls can be re-used as base classes for other owner drawn controls.
Let's start off with creating an owner drawn list base class.
abstractclassOwnerDrawnListBase<T> : Control
{
int selectedIndex;
int visibleItemsPortrait;
int visibleItemsLandscape;
VScrollBar scrollBar;
protected OwnerDrawnListBase()
: this(7, 4)
{
}
protected OwnerDrawnListBase(int visibleItemsPortrait, int visibleItemsLandscape)
The class above implements the basic functionality of an owner drawn list. It hands resizing the off screen bitmap that serves as a double buffer, handles the scroll bar visibility, and handles updating the selected index. One can implement responding to keyboard input or gestures from here as well.
Next we create a class where we define how the control is drawn. This class inherits from our owner drawn list base class.
Here's how the custom list view looks like in a Windows Mobile 6.5.3 emulator
You can grab the source for Windows Mobile application above here.
Android
Creating decent list based UI's is also pretty easy. The designer experience is unfortunately not as elegant as what Windows Phone 7 has to offer, but shares the same idea. The user interface layout of Android applications are described in XML files and are parsed during runtime. In some occasions it seems easier to create the UI layout in runtime through code instead of struggling with the UI designer. This is probably because of my lack of patience with the tool or because of my lack of experience using it. Either way, I think it could have been done in a much smarter way.
To create a list based UI in Android we can create a class that extends from the ListActivity class. The ListActivity base class contains a List control set to fill the parent, it comes in handy if you want a UI with nothing but a list control. In android development, you usually setup the UI and do other initialization methods in the onCreate() method, our example will do the same. We set the data source of our list control by calling setListAdapter().
To have a more flexible and customizable we use the ArrayAdapter for presenting our data source to the screen. To optimize performance, we use an object called convertView that ArrayAdapter exposes, we can store a single instance of a class containing UI text components and just update the text for that instance. This is done by overriding the ArrayAdapter getView method.
Here's the code for implementing the ListActivity and ArrayAdapter
Here's how the applications looks like on an Android 2.3 emulator
You can grab the source for Android application above here.
So this basically all I have for now. I plan to go into detail by breaking down each part of the code samples I provided for all 3 platforms, or perhaps add another platform as well. I hope you found this useful.