Tuesday, August 16, 2011

Creating Database In CouchDB using LoveSeat (C#)

Getting Started with CouchDB using Loveseat C#
We all know that there is very limited resources to help Implementing CouchDB using c#. as far as i feel Love Seat is the best.

Here are i am going to discuss very basic thing.
How to create Database in CouchDB using Loveseat c#.net

First step:
we have to create a connection to Couchdb database.

CouchClient ccAdmin = new CouchClient("localhost", 5984, null, null);

In the above code i am passing username and password as null. if you have installed couch db recently then every user will be considered as admin user as long as you have created a new user.

If you have username and password with you the pass them while creating couch client instance.

Here in the following code i am checking for the database existence before creating it.
Note: CouchDB is case sensitive we should not user UpperCase (Capital Letters) while creating database. ("Database1" is wrong syntax! it has to be "database1")

string dbname = "database1";
if (!ccAdmin.HasDatabase(dbname))
{
ccAdmin.CreateDatabase(dbname);
}



Tuesday, August 9, 2011

WPF and Silverlight Validation using IDataErrorInfo

How to validate WPF or Silverlight Form or Page..?
Validations in wpf
There are several ways to validate a WPF or Silverlight form and IDataError Info is the one of the interesting way to do validations.

IDataErrorInfo is a part of System.dll Assembly.

this interface contains couple of properties which we have to override in our implementation.

1) string Error { get; }

2) string this[string columnName] { get; }

out of these two properties the second property is an Index.
(you can learn more about indexers here: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx)

Here is a sample which will give some information about the implementation of IDataErrorInfo.

Here I am creating a user Class which implements IDataErrorInfo.



public class User : ViewModelbase, IDataErrorInfo
{
private string firstName;

public string FirstName
{
get { return firstName; }
set { firstName = value;
OnPropertyChanged("FirstName");
}
}

private string lastName;

public string LastName
{
get { return lastName; }
set
{
lastName = value;
OnPropertyChanged("LastName");
}
}


#region IDataErrorInfo Members

public string Error
{
get { throw new NotImplementedException(); }
}

public string this[string columnName]
{
get
{
string result = null;
if (columnName == "FirstName")
{
if (string.IsNullOrEmpty(FirstName))
result = "Please enter a First Name";
}
if (columnName == "LastName")
{
if (string.IsNullOrEmpty(LastName))
result = "Please enter a Last Name";
}

return result;
}
}

#endregion

}


You can observe the public string this[string columnName] property which contains if condition for Firstname and lastname.. when ever we there is a property changed notification then this indexer will get initiated and checks for the valid value and the value it returned will appear as error message.

Implementing the following style will give error template to a text box whenever validation returns error message