Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-07-15
4
Medium Priority
?
691 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

610 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