technology workspace
Thursday, May 23, 2013
Wednesday, May 22, 2013
Sync Adapter for updating SQlite data
I have an android application which allows user to enter data and save it to locals device and the data needs to be uploaded periodically to remote SQL Server.
As the first step I developed a contentprovider to wrap the sqlitedb in the first application which was laready operationsl. As I already had a database handelr which extends SQLiteOpenHelper for the application. I developed the content provider with lots of dummy overrides and I kept using SQLiteOpenHelper for my first application. Only interesting area for the first application is its manifest file where the Authority and permissions are defined. Defining this took lots of time as I had to do lots of trial and error.
android:exported="true"
android:grantUriPermissions="true"
android:readPermission="android.permission.permRead" />
First provider has to be within application tags.
androidname is the file name of my provider class attached with the package name.
auhtoritis is the AUTHORITY declared inside the provider class.
Relevant portion of the provider class is
//from vogela http://www.vogella.com/articles/AndroidSQLite/article.html
private static final String AUTHORITY = "in.xxx.xxx.provider";
private static final String BASE_PATH = "members";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/" + BASE_PATH);
At this point I had my first application running. This application is responsible for all database operations. Now I need to develop another application which allows me to sync data periodically.
Little bit research and help from Stackoverflow shows that the best approach is to use SyncAdapter. Sync Adapter has three componenets Account, Authentication and SyncAdapter.
Important links
Concept of SyncAdapter (android.content.AbstractThreadedSyncAdapter)
Connecting The Dots with Android SyncAdapterBreaking down Google’s SampleSyncAdapter
How to run Sync Immediately
Reg selection of Records to be updated from Server and vice versa
Idea about Authentication
Important resources
xml version="1.0" encoding="utf-8" ?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="com.android.contacts"
android:accountType="com.google"
android:userVisible="true" />
tag that includes the tag that includes this file...) will sync contacts using a com.google style account.Monday, October 29, 2012
Dynamically Loading a Dropdown with JSON data
$.ajax(
{ type: "POST",
url: "OfficeData.asmx/Getstates",
data: "{'countryId':" + (countryId) + "}",
contentType: "application/json;
charset=utf-8",
global: false,
async: false,
dataType: "json",
success: function(jsonObj)
{
var listItems= "";
var jsonData = jsonObj.d;
for (var i = 0; i < jsonData.Table.length; i++)
{
listItems+= " + jsonData.Table[i].statename + "
$("#<%=DLState.ClientID%>").html(listItems); //DLState is the dropdown
JSON [JavaScript Object Notation]
JSON is built on two structures:
- A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
- An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
- JSON is syntax for storing and exchanging text information. Much like XML.
- JSON is smaller than XML, and faster and easier to parse.
{
"employees": [
{ "firstName":"Dibakar" , "lastName":"Ray" },
{ "firstName":"Sujit" , "lastName":"Banerjee" },
{ "firstName":"Anadomohan" , "lastName":"Chakraborty" }
]
}
Working with JSON Data ASP. Net
{"IsMember" : true, "Name" : "Surnider", "Age" : 24}
Define the User type to deserialize the JSON into.
public class User
{
public bool IsMember { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
DataContractJsonSerializer serializer =
new DataContractJsonSerializer(typeof(User));
User user = (User)serializer.ReadObject(responseStream);
bool isMember = user.IsMember;
string name = user.Name;
int age = user.Age;
Saturday, March 28, 2009
Authentication Using LDAP
Intitally I tried to bind to the LDAP using admin password in the DirectoryEntry constructor and using the Filter to authenticate usergiven userid and password. But failed as couldnot access UserPassword attribute.
Later I used Userid and password directly in the DirectoryEntry constructor.
Limitation - Clear Text password. Need to fix it.
DirectoryEntry entry = new DirectoryEntry(LDAP://164.XXX.XX.X/o=XXX.in,dc=XXX,dc=in);
entry.Username ="uid="+email.Text+",ou=people,o=XXX Employees,o=XXX Support,o=XXX.in,dc=XXX,dc=in"; //email text box contains the user id and password text contains the password
entry.Password = password.Text;
entry.AuthenticationType = AuthenticationTypes.None;
DirectorySearcher searcher = new DirectorySearcher(entry);
try
{
searcher.Filter = "(uid=" + email.Text + ")";
SearchResult rs = searcher.FindOne();
if (rs != null)
{
//success
divOutput.InnerHtml="";
divOutput.InnerHtml = "Welcome - " + rs.Properties["cn"][0].ToString();
}
else
{
//Failure
divOutput.InnerHtml = "Error authenticating. Check Your User Id or Password";
}
}
catch (Exception ex)
{
divOutput.InnerHtml = "Error authenticating. " + ex.Message;
return;
}