Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. You see where your innocent-seeming comments can lead...?

You see where your innocent-seeming comments can lead...?

Scheduled Pinned Locked Moved The Lounge
8 Posts 5 Posters 250 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PIEBALDconsult
    wrote last edited by PIEBALDconsult
    #1

    I mentioned something I had been thinking of doing and @Graeme_Grant replied that PowerShell can already do that.

    So I had no choice(!) but to go ahead and begin developing a framework which I could use to leverage PowerShell to run not-yet-compiled C# in an ad hoc manner via PowerShell. And it works!

    I had to whip up some basic frameworky stuff, like the command-line parser (mostly torn from a more robust one I have) and some basic ADO.net stuff.
    All of which gets munged together with a C-preprocessor to produce a .ps1 file which then gets passed to PowerShell (in a BAT file).
    I won't bore/dazzle you with the code (about 18K of it), but I can use it like this:

    Add-Type -ReferencedAssemblies System.Data , System.Xml -TypeDefinition @"
    
    # include <PSCS.h>
    # include <PSCS.ADO.net.cs>
    
    namespace PSCS
    {
      using PSCS.ADO ;
    
      using ParameterList=System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string,object>> ;
    
      public static partial class PSCS_Demo
      {
        public static int
        Main
        (
        )
        {
          int result = 0 ;
    
          PSCS.CommandLine args = PSCS.CommandLine.Split() ;
    
          try
          {
            System.Xml.XmlNode dbspec ;
    
            string cmd ;
    
            if ( args.TryGetDbSpec ( "%DbSpecConfig%" , out dbspec ) && args.TryGetSwitch ( "SqlQuery" , out cmd ) && ( cmd != null ) )
            {
              ParameterList parm = new ParameterList ( args.SwitchCount ) ;
    
              foreach ( System.Collections.Generic.KeyValuePair<string,string> kvp in args.Switches )
              {
                parm.Add ( new System.Collections.Generic.KeyValuePair<string,object> ( kvp.Key , kvp.Value ) ) ;
              }
    
              result += dbspec.Connect().DumpReader ( cmd , 30 , parm ) ;
            }
          }
          catch ( System.Exception exc )
          {
            result = args.Dump() ;
    
            System.Console.Write ( "\r\n{0}" , exc ) ;
          }
    
          return ( result ) ;
        }
      }
    }
    "@
    
    [Environment]::Exit( [PSCS.PSCS_Demo]::Main() )
    

    And here is an example of a run of that. This is, of course, intended only as a test and demonstration of this.

    D:\>D:\project\pscs\PSCS_Demo /db=WordList /SqlQuery="SELECT 42 [Answer] , 3.14 [PI];SELECT * FROM [WordList] WHERE [SortedLetters] LIKE @pattern ORDER BY [Word];UPDATE [WordList] SET [Word] = UPPER([Word]) WHERE [SortedLetters] LIKE @pattern" /Pattern=OPST
    PSCS_Demo.pscs
    
    Answer,PI
    42,3.14
    Word,Howmany,Which,IsAlphabetic,Confidence,LetterPrint,UniqueLetters,SortedLetters,Numerology
    OPTS,9,3983,True,77.27273,835584,OPST,OPST,70
    OSTP,1,8,True,9.090909,835584,OPST,OPST,70
    POST,12,4095,True,86.36364,835584,OPST,OPST,70
    POTS,11,4031,True,81.81818,835584,OPST,OPST,70
    SPOT,12,4095,True,86.36364,835584,OPST,OPST,70
    STOP,12,4095,True,86.36364,835584,OPST,OPST,70
    TOPS,11,4031,True,81.81818,835584,OPST,OPST,70
    RecordsAffected = 7
    15
    

    So, the framework can be deployed to a server or other remote system as raw C# source files, then an application can be developed and deployed in a similar manner.
    As long as there is a C-preprocessor available, it should just work. Just like Python :D .

    (Yes, DOTNET RUN was also mentioned, but I haven't looked at that yet.)

    J 1 Reply Last reply
    1
    • Graeme_GrantG Offline
      Graeme_GrantG Offline
      Graeme_Grant
      wrote last edited by
      #2

      Nice work!

      “I fear not the man who has practised 10,000 kicks once, but I fear the man who has practised one kick 10,000 times.” - Bruce Lee.

      1 Reply Last reply
      1
      • Mircea NeacsuM Offline
        Mircea NeacsuM Offline
        Mircea Neacsu
        wrote last edited by Mircea Neacsu
        #3

        @PIEBALDconsult as you seem to be a lot into PowerShell (bleh, can't stand the thing!), this one just appeared in my GitHub feed: https://github.com/PowerShell/PowerShell. Thought you might enjoy it.

        P 1 Reply Last reply
        0
        • Mircea NeacsuM Mircea Neacsu

          @PIEBALDconsult as you seem to be a lot into PowerShell (bleh, can't stand the thing!), this one just appeared in my GitHub feed: https://github.com/PowerShell/PowerShell. Thought you might enjoy it.

          P Offline
          P Offline
          PIEBALDconsult
          wrote last edited by
          #4

          I am not a fan of PowerShell (PTUI), I try to avoid it, but it provides a way to proof-of-concept this.
          I would not use PowerShell for anything serious.

          1 Reply Last reply
          1
          • T Offline
            T Offline
            theoldfool
            wrote last edited by
            #5

            Powershell available for Linux now. Life is good! :)

            P 1 Reply Last reply
            -1
            • P PIEBALDconsult

              I mentioned something I had been thinking of doing and @Graeme_Grant replied that PowerShell can already do that.

              So I had no choice(!) but to go ahead and begin developing a framework which I could use to leverage PowerShell to run not-yet-compiled C# in an ad hoc manner via PowerShell. And it works!

              I had to whip up some basic frameworky stuff, like the command-line parser (mostly torn from a more robust one I have) and some basic ADO.net stuff.
              All of which gets munged together with a C-preprocessor to produce a .ps1 file which then gets passed to PowerShell (in a BAT file).
              I won't bore/dazzle you with the code (about 18K of it), but I can use it like this:

              Add-Type -ReferencedAssemblies System.Data , System.Xml -TypeDefinition @"
              
              # include <PSCS.h>
              # include <PSCS.ADO.net.cs>
              
              namespace PSCS
              {
                using PSCS.ADO ;
              
                using ParameterList=System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string,object>> ;
              
                public static partial class PSCS_Demo
                {
                  public static int
                  Main
                  (
                  )
                  {
                    int result = 0 ;
              
                    PSCS.CommandLine args = PSCS.CommandLine.Split() ;
              
                    try
                    {
                      System.Xml.XmlNode dbspec ;
              
                      string cmd ;
              
                      if ( args.TryGetDbSpec ( "%DbSpecConfig%" , out dbspec ) && args.TryGetSwitch ( "SqlQuery" , out cmd ) && ( cmd != null ) )
                      {
                        ParameterList parm = new ParameterList ( args.SwitchCount ) ;
              
                        foreach ( System.Collections.Generic.KeyValuePair<string,string> kvp in args.Switches )
                        {
                          parm.Add ( new System.Collections.Generic.KeyValuePair<string,object> ( kvp.Key , kvp.Value ) ) ;
                        }
              
                        result += dbspec.Connect().DumpReader ( cmd , 30 , parm ) ;
                      }
                    }
                    catch ( System.Exception exc )
                    {
                      result = args.Dump() ;
              
                      System.Console.Write ( "\r\n{0}" , exc ) ;
                    }
              
                    return ( result ) ;
                  }
                }
              }
              "@
              
              [Environment]::Exit( [PSCS.PSCS_Demo]::Main() )
              

              And here is an example of a run of that. This is, of course, intended only as a test and demonstration of this.

              D:\>D:\project\pscs\PSCS_Demo /db=WordList /SqlQuery="SELECT 42 [Answer] , 3.14 [PI];SELECT * FROM [WordList] WHERE [SortedLetters] LIKE @pattern ORDER BY [Word];UPDATE [WordList] SET [Word] = UPPER([Word]) WHERE [SortedLetters] LIKE @pattern" /Pattern=OPST
              PSCS_Demo.pscs
              
              Answer,PI
              42,3.14
              Word,Howmany,Which,IsAlphabetic,Confidence,LetterPrint,UniqueLetters,SortedLetters,Numerology
              OPTS,9,3983,True,77.27273,835584,OPST,OPST,70
              OSTP,1,8,True,9.090909,835584,OPST,OPST,70
              POST,12,4095,True,86.36364,835584,OPST,OPST,70
              POTS,11,4031,True,81.81818,835584,OPST,OPST,70
              SPOT,12,4095,True,86.36364,835584,OPST,OPST,70
              STOP,12,4095,True,86.36364,835584,OPST,OPST,70
              TOPS,11,4031,True,81.81818,835584,OPST,OPST,70
              RecordsAffected = 7
              15
              

              So, the framework can be deployed to a server or other remote system as raw C# source files, then an application can be developed and deployed in a similar manner.
              As long as there is a C-preprocessor available, it should just work. Just like Python :D .

              (Yes, DOTNET RUN was also mentioned, but I haven't looked at that yet.)

              J Offline
              J Offline
              jeron1
              wrote last edited by
              #6

              @PIEBALDconsult Perhaps, tip/trick type stuff?

              1 Reply Last reply
              1
              • T theoldfool

                Powershell available for Linux now. Life is good! :)

                P Offline
                P Offline
                PIEBALDconsult
                wrote last edited by PIEBALDconsult
                #7

                If it can run C# code like this on Linux, then maybe I have an argument against Python. :)
                I don't have access to a Linux box. I've never used Linux. I have no interest in ever using Linux

                1 Reply Last reply
                1
                • Mircea NeacsuM Offline
                  Mircea NeacsuM Offline
                  Mircea Neacsu
                  wrote last edited by
                  #8

                  Use WSL. Download Ubuntu from Microsoft store and you have a pretty decent Linux box. That’s what I do to save me the trouble of having a separate Linux box.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups