IgorShare Weblog

Practical Engineering

Archive for the ‘Tutorials’ Category

Git for Windows developers

Posted by igormoochnick on 09/28/2009

Just moved to Git on Windows. It gives me more flexibility for the local repositories and distributed development for my new team.

Found the following series very helpful for the beginners (my engineers never used Git before):

Git For Windows Developers – Git Series – Part 1

Git For Windows Developers – Git Series – Part 2

Git For Windows Developers – Git Series – Part 3

 

Take a look at Tortoise Git as well. Reduces all the command-line noise drastically:

Read the rest of this entry »

Posted in Agile, Source Control, Tutorials | 4 Comments »

Feeling Azure the first time? Check this getting-started resource …

Posted by igormoochnick on 08/18/2009

Check out this great article about how the DinnerNow.net application was ported to Windows Azure – Article.

Don’t forget to listen to the DotNetRocks #471 podcast about this whole process.

Posted in Azure, Tutorials | Leave a Comment »

GTD: Getting your inbox to zero

Posted by igormoochnick on 08/11/2009

Tremendously loved the 43folders podcast, delivered at Google,  about how to manage your Inbox and keep it empty. My advise – follow this religiously. It keeps your life easy, manageably and organized.

[Series 1] Inbox Zero – Google Tech Talk  (permalink is not really working, so use the link to MP3 directly)

43folders RSS Feed

Posted in GTD, Life Hacks, Thoughts, Tutorials | 2 Comments »

Microsoft Certified Trainer

Posted by igormoochnick on 08/11/2009

MCT(rgb)

Last week got my MCT certification.   Celebration is in order …

Posted in Community, Thoughts, Tutorials | Leave a Comment »

XML/JSON symmetric REST web services providers for Jersey

Posted by igormoochnick on 07/27/2009

Many times I’ve been asked to provide a set of Web Services interfaces where both JSON and XML clients can communicate with the server. Primarily it’s done for a set of reasons:

  1. XML is very convenient to use for inter-service communication.
  2. JSON is great for AJAX (web) clients. It’s perfect for GWT too.

In the recent project we’ve been using XStream for all serialization aspects and, since it can serialize both to XML and JSON, it was plugged into Jersey as a provider too. Following you can see XML and JSON providers implemented using XStream library.

XML Provider (annotated to be a default provider, it’ll be used if no Content-Type or Accept headers provided):

Read the rest of this entry »

Posted in GWT, JSON, Java, Jersey, REST, Tutorials, XML, XStream | 1 Comment »

Web Form Validation: Best Practices and Tutorials

Posted by igormoochnick on 07/09/2009

validation

Great article about forms and ways of implementing data validation for the web applications.

Highly advised to read.

Posted in Tutorials, Web | Leave a Comment »

The importance of nightly builds (hilarious)!

Posted by igormoochnick on 07/08/2009

I’ve preached to all my customers and co-workers the importance of Continuous Integration. Now I’ll be pointing them to this training course – they’ll learn and will have fun at the same time.

It’s hilarious!

Posted in Agile, Continous Integration, Tutorials | Leave a Comment »

Adding Watermark to GWT Textbox widget

Posted by igormoochnick on 06/30/2009

Let’s see how we can improve our UI by adding some watermarked “spice”:

clip_image001

Let’s define the primary style for the text box (textInput) and the dependent style for the watermark (textInput-watermark):

.textInput {
	border: 1px solid #C9C7BA;
	font-family:Tahoma, Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
	padding-left: 2px;
	padding-top: 2px;
}

.textInput-watermark {
   /* background-image: url('images/overlay.gif');
   background-repeat: no-repeat;
   padding-left: 20px;
   vertical-align: middle; */
   font-style: italic;
   color: DarkGray;
}

Note that the watermark style can contain images as well (see the commented out piece).

After the styles were defined we need to add some code that will apply it to the text box. To do this I’m going to extend the default GWT TextBox. The trick is to hijack the OnBlur and OnFocus events. When the OnBlur is occurring, we’re going to show the watermark and OnFocus – hide it:

public class WatermarkedTextBox extends TextBox implements BlurHandler, FocusHandler
{
	String watermark;
	HandlerRegistration blurHandler;
	HandlerRegistration focusHandler;

	public WatermarkedTextBox( )
	{
		super();
		this.setStylePrimaryName("textInput");
	}

	public WatermarkedTextBox(String defaultValue)
	{
		this();
		setText(defaultValue);
	}

	public WatermarkedTextBox(String defaultValue, String watermark)
	{
		this(defaultValue);
		setWatermark(watermark);
	}

	/**
	 * Adds a watermark if the parameter is not NULL or EMPTY
	 *
	 * @param watermark
	 */
	public void setWatermark(final String watermark)
	{
		this.watermark = watermark;

		if ((watermark != null) && (watermark != ""))
		{
			blurHandler = addBlurHandler(this);
			focusHandler = addFocusHandler(this);
			EnableWatermark();
		}
		else
		{
			// Remove handlers
			blurHandler.removeHandler();
			focusHandler.removeHandler();
		}
	}

	@Override
	public void onBlur(BlurEvent event)
	{
		EnableWatermark();
	}

	void EnableWatermark()
	{
		String text = getText();
		if ((text.length() == 0) || (text.equalsIgnoreCase(watermark)))
		{
			// Show watermark
			setText(watermark);
			addStyleDependentName("watermark");
		}
	}

	@Override
	public void onFocus(FocusEvent event)
	{
		removeStyleDependentName("watermark");

		if (getText().equalsIgnoreCase(watermark))
		{
			// Hide watermark
			setText("");
		}
	}
}

Posted in Design, GWT, Java, Tutorials, Web | 1 Comment »

Building GWT web clients [Part 4.1] – How to create an Azure RESTful web service?

Posted by igormoochnick on 06/08/2009

Prerequisites: make sure that you have all the Azure SDK tools installed for your VS2008.

 

(1) Start by creating a new “Web Cloud Service” project in the Visual Studio. Give it a nice name.

(2) Add a new “WCF Service” to the WebRole project.

(3) Define a required contract:

The most important part here is to put attributes that will tell the WCF in what format to send/receive the message body (XML or JSON) …

[ServiceContract(Name = "service", Namespace = "http://www.igorshare.com")]
public interface IContactManagerService
{
    [OperationContract]
    [WebGet(UriTemplate = "/contacts", BodyStyle = WebMessageBodyStyle.Bare,
       ResponseFormat = WebMessageFormat.Json)]
    List<Contact> GetAllContacts();

    [OperationContract]
    [WebGet(UriTemplate = "/contacts/{filter}", BodyStyle = WebMessageBodyStyle.Bare,
       ResponseFormat = WebMessageFormat.Json)]
    List<Contact> GetContacts(string filter);
}

[DataContract]
public class Contact
{
    [DataMember]
    public string FirstName { get; set; }

    [DataMember]
    public string LastName { get; set; }

    [DataMember]
    public string Company { get; set; }
}

(4) Implement the service logic:

public class ContactManagerService : IContactManagerService
{
    private static readonly List<Contact> Contacts = new List<Contact>() { ... };

    public List<Contact> GetAllContacts()
    {
        return Contacts;
    }

    public List<Contact> GetContacts(string filter)
    {
        string f = filter.ToLower();

        var contacts = from contact in Contacts
                       where contact.FirstName.ToLower().Contains(f)
                            || contact.LastName.ToLower().Contains(f)
                            || contact.Company.ToLower().Contains(f)
                       select contact;

        return contacts.ToList();
    }
}

(5) Configure it to be exposed as a RESTful service:

To make it REALLY, REALLY simple for you, do this trick:

a) Comment out the system.serviceModel section in the Web.config file

b) Add the Factory attribute to the .svc file

<%@ ServiceHost Language="C#" Debug="true"
Service="ContactManagerCloudService_WebRole.ContactManagerService"
CodeBehind="ContactManagerService.svc.cs"
Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

(6) Build the service

 

You’re interested in 2 artifacts of the build:

  1. .cscfg file – configuration for the Cloud Service deployment
  2. .cspkg file – all the bits packaged (zipped)

 

At this moment you have 2 choices:

  1. Run your project in the local Development Fabric (for testing and debugging), or …
  2. Deploy it to the Azure Cloud (for staging or production)

 

To deploy your application to the cloud, do right-click on the CloudService project and select “Publish”.

Visual Studio will launch the Azure Service Developer Portal page. Log-in to your account, create a project and deploy your bits to the staging environment:

clip_image001

 

This is it!  You’re good to go.

BTW: make sure that your application works in the staging environment and then you can push it to Production by just switching it with the Staging.

 

 

Note: Check out a great explanation about the difference between the WCF REST Configuration for ASP.NET AJAX and plain REST Services by Rick Strahl.

Posted in .NET, Azure, C#, JSON, REST, S+S, Tutorials, WCF | Leave a Comment »

Building GWT web clients [Part 4] – How to connect GWT client to Azure web service?

Posted by igormoochnick on 06/08/2009

Stay tuned …

Posted in Azure, GWT, JSON, Java, REST, S+S, Tutorials | Leave a Comment »