beyond dynamic code execution

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Meng

    #1

    beyond dynamic code execution

    I got a tough question:

    The backgroud for this question is:
    I want to design an application works like a engine.
    After release, we can still customize a form by adding a button, and source
    code for the button. (This is done by the form itself, not by using VS.Net)
    (button and source code should be a record in database, these information
    should be retrieve from database when the form shows up)

    What I want is:
    I want the source code (comes from database) to access other controls which
    has already been in the form. For example:
    I want to read a item from a listbox (let's assume there is a listbox in
    the form)
    I want to add a item to a listbox
    I want to change the property of a datagrid
    .......

    What I can to do:
    1) add a button on the fly
    2) load source code from database for this button's click event
    3) complie code on the fly.

    What I don't know:
    I don't knwo how to reference the form in the new code.
    I don't know how to reference the controls in the form.

    Thanks for any suggestions.

    George Meng


  • Cor Ligthert [MVP]

    #2
    Re: beyond dynamic code execution

    George,

    You are not the first one who asks questions related to your approach in
    this newsgroup.

    Microsoft did it already and after long time of continuous improvement they
    have now the current version of Office MS Access. It did cost Microsoft a
    lot of money to come where they are now.

    You will have to go that way as well. In my opinion is it asking to much
    from a newsgroup to give the solution for that.

    Keep in mind that your customers normaly will accept nothing less than a
    solution as MS Access.

    Just meant as warning to think about before you start.

    Cor


    Comment

    • George Meng

      #3
      Re: beyond dynamic code execution

      Not sure what you are talking about.
      I am using .Net, have nothing to do with Access.
      I a short, my question is: how to reference other objects in a new dynamic
      execution code.

      George

      "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> дÈëÏûÏ¢ÐÂÎÅ
      :eViL9dd0FHA.31 88@TK2MSFTNGP14 .phx.gbl...[color=blue]
      > George,
      >
      > You are not the first one who asks questions related to your approach in
      > this newsgroup.
      >
      > Microsoft did it already and after long time of continuous improvement[/color]
      they[color=blue]
      > have now the current version of Office MS Access. It did cost Microsoft a
      > lot of money to come where they are now.
      >
      > You will have to go that way as well. In my opinion is it asking to much
      > from a newsgroup to give the solution for that.
      >
      > Keep in mind that your customers normaly will accept nothing less than a
      > solution as MS Access.
      >
      > Just meant as warning to think about before you start.
      >
      > Cor
      >
      >[/color]


      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: beyond dynamic code execution

        George,
        | What I don't know:
        | I don't knwo how to reference the form in the new code.
        | I don't know how to reference the controls in the form.
        The "easiest" way may be to define the dynamic code as inheriting from your
        form. Alternatively you could define your dynamic code as accepting a
        parameter of your form.

        Thinking about it: the Separated Interface Pattern might be useful here.

        Defines an interface in a separate package from its implementation.



        I would put the form or separated interface in its own class library, then
        when I compile the dynamic code I would add a reference to the class
        library.

        I will see if I can come up with an example tomorrow.

        Some questions:
        - Is the definition of the form static? (other then the button you are
        adding?)
        - How is the dynamic code defined? (Is it a sub, function, class, something
        else?)
        - Is Code Access Security involved?
        - How many buttons w/code can be added to a form? (

        I believe Cor was referring to "full integration" where the users of your
        app have complete control to customize the UI as Access does. You may want
        to consider a product such as Microsoft Visual Studio 2005 Tools for
        Applications if you are looking for significant user customization of your
        UI.

        http://msdn.microsoft.com/vstudio/ex...a/default.aspx


        --
        Hope this helps
        Jay [MVP - Outlook]
        T.S. Bradley - http://www.tsbradley.net


        "George Meng" <georgemeng2000 @sohu.com> wrote in message
        news:ejRtxOa0FH A.464@TK2MSFTNG P15.phx.gbl...
        |I got a tough question:
        |
        | The backgroud for this question is:
        | I want to design an application works like a engine.
        | After release, we can still customize a form by adding a button, and
        source
        | code for the button. (This is done by the form itself, not by using
        VS.Net)
        | (button and source code should be a record in database, these information
        | should be retrieve from database when the form shows up)
        |
        | What I want is:
        | I want the source code (comes from database) to access other controls
        which
        | has already been in the form. For example:
        | I want to read a item from a listbox (let's assume there is a listbox in
        | the form)
        | I want to add a item to a listbox
        | I want to change the property of a datagrid
        | ......
        |
        | What I can to do:
        | 1) add a button on the fly
        | 2) load source code from database for this button's click event
        | 3) complie code on the fly.
        |
        | What I don't know:
        | I don't knwo how to reference the form in the new code.
        | I don't know how to reference the controls in the form.
        |
        | Thanks for any suggestions.
        |
        | George Meng
        |
        |


        Comment

        • Jay B. Harlow [MVP - Outlook]

          #5
          Re: beyond dynamic code execution

          George,
          Another question.

          Is there only one form that you can add dynamic code to or are there
          multiple forms that you add dynamic code to?

          --
          Hope this helps
          Jay [MVP - Outlook]
          T.S. Bradley - http://www.tsbradley.net


          "George Meng" <georgemeng2000 @sohu.com> wrote in message
          news:ejRtxOa0FH A.464@TK2MSFTNG P15.phx.gbl...
          |I got a tough question:
          |
          | The backgroud for this question is:
          | I want to design an application works like a engine.
          | After release, we can still customize a form by adding a button, and
          source
          | code for the button. (This is done by the form itself, not by using
          VS.Net)
          | (button and source code should be a record in database, these information
          | should be retrieve from database when the form shows up)
          |
          | What I want is:
          | I want the source code (comes from database) to access other controls
          which
          | has already been in the form. For example:
          | I want to read a item from a listbox (let's assume there is a listbox in
          | the form)
          | I want to add a item to a listbox
          | I want to change the property of a datagrid
          | ......
          |
          | What I can to do:
          | 1) add a button on the fly
          | 2) load source code from database for this button's click event
          | 3) complie code on the fly.
          |
          | What I don't know:
          | I don't knwo how to reference the form in the new code.
          | I don't know how to reference the controls in the form.
          |
          | Thanks for any suggestions.
          |
          | George Meng
          |
          |


          Comment

          • George Meng

            #6
            Re: beyond dynamic code execution

            Thanks very much Jay, actually, I want to put this feature into multiple
            forms.


            "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @tsbradley.net> дÈëÏûÏ¢ÐÂÎÅ
            :euuIMXg0FHA.35 68@TK2MSFTNGP15 .phx.gbl...[color=blue]
            > George,
            > Another question.
            >
            > Is there only one form that you can add dynamic code to or are there
            > multiple forms that you add dynamic code to?
            >
            > --
            > Hope this helps
            > Jay [MVP - Outlook]
            > T.S. Bradley - http://www.tsbradley.net
            >
            >
            > "George Meng" <georgemeng2000 @sohu.com> wrote in message
            > news:ejRtxOa0FH A.464@TK2MSFTNG P15.phx.gbl...
            > |I got a tough question:
            > |
            > | The backgroud for this question is:
            > | I want to design an application works like a engine.
            > | After release, we can still customize a form by adding a button, and
            > source
            > | code for the button. (This is done by the form itself, not by using
            > VS.Net)
            > | (button and source code should be a record in database, these[/color]
            information[color=blue]
            > | should be retrieve from database when the form shows up)
            > |
            > | What I want is:
            > | I want the source code (comes from database) to access other controls
            > which
            > | has already been in the form. For example:
            > | I want to read a item from a listbox (let's assume there is a listbox[/color]
            in[color=blue]
            > | the form)
            > | I want to add a item to a listbox
            > | I want to change the property of a datagrid
            > | ......
            > |
            > | What I can to do:
            > | 1) add a button on the fly
            > | 2) load source code from database for this button's click event
            > | 3) complie code on the fly.
            > |
            > | What I don't know:
            > | I don't knwo how to reference the form in the new code.
            > | I don't know how to reference the controls in the form.
            > |
            > | Thanks for any suggestions.
            > |
            > | George Meng
            > |
            > |
            >
            >[/color]


            Comment

            • Cor Ligthert [MVP]

              #7
              Re: beyond dynamic code execution

              Jay,
              [color=blue]
              >
              > I believe Cor was referring to "full integration" where the users of your
              > app have complete control to customize the UI as Access does. You may want
              > to consider a product such as Microsoft Visual Studio 2005 Tools for
              > Applications if you are looking for significant user customization of your
              > UI.[/color]

              Exactly

              :-)
              [color=blue]
              >
              > http://msdn.microsoft.com/vstudio/ex...a/default.aspx
              >[/color]
              Exactly

              :-)

              Cor


              Comment

              • Jay B. Harlow [MVP - Outlook]

                #8
                Re: beyond dynamic code execution

                George,
                I sounds like you want an Add-in/Plug-in ability where the code is
                dynamically compiled, rather then loaded from a pre-compiled assembly.

                The following articles discusses loading plug-ins into AppDomains
                http://msdn.microsoft.com/msdnmag/is...s/default.aspx

                The following article discusses some security to using AddDomains:
                http://msdn.microsoft.com/msdnmag/is...s/default.aspx


                The following discusses what's new in CAS in .NET 2.0
                http://msdn.microsoft.com/msdnmag/is...y/default.aspx

                The following discuss what's new in .NET 2.0 for loading plug-ins into
                AppDomains
                http://msdn.microsoft.com/msdnmag/is...s/default.aspx


                When you compile your dynamic code you can use
                CompilerParamet ers.ReferencedA ssemblies to reference the assembly with your
                application's "object model" in it. I would make this "object model"
                "hardened" as the above article articles suggest. Although using AppDomains
                & an "hardened object model" is more work, it helps your app be more
                resilient to problems in the dynamic code.

                NOTE: You will need to compile the dynamic code in the sand boxed AppDomain
                to ensure its isolated...

                --
                Hope this helps
                Jay [MVP - Outlook]
                T.S. Bradley - http://www.tsbradley.net


                "George Meng" <georgemeng2000 @sohu.com> wrote in message
                news:OgJ8hTh0FH A.2132@TK2MSFTN GP15.phx.gbl...
                | Thanks very much Jay, actually, I want to put this feature into multiple
                | forms.
                |
                |
                | "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @tsbradley.net>
                дÈëÏûÏ¢ÐÂÎÅ
                | :euuIMXg0FHA.35 68@TK2MSFTNGP15 .phx.gbl...
                | > George,
                | > Another question.
                | >
                | > Is there only one form that you can add dynamic code to or are there
                | > multiple forms that you add dynamic code to?
                | >
                | > --
                | > Hope this helps
                | > Jay [MVP - Outlook]
                | > T.S. Bradley - http://www.tsbradley.net
                | >
                | >
                | > "George Meng" <georgemeng2000 @sohu.com> wrote in message
                | > news:ejRtxOa0FH A.464@TK2MSFTNG P15.phx.gbl...
                | > |I got a tough question:
                | > |
                | > | The backgroud for this question is:
                | > | I want to design an application works like a engine.
                | > | After release, we can still customize a form by adding a button, and
                | > source
                | > | code for the button. (This is done by the form itself, not by using
                | > VS.Net)
                | > | (button and source code should be a record in database, these
                | information
                | > | should be retrieve from database when the form shows up)
                | > |
                | > | What I want is:
                | > | I want the source code (comes from database) to access other controls
                | > which
                | > | has already been in the form. For example:
                | > | I want to read a item from a listbox (let's assume there is a listbox
                | in
                | > | the form)
                | > | I want to add a item to a listbox
                | > | I want to change the property of a datagrid
                | > | ......
                | > |
                | > | What I can to do:
                | > | 1) add a button on the fly
                | > | 2) load source code from database for this button's click event
                | > | 3) complie code on the fly.
                | > |
                | > | What I don't know:
                | > | I don't knwo how to reference the form in the new code.
                | > | I don't know how to reference the controls in the form.
                | > |
                | > | Thanks for any suggestions.
                | > |
                | > | George Meng
                | > |
                | > |
                | >
                | >
                |
                |


                Comment

                • George Meng

                  #9
                  Re: beyond dynamic code execution

                  Thanks so much Jay, I got the direction. I will try it.

                  "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @tsbradley.net> дÈëÏûÏ¢ÐÂÎÅ
                  :eodGnRm0FHA.23 48@TK2MSFTNGP15 .phx.gbl...[color=blue]
                  > George,
                  > I sounds like you want an Add-in/Plug-in ability where the code is
                  > dynamically compiled, rather then loaded from a pre-compiled assembly.
                  >
                  > The following articles discusses loading plug-ins into AppDomains
                  > http://msdn.microsoft.com/msdnmag/is...s/default.aspx
                  >
                  > The following article discusses some security to using AddDomains:
                  > http://msdn.microsoft.com/msdnmag/is...s/default.aspx
                  >
                  >
                  > The following discusses what's new in CAS in .NET 2.0
                  >[/color]
                  http://msdn.microsoft.com/msdnmag/is...ity/default.as
                  px[color=blue]
                  >
                  > The following discuss what's new in .NET 2.0 for loading plug-ins into
                  > AppDomains
                  > http://msdn.microsoft.com/msdnmag/is...s/default.aspx
                  >
                  >
                  > When you compile your dynamic code you can use
                  > CompilerParamet ers.ReferencedA ssemblies to reference the assembly with[/color]
                  your[color=blue]
                  > application's "object model" in it. I would make this "object model"
                  > "hardened" as the above article articles suggest. Although using[/color]
                  AppDomains[color=blue]
                  > & an "hardened object model" is more work, it helps your app be more
                  > resilient to problems in the dynamic code.
                  >
                  > NOTE: You will need to compile the dynamic code in the sand boxed[/color]
                  AppDomain[color=blue]
                  > to ensure its isolated...
                  >
                  > --
                  > Hope this helps
                  > Jay [MVP - Outlook]
                  > T.S. Bradley - http://www.tsbradley.net
                  >
                  >
                  > "George Meng" <georgemeng2000 @sohu.com> wrote in message
                  > news:OgJ8hTh0FH A.2132@TK2MSFTN GP15.phx.gbl...
                  > | Thanks very much Jay, actually, I want to put this feature into multiple
                  > | forms.
                  > |
                  > |
                  > | "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @tsbradley.net>
                  > дÈëÏûÏ¢ÐÂÎÅ
                  > | :euuIMXg0FHA.35 68@TK2MSFTNGP15 .phx.gbl...
                  > | > George,
                  > | > Another question.
                  > | >
                  > | > Is there only one form that you can add dynamic code to or are there
                  > | > multiple forms that you add dynamic code to?
                  > | >
                  > | > --
                  > | > Hope this helps
                  > | > Jay [MVP - Outlook]
                  > | > T.S. Bradley - http://www.tsbradley.net
                  > | >
                  > | >
                  > | > "George Meng" <georgemeng2000 @sohu.com> wrote in message
                  > | > news:ejRtxOa0FH A.464@TK2MSFTNG P15.phx.gbl...
                  > | > |I got a tough question:
                  > | > |
                  > | > | The backgroud for this question is:
                  > | > | I want to design an application works like a engine.
                  > | > | After release, we can still customize a form by adding a button, and
                  > | > source
                  > | > | code for the button. (This is done by the form itself, not by using
                  > | > VS.Net)
                  > | > | (button and source code should be a record in database, these
                  > | information
                  > | > | should be retrieve from database when the form shows up)
                  > | > |
                  > | > | What I want is:
                  > | > | I want the source code (comes from database) to access other[/color]
                  controls[color=blue]
                  > | > which
                  > | > | has already been in the form. For example:
                  > | > | I want to read a item from a listbox (let's assume there is a[/color]
                  listbox[color=blue]
                  > | in
                  > | > | the form)
                  > | > | I want to add a item to a listbox
                  > | > | I want to change the property of a datagrid
                  > | > | ......
                  > | > |
                  > | > | What I can to do:
                  > | > | 1) add a button on the fly
                  > | > | 2) load source code from database for this button's click event
                  > | > | 3) complie code on the fly.
                  > | > |
                  > | > | What I don't know:
                  > | > | I don't knwo how to reference the form in the new code.
                  > | > | I don't know how to reference the controls in the form.
                  > | > |
                  > | > | Thanks for any suggestions.
                  > | > |
                  > | > | George Meng
                  > | > |
                  > | > |
                  > | >
                  > | >
                  > |
                  > |
                  >
                  >[/color]


                  Comment

                  Working...