Building the CRMLiveFramework project

This project is meant to be a lightweight Class Library project (that, when compiled, produces a .DLL file). It contains all the basic, common, and shared classes that will need to be used throughout the Sales Force solution. It is therefore expected to be referenced by all other projects.

You will be adding more classes and functionality to the CRMLiveFramework project as you progress through the book. In this chapter though, it will only contain the following items:

Item name

Description

IDataLibPlugin interface

The IDataLibPlugin interface provides the rest of the sales force application with a consistent set of methods to retrieve data from the SQL Server CE and Oracle Lite databases without having to worry about its underlying implementation.

PluginCollection class

This class inherits from the System.Collections.Hashtable class. It is used to hold a list of plugin objects that implement the IDataLibPlugin interface.

PluginManager class

This class contains the functions to install and remove plugins from the framework. It will also handle the persisting of plugin information to disk (in the form of XML) and vice versa.

Let's start by launching the Visual Studio application and creating a new Smart Device project. Enter CRMLiveFramework as the name of this project and click OK to proceed. You will be prompted with another window as shown in the following screenshot. Do ensure that you have chosen the Class Library project type, Windows Mobile 6 Professional SDK as the Target platform, and the .NET Compact Framework Version 3.5 as the target framework before continuing.

Building the CRMLiveFramework project

As a last step, you need to change the namespace of the project to a more consistent one. To do this, navigate to the Project | CRMLiveFramework Properties menu item and launch it. Change the Root namespace value to CRMLive.

Note

We will establish CRMLive as the namespace for all the projects in the Sales Force solution.

After this is done, you have created your very first Smart Device project! We will proceed to create some classes for this project in the next section.

Defining the IDataLibPlugin interface

At the heart of the data tier lies the IDataLibPlugin interface. It contains a set of method definitions that define how the sales force application communicates with the SQL Server CE and Oracle Lite databases.

Note

An interface is a collection of method definitions (without the implementation). A class that implements an interface has to provide implementations for each and every defined method of the interface.

Interfaces are great for defining a consistent set of behavior that different classes have to provide, but leaves the details of the implementation to these classes.

Add a new Interface item to your CRMLiveFramework project by launching the Project | Add New Item menu item and choosing Interface as the item type. Name your Interface IDataLibPlugin when prompted. Let us take a look at the various methods we will define in this interface:

public interface IDataLibPlugin
CRMLiveFramework projectIDataLibPlugin interface, defining{
//=========================================================
//The following properties are required for all plugins
//so we define them in the interface
//=========================================================
string Datasource {
get;
set;
}
string PluginPath {
get;
set;
}
bool Active {
get;
set;
}
string PluginFullName {
get;
}
//========================================================= //This method opens a connection to the database designated //by the Datasource property
//=========================================================
bool ConnectDatabase();
//=========================================================
//This method closes the connection opened via //ConnectDatabase()
//=========================================================
bool DisconnectDatabase();
//========================================================= //The CreateSalesForceDatabase() method defines a function
//that generates an entirely new and empty Sales Force //database
//========================================================= bool CreateSalesForceDatabase();
//=========================================================
//The GetAccountDetails() method defines a function that //takes in an AccountGUID value and returns a Dataset
//object containing the full details of the account
//=========================================================
DataSet GetAccountDetails(Guid AccountGUID);
//========================================================= //The SetAccountDetails() method defines a function that //takes in a Dataset object (containing the updated account //details). The function must then write the updated
//details to the underlying database
//=========================================================
bool SetAccountDetails(Guid AccountGUID, DataSet Account);
//=========================================================
//The RemoveAccount() method removes an account record and
//all its related child records
//=========================================================
bool RemoveAccount(Guid AccountGUID);
//========================================================= //The AccountExists checks if an account with the same
//first name and last name already exists
//=========================================================
bool AccountExists(string FirstName, string LastName, Guid AccountGUID);
//=========================================================
//The ChangeAccountType() method defines a function that //changes the type of an account between a Lead,
//Opportunity and Customer
//========================================================= bool ChangeAccountType(Guid AccountGUID, int Type);
//========================================================= //The GetProductList() method retrieves the full list of //records from the Products table as a Dataset
//=========================================================
DataSet GetProductList();
//========================================================= //The GUIDToNative() method converts a .NET System.GUID
//object into the database's native data type used to store
//GUID values
//=========================================================
object GUIDToNative(Guid AccountGUID);
//========================================================= //The NativeToGUID() method does the opposite it converts //the database's native data type for GUID into a .NET //System.GUID object
//=========================================================
Guid NativeToGUID(object AccountGUID);
}

Tip

What goes in an interface?

As a rule of thumb, two functions that achieve the same output but do so in different ways are good candidates to include in an interface. For instance, consider the GetAccountDetails() method we used in the previous section. We know that regardless of the database used, if we pass in the GUID of an account, it will return a Dataset containing the matching account details. How this data retrieval is done in SQL Server CE and Oracle Lite, however, is entirely different; SQL Server CE uses the SqlCeCommand class, whereas Oracle Lite uses the OracleCommand class.

With that done, you will now proceed to build the Plugin Manager UI.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.83.150