This thing still has some bugs

It looks like my plans on becoming a multi-billionaire referring links to Amazon have failed. 😛

Today I tried to include another book on my list, but the site simply started to generate wrong URLs.

Another bug that bothers me is the fact from time to time the lists don’t render correctly:

Let’s hope these bugs are fixed as soon as possible.

What do you do with the books you don’t want anymore?

I have lots of books. I buy lots of them, but I don’t want to keep all of them.
Some have already done their job – as the ones I bought to study towards certification. Others are simply bad books.
What do you do with the books you don’t want anymore?
Keep them anyway? Give them away? Sell them? How do you sell them?

Accessing a Web Service from within a browser’s client-side script

Have you already accessed a Web Service through the browser?
I’m not talking about that test page shown when you open the WSDL file in Internet Explorer.
I’m talking about accessing a Web Service through client-side script.
Imagine that you have a Web Forms application whose server does a Web Service operation on another server and passes the result back to the client. It serves only as a gateway between the client and the Web Service.
Using WebService Behavior there is no need to do this triangulation because the browser can access the Web Service directly using JavaScript or VBScript on Internet Explorer 5.0 or later.
The feature is exposed through an HTML component (*.htc) but unfortunately it isn’t supported (anymore?) by Microsoft.

Global.asax event handling internals (part 3 of 3)

// In HttpApplicationFactory

private void HookupEventHandlersForAppplicationAndModules(MethodInfo[] handlers)
{
      // handlers receives a list of Global’s methods.
      for (int num1 = 0; num1 < handlers.Length; num1++)
      {
            MethodInfo info1 = handlers[num1];
            string text1 = info1.Name;
            int num2 = text1.IndexOf('_'); // Splits the method name to get the object and method’s name.
            string text2 = text1.Substring(0, num2);
            object obj1 = null;
            if (string.Compare(text2, "Application", true, CultureInfo.InvariantCulture) == 0)
            {
                  obj1 = this// Maps “Application_*” to HttpApplication
            }
            else if (this._moduleCollection != null)
            {
                  obj1 = this._moduleCollection[text2];
            }
            if (obj1 != null)
            {
                  // Tries to get an EventDescription that matches a method in Global.
                  Type type1 = obj1.GetType();
                  EventDescriptorCollection collection1 = TypeDescriptor.GetEvents(type1);
                  string text3 = text1.Substring(num2 + 1);
                  EventDescriptor descriptor1 = collection1.Find(text3, true);
                  if ((descriptor1 == null) && (string.Compare(text3.Substring(0, 2), "on", true, CultureInfo.InvariantCulture) == 0))
                  {
                        text3 = text3.Substring(2);
                        descriptor1 = collection1.Find(text3, true);
                  }
                  // Gets a method that corresponds to the “+” in Type.Event += EventHandler
                  MethodInfo info2 = null;
                  if (descriptor1 != null)
                  {
                        EventInfo info3 = type1.GetEvent(descriptor1.Name);
                        if (info3 != null)
                        {
                              info2 = info3.GetAddMethod();
                        }
                  }
                  if (info2 != null)
                  {
                        ParameterInfo[] infoArray1 = info2.GetParameters();
                        if (infoArray1.Length == 1)
                        {
                              Delegate delegate1 = null;
                              ParameterInfo[] infoArray2 = info1.GetParameters();
                              if (infoArray2.Length == 0)
                              {
                                    if (infoArray1[0].ParameterType != typeof(EventHandler))
                                    {
                                          goto Label_0168;
                                    }
                                    ArglessEventHandlerProxy proxy1 = new ArglessEventHandlerProxy(this, info1);
                                    delegate1 = proxy1.Handler;
                              }
                              else
                              {
                                    try
                                    {
                                          // Creates the delegate. Corresponds to “new EventHandler(metodoDeGlobal)”
                                          delegate1 = Delegate.CreateDelegate(infoArray1[0].ParameterType, this, text1);
                                    }
                                    catch (Exception)
                                    {
                                          goto Label_0168;
                                    }
                              }
                              try
                              {
                                    object[] objArray1 = new object[1] { delegate1 } ;
                                    // Binds the method to the event. 
                                    // Corresponds to executing the “+” in Type.Event += EventHandler                                    info2.Invoke(obj1, objArray1);
                              }
                              catch (Exception)
                              {
                              }
                        }
                  }
            }
      Label_0168:;
      }

}

Global.asax event handling internals (part 2 of 3)

// HttpApplication class, from which Global is derived.
private void ReflectOnApplicationType()
{
      // Enumerates all Global and it’s wrapper methods..
      ArrayList list1 = new ArrayList();
      MethodInfo[] infoArray1 = this._theApplicationType.GetMethods(BindingFlags.NonPublic | (BindingFlags.Public | (BindingFlags.Static | BindingFlags.Instance)));
      MethodInfo[] infoArray2 = infoArray1;
      int num2 = 0;
      while (num2 < infoArray2.Length)
      {
            MethodInfo info1 = infoArray2[num2];
            // If the method’s name looks like an event handler, adds it to the list.
            if (this.ReflectOnMethodInfoIfItLooksLikeEventHandler(info1))
            {
                  list1.Add(info1);
            }
            num2++;
      }
      Type type1 = this._theApplicationType.BaseType;
      if ((type1 != null) && (type1 != typeof(HttpApplication)))
      {
            infoArray1 = type1.GetMethods(BindingFlags.NonPublic | (BindingFlags.Static | BindingFlags.Instance));
            infoArray2 = infoArray1;
            for (num2 = 0; num2 < infoArray2.Length; num2++)
            {
                  MethodInfo info2 = infoArray2[num2];
                  if (info2.IsPrivate && this.ReflectOnMethodInfoIfItLooksLikeEventHandler(info2))
                  {
                        list1.Add(info2);
                  }
            }
      }
      // Stores the list of methods for further use.
      this._eventHandlerMethods = new MethodInfo[list1.Count];
      for (int num1 = 0; num1 < this._eventHandlerMethods.Length; num1++)
      {
            this._eventHandlerMethods[num1] = (MethodInfo) list1[num1];
      }
}

 

//Também na classe HttpApplicaton

private bool ReflectOnMethodInfoIfItLooksLikeEventHandler(MethodInfo m)
{
      ParameterInfo[] infoArray1;
      string text1;
      if (m.ReturnType == typeof(void))
      {
            infoArray1 = m.GetParameters();
            switch (infoArray1.Length)
            {
                  case 0:
                  {
                        goto Label_007A;
                  }
                  case 2:
                  {
                        // The event handler’s traditional signature in .NET: object, EventArgs
                        if (infoArray1[0].ParameterType != typeof(object))
                        {
                              return false;
                        }
                        if ((infoArray1[1].ParameterType != typeof(EventArgs)) && !infoArray1[1].ParameterType.IsSubclassOf(typeof(EventArgs)))
                        {
                              return false;
                        }
                        goto Label_007A;
                  }
            }
      }
      // If it doesn’t have 0 or 2 parameters, the method is not an event handler.
      return false;
Label_007A:
      text1 = m.Name;
      int num1 = text1.IndexOf('_');
      if ((num1 <= 0) || (num1 > (text1.Length - 1)))
      {
            // “_” has to be within the name but it cannot be neither the first nor the last character.
            return false;
      }
      // Special cases that won’t be treated in HookupEventHandlersForAppplicationAndModules
      if ((string.Compare(text1, "Application_OnStart", true, CultureInfo.InvariantCulture) == 0) || (string.Compare(text1, "Application_Start", true, CultureInfo.InvariantCulture) == 0))
      {
            this._onStartMethod = m;
            this._onStartParamCount = infoArray1.Length;
      }
      else if ((string.Compare(text1, "Application_OnEnd", true, CultureInfo.InvariantCulture) == 0) || (string.Compare(text1, "Application_End", true, CultureInfo.InvariantCulture) == 0))
      {
            this._onEndMethod = m;
            this._onEndParamCount = infoArray1.Length;
      }
      else if ((string.Compare(text1, "Session_OnEnd", true, CultureInfo.InvariantCulture) == 0) || (string.Compare(text1, "Session_End", true, CultureInfo.InvariantCulture) == 0))
      {
            this._sessionOnEndMethod = m;
            this._sessionOnEndParamCount = infoArray1.Length;
      }
      return true;
}