You see where your innocent-seeming comments can lead...?
-
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.)
-
Nice work!
-
@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.
-
@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.
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. -
Powershell available for Linux now. Life is good! :)
-
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.)
@PIEBALDconsult Perhaps, tip/trick type stuff?
-
Powershell available for Linux now. Life is good! :)
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 -
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.