Solved

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

Posted on 2009-07-15
4
673 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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