Solved

How to trigger functions in asp.net/vb.net

Posted on 2009-07-15
4
668 Views
Last Modified: 2013-11-08

Hi

I have myhandler.ashx file and which has code behind file  at "app_code/myhandler.ashx.vb" .
myhandler.ashx file  will be triggered by some external process.

in myhandler.ashx file , i write below code:
perform

Public Class PaypalColorHandler : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
  step1:  ' execute some logic to perform generic process.
 step2:    strTransactionType = context.Request.Form("transaction_type")
         Select Case strTransactionType
                   
                    Case Is = "XYZ"
                        //execute some logic to handle transaction "XYZ"

                   CAse Is=""ABC"
                       //execute logic to handle transaction "ABC"
   etc..



     //send response back to external process who isntiated call
    //logic for handling sedning response back to external process.
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class
 

I want to write generic class to handle above to re-use above accross the projects.

i am thinking to write like this,
   i wanto create "generichandler.vb" handler which other devlopers can call .
  Devopers still create their own .ashx file with own code behind file(Devloperown.ashx.vb) and they still write Processrequest()  in DevloperOwn.ashx.vb.  But inside processRequest() fucintion they call "create object of generichandler" and call "handleRequest()" function.

Please let me know how to  initiate triggers in "genricHanlder.vb"  to call "ABCTrigger(),XYZTrigger() etc. also syntax for how to define functions these fucntions.
Please let me know.
alos Is it possible to write these "ABCTrigger() and XYZTrigger() " functions  inside devloperhandler(DevloperOwnHandler.ashx.vb) itself instead of writing in "genericHandler.vb" file.



Current Code: Myhandler.ashx.vb

Public Class  MyHandler: Implements IHttpHandler
 

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

  step1:  ' execute some logic to perform generic process.

 step2:    strTransactionType = context.Request.Form("transaction_type")

         Select Case strTransactionType

                    

                    Case Is = "XYZ" 

                        //execute some logic to handle transaction "XYZ"
 

                   CAse Is=""ABC"

                       //execute logic to handle transaction "ABC"

   etc..
 
 
 

     //send response back to external process who isntiated call

    //logic for handling sedning response back to external process.

End Sub
 

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable

        Get

            Return False

        End Get

    End Property
 

End Class

 

....
 

generichandler.vb:

 Public Class generichandler

    public sub handleRequest(ByVal context As HttpContext)

       step1:  ' execute some logic to perform generic process.

 step2:    strTransactionType = context.Request.Form("transaction_type")

         Select Case strTransactionType

                    

                    Case Is = "XYZ" 

                       // ' trigger XYZTrigger() //to perform logic for transaction "XYZ"
 

                   CAse Is=""ABC"

                     //   ' trigger ABCTrigger() //to perform logic for transaction "ABC"   etc..
 
 
 

     //send response back to external process who isntiated call

    //logic for handling sedning response back to external process.

' 

  End Sub
 

public sub ABCTrigger()  

' implementation defered to devloepr to write own logic to perform database updates etc..

end sub

   End Class
 

public sub XYZTrigger()  

' implementation defered to devloepr to write own logic to perform database updates etc..

end sub

   End Class

Open in new window

0
Comment
Question by:ram27
  • 2
4 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 24863185
Maybe I totally misread, but it seems developers should inherit from your class here.  You might also need to declare some methods "MustOverride" so when they do this, they are forced to extend the functionality or it will not compile.
0
 

Author Comment

by:ram27
ID: 24865019
i mentioned in my post may not be righ
Please see below i reframed my question see below:

I have myhandler.ashx file and which has code behind file  at "app_code/myhandler.ashx.vb" .
myhandler.ashx file  will be triggered by some external process and based on the trasaction type, i want to execute different logic(will be specefic for each project) . Implementation logic for each transaction  want to defer to devlopers.
here is my code for "myhandler.ashx.vb":


Public Class myhandler: Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
  step1:  ' execute some logic to perform generic process.
 step2:    strTransactionType = context.Request.Form("transaction_type")
         Select Case strTransactionType
                   
                    Case Is = "XYZ"
                        //execute some logic to handle transaction "XYZ"

                   CAse Is=""ABC"
                       //execute logic to handle transaction "ABC"
   etc..



     //send response back to external process who isntiated call
    //logic for handling sedning response back to external process.
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class
 


Pease let me know best way to achive this.
i have below  approach in mind:
create class called "myhandler"

I want to write generic class for above (myhandler.aspx.vb) to re-use   the accross the projects.

i have below approach in mymind
" create "generichandler.vb" handler which other devlopers can call .
  Devopers still create their own .ashx and .vb files with own code behind file(Devloperown.ashx.vb) and they still write Processrequest()  in DevloperOwn.ashx.vb.  But inside processRequest() fucintion they  "create object of generichandler" and call "handleRequest()" function. in this parroach,
Please let me know how to  initiate trigger/fire events  in "genricHanlder.vb"  to call "ABCTrigger(),XYZTrigger() etc based on the transaction type. . also syntax for how to define functions these fucntions.
Please let me know.
alos Is it possible to write these "ABCTrigger() and XYZTrigger() " functions  inside devloperhandler(DevloperOwnHandler.ashx.vb) itself instead of writing in "genericHandler.vb" file.
code:
generichandler.vb:
 Public Class generichandler
    public sub handleRequest(ByVal context As HttpContext)
       step1:  ' execute some logic to perform generic process.
 step2:    strTransactionType = context.Request.Form("transaction_type")
         Select Case strTransactionType
                   
                    Case Is = "XYZ"
                       // ' trigger XYZTrigger() //to perform logic for transaction "XYZ"
 
                   CAse Is=""ABC"
                     //   ' trigger ABCTrigger() //to perform logic for transaction "ABC"   etc..
 
 
 
     //send response back to external process who isntiated call
    //logic for handling sedning response back to external process.
'
  End Sub
 
public sub ABCTrigger()  
' implementation defered to devloepr to write own logic to perform database updates etc..
end sub
   End Class


Please let me know whether the above approach makes feasible or not. IS there any best approach.

0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 24865284
If you want the code handling the transaction to be specific to each project, then ditch the generichandler.vb idea and write the code within myhandler.ashx.vb.  Any other way creates unnecessary generalizaton, when in fact each handler is going to specialize for the particular set of operations necessary for the project.  This is the way I see it, based on what you've said so far.  
0
 
LVL 33

Accepted Solution

by:
raterus earned 500 total points
ID: 24869297
I still go with my first suggestion.  If you have a generic plan for how something should work, and each project needs to implement these set methods, then Inheritance/Interfaces are the way to go.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now