Thursday, March 21, 2013

[C#] How to read custom config Section in C#

step 1. Create a class to handle custom configuration elements. in this sample called "MyAttribute"

and this class will be responsible for reading following element from config file



<add myAttributeId="6" myAttributes="1" />



using System.Configuration;

namespace MyApp.Configurations
{
    public class MyAttributeConfigurationElement : ConfigurationElement
    {
        [ConfigurationProperty("myAttributeId", IsRequired = true)]
        public int MyAttributeId
        {
            get
            {
                return (int)this["myAttributeId"];
            }
            set
            {
                this["myAttributeId"] = value;
            }
        }


        [ConfigurationProperty("myAttributes", IsRequired = true)]
        public string MyAttributes
        {
            get
            {
                return (string)this["myAttributes"];
            }
            set
            {
                this["myAttributes"] = value;
            }
        }
    }
}

step 2 create class to handle config element collection. as follows


using System.Collections;
using System.Collections.Generic;
using System.Configuration;

namespace MyApp.Configurations
{
    public class MyAttributeConfigurationCollection : ConfigurationElementCollection, IEnumerable
    {
        ///





        ///
        ///
        ///
        ///
        public MyAttributeConfigurationElement this[int index]
        {
            get
            {
                return BaseGet(index) as MyAttributeConfigurationElement;
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        ///





        ///
        ///
        public IEnumerable Elements
        {
            get
            {
                for (var i = 0; i < Count; ++i)
                {
                    yield return this[i];
                }
            }
        }

        ///





        ///
        ///
        ///
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        ///





        ///
        ///
        ///
        public new IEnumerator GetEnumerator()
        {
            for (var i = 0; i < Count; ++i)
            {
                yield return this[i];
            }
        }

        ///





        ///
        ///
        ///
        protected override ConfigurationElement CreateNewElement()
        {
            return new MyAttributeConfigurationElement();
        }

        ///





        ///
        ///
        ///
        ///
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((MyAttributeConfigurationElement)element).MyAttributeId;
        }
    }
}




step 3. Create Class to handle custom configuration section. Here called "MyAttributeSection"


using System.Configuration;

namespace MyApp.Configurations
{
    public class MyAttributeConfiguration : ConfigurationSection
    {
        private static readonly MyAttributeConfiguration MyAttributeConfigSection
            = ConfigurationManager.GetSection("myAttributeConfigSection") as MyAttributeConfiguration;

        public static MyAttributeConfiguration Section
        {
            get
            {
                return MyAttributeConfigSection;
            }
        }


        [ConfigurationProperty("myAttributeConfig")]
        public MyAttributeConfigurationCollection MyAttributeConfig
        {
            get
            {
                return this["myAttributeConfig"] as MyAttributeConfigurationCollection;
            }
        }
    }
}

step 4 create a config file entry to be read by the classes we have created so far



<configSections>
    <section name="myAttributeConfigSection" type="MyApp.Configurations.MyAttributeConfiguration,MyApp" />
</configSections>
<myAttributeConfigSection>
    <myAttributeConfig>
      <add myAttributeId="6" myAttributes="1" />
    </myAttributeConfig>
</myAttributeConfigSection>





Friday, March 1, 2013

[ASP .Net MVC3] ASP.Net MVC Execution flow

Ref

A typical flow of Web Request comes to MVC Application is handled as follows

WebRequest ->  UrlRoutingModule -> MVCRouteHandler (Extracted from Route Object and implements IRouteHandler) 
  1. MvcHandler (IHttpHandler) 
  2. RequestContext
-> Controller

So to understand it better let see the flow simpler way :-

At very first request comes to UrlRoutingModule which is a http module very similar to the any web request processor (Asp.Net engine or IIS). This parse the request and select route from requested URL. Once parsing complete UrlRoutingModule select the first route object which matches to the parsed request. (Route object is the object which is used at Global.asax). read more about routing object

if no route is matched url is processed as normal url (as processed on asp.net or iis).


After route object is selected RequestContext is created and an instance of MvcRouteHandler is extract from the route object creates MvcHanlder object and pass RequestContext to it.

Once MvcHandler object is obtained, MVCHandler selects appropriate Controller to serve request.

Later Execute method is performed on the controller to perform the action.

For controllers that inherit from the ControllerBase class, the ControllerActionInvoker object that is associated with the controller determines which action method of the controller class to call, and then calls that method.

Once Action is executed Result is served as Allowed Result Type (i.e. ViewResult, RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, FileResult, and EmptyResult.)


Tuesday, March 20, 2012

MatWalle


"MatWaale", now there is no better word I can come up for these guys, who, I came to know when I reached Mumbai. This particular bunch of "matwaale" was introduced to me in late July of 2009. To be honest, 2 were introduced but rest were imposed (just kidding). As 2 of these guys were my (official) flatmates (Anuj and Anurag) at that time.


Lucky me, that both worked in TCS while I was looking for a place to live.  My friends gave me their contact details from an advertisement posted on TCS portal. When I first met them, both looked fairly normal but turst me it is not at all true. If I could compare now, their normal looks were nothing less than a mirage. There is something about this group which you start noticing after few close encounters and to worsen the matters, it changes when you know them fully :D.

So as I said, initially they both were formal but as time passed by, I tend to spend more time in their gourp which had increased to 4-5 without me noticing it :P . These chaps are like sugar mixed milk you will never notice how smoothly, they pull you in their group. in no time you will be part of the pack.

Before I could have realized, by the end of 2009 I was an important part of the pack (at-least, i think so). That time I realized the major strength of the group of HCST. That is love and unsaid respect towards each other even though it doesn't reflect in the way they talk to each other but the way they treat you, stand by you, come forward in need and so many small gestures.

I came to know many of these amazing creatures naming MohitAnujVivek, Anurag, Atul, Abhishek and so many that if I start writing names the blog will go for that only :P . Each person have their own individual character but when they are togather they are just HiCoSTians. All these people are still living their college life even after college is over (I envy these guys).

After I left the pack for no good reason I tried to be in close radius to the group. I was a regular to their apartment even sometime instead of going to my home I used to go to directly their flat after hectic office shifts. It was refreshing to listen to Lambu, Ciar, Budhauu and Mamma(these are what bangalis call daak naam in bangla, in english pet names; now, you figure out which belongs to who) arguing, teasing, pulling leg.

I  never felt that they are not from my college as I was treated with equal respect, love and brotherhood.

I wish all the best and bright future to all my HiCoSTian amigos.

Saturday, April 9, 2011

Cleaning of a Corrupt nation

Now a days nearly every Indian is talking about corruption. either remove it or preserve it :)

Anna hazare is portraited as new generation's Gandhi and this is what he deserve. He is my hero.  But i will not spend my time on what's happening because media is already covering that. I will share my experience about corruption and how my frd circle react about it. How they feel about this against corruption campaign.

I have seen few supporting the campaign virtually i mean they stayed in there home or office. Clicked links on web page or given a miss call. If they wanted to do more they joined the local groups for supporting the campaign. I respect it and i think at least something is done. But this doesn't make me comfortable that corruption will be gone from my nation.

This is something which is very similar to freedom fight of India. When everybody joined hand in hand against East India Company. That was the time no one care how much they need to suffer in order to get the freedom. But it is the case in my Nation right now ? Are we ready to suffer in order to clean our nation from corruption ?

I am not negative person please do think i don't support current campaign. I have done this virtually and yes i have not done anything else for this campaign. Now one can say then why writing so much when you are also not better than anyone else. But as i am free to think about my country i am free to write about what i think i happening around me.

Some of my friends are still not convince that something gonna happen. For that same reason they are ignoring this campaign fully but i am not in that group i grab every possible opportunity to do my bit. But what i do is not important. Important is what whole nation does.

I agree a single person "Anna Hazare" made the difference. But think about a single person stopped paying bribe in my current nation what will happen. Yes he will be screwed royally. Starting something and getting media's attention is not tough now a days. Forcing government to listen you is tough. But the toughest thing is to clean the building blocks of a nation and that's US.

Now i am leaving this post unfinished because after this every individual has to write by his own self. What their thought, what they want to do and how they will clean their nation.

Sunday, August 1, 2010

Ya kundendu tusharahaar dhawala

Yes it's been a long time and now also i am not very happy about the topic i am writing. As many of as might have forgotten as i have done THE "Saraswati Vandana". From last two three days i was trying to search few nice violin scores. During the search of those 3-4 minutes music wonders i came across a concert recorded by Ustaad Sultaan Khaan (Great Sarangi player) and Ustd Zakir (Tabla player). i started to just get the flavour of Sarangi as well. I started without paying attention on the length on concert recording but this over an hour length of recording was great pleasure to listen and same time i was ashamed of not listening this earlier.

Apart from the guilt of not able to listen that earlier there was another guilt and that was the forgetting the roots. In mid of the concert Ustad Zaakir hussain stops the people from distrubing them from continous photoshoots. Which makes a point that few people still don't go for these concerts for listening them playing, they just simply want to show off. So lame !!! While Ustad Zaakir hussain stopping others he took the ref. of sarswati vandana. Which make me recall, YES recall i have forgotten that. As now a days we people take every art is just as medium of fame and money. Today i have a reason why our musicians are not so popular as from other countries because they get pleasure in there sarswati vandana. For these mastros sarswati vandana is their music. They really don't care about fame and money.

And sucha a shame for we people that we still didn't heard many of those maters of music in this country. At least i feel shameful for this.

http://www.youtube.com/watch?v=EPQU9Egoe2Q  Link for the concert which hold me for over an hour while musicians like Samvel Yervinyen and Yanni wasn't able to grab my attention for 2-3 minutes.

Please do go for these concerts atleast if there are any near you. Not for telling people that u have been to such and such concert, But to listen and experience the legends.

Saturday, April 17, 2010

The jail and Poseidon's place

It's nearly 12:00 am and I am in The Jail... Yes, it doesn't come as a surprise to me that i am in The Jail; though you might wonder about it. I always knew this day will come someday but I never expected it to come so soon. I was accompanied to Jail by 3 of my friends - mohit, atul and abhishek. While sitting in there, I recalled the time when once i asked a small-shop keeper "Bhai jail kaise jaate hain ??" and he replied to me "bahut aasan hai, kisi ka khoon kar do". And I told him "Kuch tod-phod par bhi jail ho jaati hai na, lekin mujhe to jail jaana hai".




Oh, I guess by now you people might have guessed it. If no, then let me enlighten you that 'The Jail' is a place here in mumbai to eat and drink. This place has theme of Jail, waiters are dressed as convicts, Managers are dressed as cops. Overall, a nice place to visit. Later I managed to come back to home around 1:30 am and slept around 4:00 am.



While sleeping i felt something was scratching my feet. At first I felt it's a mouse or something else. I opened my eyes just enough to grab a glimpse of what's there on my foot. But i had to open them wide enough to grab full view of Vivek (my roomie cum college Junior). I tried an unsuccessful attempt to go back to the sleep after letting him that I wanted to sleep (I think it's was around 7 am).



But he said it's serious and he made a blunder. It was time to pay attention, obviously, when he woke me up in morning there would be a good reason to grab my attention is such wee hours. I thought, It better be. I jumped from the bed to talk to him with all of my attention but holy god, what was that? I was in Poseidon's place!!! Everywhere was water (let me stop for a moment and tell you that the flat we live in, is on 2nd floor). This discarded the possibility of flood at once. I asked him few questions which he answered without delay. I was informed about a tap of our kitchen which was left opened when water supply was not there. That bloody f***ing tap !!



And to get you guys some extra but relevant information : there is a 1500/- fine in our society over water lodging + some 1000/- plumbing charges. So taking these things in consideration my roomie looked a bit tensed. By now I was rolling my eyes on the surroundings which included my newly bought desktop cabinet which was on the floor in nearly 3' water with the home theater lying beside it. Suddenly I got the chance to look on the black thing in my roomie's hand it was my 5 years old laptop dripping the water line. It was enough to stop looking for the losses. I tried to look stable than angry to avoid increasing the tension around. While, Vivek tried to avoid it unsuccessfully by letting me know that water was flowing out of flat.



After analyzing the situation I was in the action mode. I had to start doing something to show myself that situation can be controlled and it's progressing. I asked him to grab a clothe and start pushing water in bathroom. While, he was doing this I went to the kitchen and opened the choked sink by removing the plate covering the vent. This gave me a bit relief that something was happening to smooth our pains. When i joined him back to guide water-flow towards bathroom. We had a small discussion about getting wiper which was ruled out by me within nano-second by considering there was no way we could get one in morning 7'O clock.



I used my bathroom sleepers to join the rescue mission and used them as wiper. Which worked quiet well. Being an Engg. it's the benefit, I guess. Within next few minutes, water level was reduced and to confirm it I asked him to check if water had stopped flowing outside the flat. He nodded in a 'Yes'. I asked him to use my hand made wiper which he refused to use within less than 30 second after giving it a shot as he was not able to use that. But he kept pushing the water with the cloth he was using earlier. I pushed water to the toilet with my self-made instrument. After some time I asked him to use the cloth to soak the water and then rinse that in bucket. And then we came back to the living room where I found that every thing which was lying on the floor was flooded by then and most of the papers ( including my schooling and degree certificates) were drenched.



I was not angry at all, I don't know why but I was laughing. I was laughing for no reason for next few minutes and then I came back to the work of getting water using towel soaking and rinsing in bucket with him. Within 1:30 hour we cleared the water from flat. And without saying even a single word we both went back to sleep as we were too tired to discuss anything.....



P.S. Desktop got saved because motherboard was high enough inside the cabinet to avoid water. Laptop and home theater are still in getting dry. Certificates are not so damaged as we thought at first.
 
Thanks to @Viveky for doing some editing on a short notice :)

Wednesday, March 10, 2010

Encounter with snow [Episode 2]

Ram wanted to go by walk and see what's blocking the road. So we started walking but after not more than 10 or 20 meter i relaised this is foolishness and i told ram to walk back. Ram took this seriously and agreed with me and we headed towards bike. now Because of mud we were not able to move bike back but somehow after 5 minute we were able to rotate bike 180 degree and we were heading back on the track towards karsog. We were tired hungry but if we would have stopped we couldn't have reached karsog on same day. Point to be noted we had breakfast at around 9:30 in morning and since afternoon we are hungry & riding. Now on this way back to karsog i was on rider seat. I was having only one aim reach karsog before it even get drak [Main reason was we were having very less money to afford food and accomodation]. I started riding bike at 3:30 Ram was riding bike from 8:30 in monring and he was tired enough to not on rider seat. It took me 5 hours to reach karsog and i didn't stopped at any place just to reach karsog ram was asking me to stop to loo. But i just kept asking him to hold on till karsog. Finally we reached karsog at 8:30 and everything was at halt. Very rear shops were open. Some how we we got few person on road to ask about accomodation. While asking the hotel we again fallen down. This time my knee doesn't supported me and i couldn't support bike while it was on halt. I start blaming ram for this fall but i knew this was sole my fault. Anyway ram didn't reacted harsh [Later in hotel i confessed ram that was my fault].
     Sooner we reached karsog we withdrawl enough money for the trip and kept that with us. Later we found a costly hotel (according to locals rent was 500/- very nice room but it's costly). There we saw that there is pipe unjoint at one end hanging from bike. Trouble again but we left that on morning task and went for dinner. I purchased few warm clothing which really helped me. We got nice food in hotel and slept nicely.
     Next morning 6'0 Clock we started our journey towards manali via sundernagar and kullu. We drove for hours but during this ride we saw very beautiful nature we saw jungle. So many curved roads. We were so in touch with curved roads that when we got straight road we were riding on speed of 30-40 only. Later we realised we can go on some high speed. Around 1 we reached mandi. Which was only 110 Km from Karsog. We had lunch and again started the trip. We encountered very beautiful road ahead very sencenic. Beas River was adding more charm to this road
. There was an 2-3 Km tunnel in between which was also a great pleasure to ride on. While driving we stopped just before kullu to swith the rider. That time ram told me take a look on road sode snow
. Now as ram was on rider seat he started to get bad road and he was not so happy to ride on. But there was no other way. After some 10-15 mintue ram applied a sudden break while i was enojoying the nature without any clue that ram is going make a sudden fall. I just managed to jump before we fall again. Within seconds we managed to get bike on wheels again and riding back on road :). Ram was pissed off by now as few junkyard eligible trucks was fooling around on road. Finally off there this and that we reached to manali. And i tell you ram was back in full "Josh" as he was heading towards rohtang pass. Which didn't said anything but we took stopped to see manali natural beauty
.
          Now ram was riding with aim of rohtang pass which i was not in accord but i didn't told him. We saw some really bad roads and this was nearly 4 after noon. i was worried about night stay. Ram was riding with his aim then later saw some really bad road where we were not able to move
. Indian Army was on work to make it clear. some people were in hurry
. But we utilized this time to enjoy the nature
. We headed again on roll. Reached to shilong. This was the real natural beauty which were aiming for. Now this was satisfying this much long journey
. We  reached to the place where snow games were going on. People were enjoying the sking and paragliding. Some couple were happy with snow only. anyway worthfull to come this far. Ram were trying to go ahead but locals told there is no way furthur road is blocked due to snow.
         We stopped and done the paragliding which earlier ram was not ready to do so. But finally he did.
.  Later we made frds with rinkoo the guy who arranged the paragliding for us. He told that we can do skiing in the morning around 8 as we were planning to leave manali in morning. He showed us one beautiful, shortcut (bad road) for manali which was really helpful for bike riders
.

        Later came back to manali nearly 6 was on clock. We decided to watch "My name is khan". We had dinner and taken some rest in hotel. At 9 we reached at mall to watch movie. Movie started ok and in interval as expacted on rash thing happened. Some local couple were on seats infront of us. Ram tried to take out his mobile from his jeans pocket and his shoe hit the seat back infront of him. And this lady sitting on that seat got rash. This i tried to make her quiet but things went wrong. Not only wrong way wrong too much. His mate got angry for various reasons (might be for talibans also but i have no clue). Locals also came in support of those couple. Justg because of this i think "chadyaan di joon buri". It's an punjabi saying which means bachelorhood is worst. One uncle grabbed my collar and dragged my out of hall. I was in shock all was happening so fast. Ram was asking everyone to stop it but i was not i mood to avoid the collar drag.

      Later somehow uncle who grabbed my collar taken me with him to lower level to watch the movie infact he seated next to us and watched  movie along us. He was actually protacting us. from thos locals who were in chance to take some cheap advantage in there city and in eyes of there girls. Later in end of movie uncle again dragged me by holding my hand with him towards his car. Ram also approached me uncle dropped us to our hotel for avoiding the problems which could have happened. Thanks a lot uncle.

      Next day in morning ram was not in mood to go for skiing but he got ready some how. We headed towards skiing aread and called rinkoo to be ready there. We reached to shortcut rickoo was already there to help us to reach skiing area. We reached there and done skiing. Nice experience

. Later head back on our long and boring jouney to back to chandigarh. We started around 11 in morning and reached chandigarh at 9:30 in night. After mandi full journey was very boring. but over all total trip was great...