July 2007 - Posts

AOP and Spring.NET

Today I wrote a nice code using AOP and Spring.NET.I used IOC facilities of Spring.NET and it is really fantastic. Implementing some interfaces and a little bit of code you can have great and flexible code.

This is an example of interface that you must implement:

using System;
using System.Reflection;
using Actvalue.Data.Interfaces;
using My.JobProfiler.Entities;
using Spring.Aop;

namespace My.AOP
{
    public class CVLoggingAfterAdvice : IAfterReturningAdvice
    {
        public void AfterReturning(
           object returnValue, MethodInfo method, object[] args, object target)
        {
            EasyCV.Entities.CVStatus st;
            if (args.Length > 0)
                st = (EasyCV.Entities.CVStatus)args[0];
            else return;
            IUnitOfWork UoW = DataAccessProviderFactory.GetConversationUnitOfWork();
            CVHistory obj = new CVHistory();
            obj.CV = UoW.GetByKey<Actvalue.JobProfiler.Entities.CVCore>(st.cvst_cvcr_id);
            obj.Modified = DateTime.Now;
            obj.Status_Id = st.cvst_cvtypologicalId_State;
            obj.Type_Id = st.cvst_cvtypologicalId_Type;
            obj.User = "rew";
            UoW.RegisterNew(obj);

        }
    }
}

 

After running a method I logged everything there without change class (class that I call) that works. After in web.config I used IOC Spring facilities:

 <spring>
    <context>
      <resource uri="config://spring/objects" />
    </context>
    <objects xmlns="http://www.springframework.net">
      <description></description>

      <object id="afterAdvice" type="My.AOP.CVLoggingAfterAdvice, Actvalue.AOP" />
      <object id="throwsAdvice"  type="My.AOP.CVLoggingThrowsAdvice, Actvalue.AOP" />

      <object id="CVStatusChanged" type="Spring.Aop.Framework.ProxyFactoryObject">
        <property name="Target">
          <object type="My.DataAccessLayer.CVStatusDAL, My.DataAccessLayer" />
        </property>
        <property name="InterceptorNames">
          <list>
            <value>afterAdvice</value>
            <value>throwsAdvice</value>
          </list>
        </property>
      </object>
    </objects>
  </spring>

 
This is a little methos test for see if it works:

        [NUnit.Framework.Test()]
        public void CVHistoryTest1()
        {
            // Create AOP proxy using Spring.NET IoC container.
            IApplicationContext ctx = ContextRegistry.GetContext();
            ICVStatus command = (ICVStatus)ctx["CVStatusChanged"];
            My.Entities.CVStatus obj=new CVStatus();
            obj.cvst_cvcr_id = 23;
            obj.cvst_cvtypologicalId_State = 588;
            obj.cvst_cvtypologicalId_Type = 592;
            obj.cvst_dateinserted = DateTime.Now;
            obj.cvst_dateupdated = DateTime.Now;
            obj.cvst_profcatassigned = 12111;

            command.Update(obj);
            
        }

I used more times AOP with Spring.NET and it is a great framework for AOP too (for IOC maybe is the best). Maybe in future I will write an article about AOP in Spring.NET...

Bye 

Antonio 

DateTimeFormat

Sometimes you want to convert a specific culture date string in a DateTime, you can create a DateTime for InvariantCulture in VB.NET in this way:

 Dim paramvalue As Object = DateTime.ParseExact("23/11/2007", "dd/mm/yyyy", System.Globalization.CultureInfo.InvariantCulture)

 

or if you want by a specific culture :

    Dim myDTFI As DateTimeFormatInfo
        myDTFI = New CultureInfo("it-IT", False).DateTimeFormat

        myDTFI.ShortDatePattern = "dd/MM/yyyy"
        Dim MyDate As DateTime = DateTime.Parse("20/06/2007", myDTFI)

 

Bye 

Antonio :-) 

Posted 11 July 2007 12:24 PM by antrad | no comments
Filed under:
xhtmlConformance Element and Cassini

Today I was working with Watin, a framework for testing of web pages in .NET, using Cassini web server integrated in VS2005. I found a strange problem in referencing html control generated by asp.net.I saw that it create tags in this way:

<td class="width175px">
            <span id="ManageRichiesta1_Label3" class="lbl">Professione *</span>
        </td>

and some other controls in this way:

ManageRichiesta1$ChooseProfessionalCategories1$MasterTableSelectControl1$HierarchicControlSearch1$cntSearch$txtSearch 

and we had a method that process  that use "_" for process controls. It happened with Cassini Web Server, IIS generate ever control with "_" char.

So I found this this config element xhtmlConformance. I resolved the problem of "_" with Legacy option but my Ajax controls didn't postback correctly. For resolve I used

<xhtmlConformance mode="Strict" />

that is the most right way and I write different method where I control what is the web server by this method:

System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName

:-((((((((((

Antonio 

 

 

Posted 10 July 2007 09:29 AM by antrad | no comments
Filed under:

This site

Search

Go

This Blog

Syndication

Sponsors

  • MaximumASP
  • Breaking News
  • Find a Job
  • Social Bookmarking
    Tidebuy Reviews
    Online Shopping
    asp.net hosting
    UK online local dating