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.
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 {
//=========================================================
//The following properties are required for all plugins
//so we define them in the interface //=========================================================
string Datasource { get; set;
string PluginPath { 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);
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.
Average user rating: 5 stars out of 1 votes
Post a comment