Link to home
Start Free TrialLog in
Avatar of ram27
ram27

asked on

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


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

Avatar of raterus
raterus
Flag of United States of America image

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.
Avatar of ram27
ram27

ASKER

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.

Avatar of Christopher Kile
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.  
ASKER CERTIFIED SOLUTION
Avatar of raterus
raterus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial