Labels

Thursday, September 17, 2009

Automatic Properties - Where the fun stops

Using Accessibility Modifiers on Auto Properties

 

This post could be older for you. Below is the way to define properties.

 

public class Person

{

    private string firstName;

    public string FirstName

    {

        get { return firstName; }

        set { firstName = value; }

    }

}

 

You get to write the same in C#3.0 as below.

 

public class Person

{

    public string FirstName { get; set; }

}

 

Unfortunately, for most developers, the above use of automatic properties is where the fun stops. Once they get to the point where they need to have a read-only property, they fall back to their old tricks and write this:

 

public class Person

{

    private string firstName;

    public string FirstName

    {

        get { return firstName; }           

    }

}

 

You don’t need to do that silly way. You just need to do this:

 

public class Person

{       

    public string FirstName { get; private set; }

}

 

public class Person

{       

    public string FirstName { private get; set; }

}

 

public class Person

{       

    public string FirstName { get; protected set; }

    public string LastName { get; internal set; }

}

 

 

Hope this helps.

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

 

Thursday, September 10, 2009

Google SiteMap File

Generating a Google SiteMap File

 

Google provides a free service, named Google SiteMaps, that you can use to improve the way that Google indexes the pages on your website.

For example, you can use Google SiteMaps to discover which Google search queries have returned pages from your website and the ranking of your pages in Google search results. You also can use Google SiteMaps to view any problems that the Google crawler encounters when indexing your site.

 

You can sign up for Google SiteMaps by visiting the following URL:

http://www.google.com/webmasters/sitemaps

 

To use Google SiteMaps, You Must Provide Google With The Url Of A Google Sitemap File Hosted On Your Website.

The Google SiteMap file is an XML file that contains a list of URLs you want Google to index.

The Google SiteMap XML file has the following format:

 

Google Sitemap File
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
  <url>
    <loc>http://localhost:2905/SiteMaps/Default.aspx</loc>
    <lastmod>2005-10-30T03:13:58</lastmod>
  </url>
  <url>
    <loc>http://localhost:2905/SiteMaps/Products/Default.aspx</loc>
    <lastmod>2005-10-28T21:48:04</lastmod>
  </url>
  <url>
    <loc>http://localhost:2905/SiteMaps/Services</loc>
    <lastmod>2005-10-30T04:31:57</lastmod>
  </url>
  <url>
    <loc>http://localhost:2905/SiteMaps/Employees/Default.aspx</loc>
    <lastmod>1601-01-01T00:00:00</lastmod>
  </url>
  <url>
    <loc>http://localhost:2905/SiteMaps/Products/FirstProduct.aspx</loc>
    <lastmod>2005-10-30T03:43:52</lastmod>
  </url>
</urlset>

 

 

The Google SiteMap file contains a simple list of <url> elements that contain <loc> elements representing the location of the URL and <lastmod> elements representing the last modified date of the URL.

Note

The Google SiteMap file also can contain <changefreq> and <priority> elements. The <changefreq> element indicates how frequently a URL changes, and the <priority> element represents the priority of a URL relative to other URLs in your site. These elements are optional and are ignored here.

 

When you sign up at the Google SiteMaps website, submit the URL of the above file when you are asked to enter your SiteMap URL. The Google service retrieves your SiteMap from the handler automatically.

 

How to generate the ‘Google SiteMap XML file’ file automatically -

 

You can generate a Google SiteMap file automatically from an ASP.NET SiteMap. The below HTTP Handler generates a Google SiteMap File that conforms to Google's requirements for a valid SiteMap file.

 

HTTP Handler
<%@ WebHandler Language="VB" Class="PublicSiteMap" %>
Imports System
Imports System.Web
Imports System.Xml
Imports System.Text
Imports System.IO
 
Public Class PublicSiteMap
    Implements IHttpHandler
 
    Private _xmlWriter As XmlWriter
 
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler
.ProcessRequest
        context.Response.ContentType = "text/xml"
 
        Dim settings As New XmlWriterSettings()
        settings.Encoding = Encoding.UTF8
        settings.Indent = True
        _xmlWriter = XmlWriter.Create(context.Response.OutputStream, settings)
        _xmlWriter.WriteStartDocument()
        _xmlWriter.WriteStartElement("urlset", "http://www.google.com/schemas/sitemap/0.84")
 
        ' Add root node
        AddUrl(SiteMap.RootNode)
 
        ' Add all other nodes
        Dim nodes As SiteMapNodeCollection = SiteMap.RootNode.GetAllNodes()
        For Each node As SiteMapNode In nodes
            AddUrl(node)
        Next
 
        _xmlWriter.WriteEndElement()
        _xmlWriter.WriteEndDocument()
        _xmlWriter.Flush()
    End Sub
 
    Private  Sub AddUrl(ByVal node As SiteMapNode)
        ' Skip empty Urls
        If String.IsNullOrEmpty(node.Url) Then
            Return
        End If
        ' Skip remote nodes
        If node.Url.StartsWith("http",True,Nothing) Then
            Return
        End If
        ' Open url tag
        _xmlWriter.WriteStartElement("url")
        ' Write location
        _xmlWriter.WriteStartElement("loc")
        _xmlWriter.WriteString(GetFullUrl(node.Url))
        _xmlWriter.WriteEndElement()
        ' Write last modified
        _xmlWriter.WriteStartElement("lastmod")
        _xmlWriter.WriteString(GetLastModified(node.Url))
        _xmlWriter.WriteEndElement()
        ' Close url tag
        _xmlWriter.WriteEndElement()
    End Sub
 
    Private Function GetFullUrl(ByVal url As String) As String
        Dim context As HttpContext =  HttpContext.Current
        Dim server As String =  context.Request.Url.GetComponents( UriComponents
.SchemeAndServer,UriFormat.UriEscaped)
        Return Combine(server,url)
    End Function
 
    Private Function Combine(ByVal baseUrl As String, ByVal url As String) As String
        baseUrl = baseUrl.TrimEnd(New Char() {"/"c})
        url = url.TrimStart(New Char() {"/"c})
        Return baseUrl + "/" + url
    End Function
 
    Private Function GetLastModified(ByVal url As String) As String
        Dim context As HttpContext =  HttpContext.Current
        Dim physicalPath As String =  context.Server.MapPath(url)
        Return File.GetLastWriteTimeUtc(physicalPath).ToString("s")
    End Function
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return True
        End Get
    End Property
 End Class

 

 

Hope this helps.

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

 

Tuesday, September 8, 2009

Agile Resources - Scaling Software Agility

Hi,

 

Here is the link to download ‘Videos & WhitePapers’ to better understand the Agile.

Few highlights:

 

·         How to Explain the Financial Impact of Agile to Your Execs

·         Release Planning Guide

·         Iteration Planning Guide

·         Agile Imperative for SaaS Operations

·         Proving the Financial Impact of Agile

·         Making Agile Work for Your Bottom Line

Few more ..

·         The Top 3 Cost-Cutting Mistakes CIOs Make - And How to Avoid Them

·         Continuous Quality Management

·         Improved Software Design with Test-Driven Development (TDD)

Hope this helps.           

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

 

Monday, September 7, 2009

Conversion Myth

 

Input

Output

Object obj = null;               

 

string str1 = Convert.ToString(obj);

“”  (Blank)

string str2 = obj as string;

Null

string str3 = obj.ToString();

Exception – Object Reference not set to an instance of an object

 

 

Input

Output

Int? obj = null;               

 

string str1 = Convert.ToString(obj);

“”  (Blank)

string str2 = obj.ToString();

“”  (Blank)

 

 

Input

Output

Int obj = 0;               

 

string str1 = Convert.ToString(obj);

0

string str2 = obj.ToString();

0

 

 

Input

Output

string str = “”;

int i = Convert.ToInt32(str);

Exception  - Input string was not in a correct format

string str = “A”;

int i = Convert.ToInt32(str);

Exception  - Input string was not in a correct format

string str = null;

int i = Convert.ToInt32(str);

0

 

 

Input

Output

string str = “”;

int i = Int32.Parse (str);

Exception  - Input string was not in a correct format

string str = “A”;

int i = Int32.Parse (str);

Exception  - Input string was not in a correct format

string str = null;

int i = Int32.Parse (str);

Exception  - Value cannot be null.

 

 

Input string was not in a correct format.

 

 

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

 

Friday, September 4, 2009

Turning an .ascx User Control into a Redistributable Web Control

Hi,

 

http://msdn.microsoft.com/en-us/library/aa479318.aspx

 

As mentioned in the article above, we can turn the user control in to custom control. Please follow the following steps for the same;

ü       Create the user control

ü       Put in the stand alone visual studio web project and add the required dlls referencing the user control.

ü       Publish the web site

ü       Deselect "Allow this precompiled site to be updatable”

ü       Select "Use fixed naming and single page assemblies”

ü       This would result a dll file. Add this dll file in the CSTools or Veriphy web application’s bin folder

ü       Reference the user control in the aspx file like below;

<%@Register TagPrefix="YourControl" Namespace="ASP" Assembly="App_Web_yourcontrol.ascx.cdcab7d2"%>

     

There is small glitch here; the Namespace should always be “ASP”.

 

ü       Add the control on the page.

  < YourControl:devicenotification_ascx id="groupDeviceNotification" runat="server"/>

 

Hope this helps.

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

 

Taxi - Let me be non-technical

Taxi -

I arrived at the address where someone had requested a taxi. I honked (sound the horn) but no one came out. I honked again, nothing. So I walked to the door and knocked. 'Just a minute', answered a frail (weak), elderly voice. I could hear something being dragged across the floor.
 
After a long pause, the door opened. A small woman in her 90's stood before me. She was wearing a print dress and a pillbox hat with a veil pinned on it, like somebody out of a 1940s movie. 

By her side was a small nylon suitcase. The apartment looked as if no one had lived in it for years. All the furniture was covered with sheets. There were no clocks on the walls, no knickknacks or utensils on the counters. In the corner was a cardboard box filled with photos and glassware.  'Would you carry my bag out to the car?' she said. I took the suitcase to the cab, and then returned to assist the woman.

 She took my arm and we walked slowly toward the curb.  She kept thanking me for my kindness. 'It's nothing', I told her. 'I just try to treat my passengers the way I would want my mother treated'.'Oh, you're such a good boy', she said. When we got in the cab, she gave me an address, and then asked, 'Could you drive through downtown?''It's not the shortest way,' I answered quickly. 'Oh, I don't mind,' she said.

'I'm in no hurry. I'm on my way to a hospice' (hospital / rest room).  I looked in the rear-view mirror. Her eyes were glistening (shiny). 'I don't have any family left,' she continued. 'The doctor says I don't have very long.' I quietly reached over and shut off the meter. 'What route would you like me to take?' I asked.

For the next two hours, we drove through the city. She showed me the building where she had once worked as an elevator operator.  We drove through the neighborhood where she and her husband had lived when they were newlyweds. She had me pull up in front of a furniture warehouse that had once been a ballroom where she had gone dancing as a girl.  Sometimes she'd ask me to slow in front of a particular building or corner and would sit staring into the darkness, saying nothing.  As the first hint of sun was creasing the horizon, she suddenly said, 'I'm tired. Let's go now' 

 We drove in silence to the address she had given me. It was a low building, like a small convalescent (recovery) home, with a driveway that passed under a portico. Two orderlies came out to the cab as soon as we pulled up. They were solicitous (caring/atentive) and intent, watching her every move.They must have been expecting her.

I opened the trunk and took the small suitcase to the door. The woman was already seated in a wheelchair.  'How much do I owe you?' she asked, reaching into her purse. 
'Nothing,' I said 'You have to make a living,' she answered. 'There are other passengers,' I responded. Almost without thinking, I bent and gave her a hug.She held onto me tightly. 
 
'You gave an old woman a little moment of joy,' she said.  'Thank you.' I squeezed her hand, and then walked into the dim morning light. Behind me, a door shut. It was the sound of the closing of a life. I didn't pick up any more passengers that shift. I drove aimlessly lost in thought. For the rest of that day, I could hardly talk. What if that woman had gotten an angry driver, or one who was impatient to end his shift? 
 
What if I had refused to take the run, or had honked once, then driven away? 
On a quick review, I don't think that I have done anything more important in my life. 
 
We're conditioned to think that our lives revolve around great moments. But great moments often catch us unaware-beautifully wrapped in what others may consider a small one.  

 PEOPLE MAY NOT REMEMBER EXACTLY WHAT YOU DID, OR WHAT YOU SAID, BUT THEY WILL ALWAYS REMEMBER HOW YOU MADE THEM FEEL.  You won't get any big surprise in 10 days if you send this to ten people.. But, you might help make the world a little kinder and more compassionate by sending it on. 

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead