C# 3.0 in a Nutshell
C# 3.0 in a Nutshell, Third Edition A Desktop Quick Reference By Joseph Albahari, Ben Albahari
September 2007
Pages: 858


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Linqpad Automation Interface - What Are Your Thoughts?
JoeAlbahari
post Mar 20 2009, 11:28 PM
Post #1


Advanced Member
******

Group: Members
Posts: 215
Joined: 15-February 08
From: Perth, Australia
Member No.: 90



I'm thinking of adding an automation interface for LINQPad. This would mean you could reference LINQPad.exe from an external program and then automate the execution of queries like this:

CODE
using LINQPad.Automation;

static void Main()
{
    var queryOutput = Query.Run ("myquery.linq");

    if (queryOutput.Successful)
        File.WriteAllText ("results.html", queryOutput.Results);
}


Here's what the complete automation interface might look like:

CODE
namespace Automation
{
    // All members threadsafe
    public class Query : IDisposable
    {
        // args would be for queries of type "C# Program"
        // or "VB Program" and would get passed to the Main method.

        public Query (string fileToOpen,
                       params object[] optionalArgs) { }

        public ResultsFormat ResultsFormat { get; set; }

        public void Start () { }
        public void Start (bool waitUntilComplete) { }

        public bool IsExecuting { get; }
        public void Cancel () { }
        public WaitHandle WaitHandle { get; }

        public QueryOutput Output { get; }

        public void Dispose () { }

        // Helper method
        public static QueryOutput Run (string filePath)
        {
            using (var query = new Query (filePath))
            {
                   query.Start (true);
                   return query.Output;
            }
        }
    }

    public enum ResultsFormat
    {
        // Default - identical to LINQPad's standard output
        Xhtml,

        // No fluff - ideal for regression testing
        Text,

        // This would be effective for queries that dumped
        // a single result set.
        CSV
    }

    public class QueryOutput
    {
        public readonly bool Successful;
        public readonly string Results;
        public readonly string SqlTranslation;
        public readonly string LambdaTranslation;
        public readonly string ILTranslation;
    }
}


Command-line support would build on this, although it would expose only a small subset of the features available via the automation interface.

It would also be possible to automate LINQPad from within LINQPad itself - so you could run several queries in one go.

What are people's thoughts?

Joe
Go to the top of the page
 
+Quote Post
Terry Aney
post Mar 23 2009, 06:46 AM
Post #2


Active Member
**

Group: Members
Posts: 16
Joined: 25-March 08
Member No.: 169



I think this sounds great. LINQPad has definately become my primary tool for doing almost anything. I almost feeling like I'm too addicted to it and becoming too much of a C# 'script junkie'...but I digress.

I also like the idea of LINQPad automating itself as well...it opens the possibilities of working on multiple databases from one 'master' script which I've needed a couple times.

My only suggestions are for the 'results' (and I'm not sure of the effort or feasiiblity)

1) I think there should be a pure Xml result.
2) Any chance of getting a IEnumerable<object> or similar passed back?

Both of these would be better suited if you needed to pass some information from script to script. Obviously with #2 we'd need to write an extension method or something, and speed wouldn't be great (thinking it'd need a bit of reflection), but that would be acceptable in the few situations where I'd like to pass info between scripts i.e. just getting some read only lists from one DB to another to compare and report on (if speed were issue, I'd just have to write a full blown c# app).

Finally, a bit off topic, but not sure if some of the re-work/effort you need for automation would be good time to think about it...it'd be nice in the output window of LINQPad if we could disable HTML encoding. There are a few times when I query stuff and want to make HTML links that are simply clickable from output window to open a new browser and navigate to my target. Would be great to get this too smile.gif

Looking forward to the automation with or without my result suggestions, I've a few good uses for just plain old single script automation 'right now' smile.gif
Go to the top of the page
 
+Quote Post
JoeAlbahari
post Mar 24 2009, 04:36 AM
Post #3


Advanced Member
******

Group: Members
Posts: 215
Joined: 15-February 08
From: Perth, Australia
Member No.: 90



These are good ideas. Piping results between queries as objects might be tricky, though - the data would have to be serializable for a start. I'll think on it more.

Thanks

Joe
Go to the top of the page
 
+Quote Post
frankkampas
post Mar 26 2009, 06:39 AM
Post #4


New Member
*

Group: Members
Posts: 1
Joined: 13-January 09
Member No.: 1,989



I think that automation would be very useful. I often call .NET code from other languages such as Mathematica. It would be a lot faster to set up C# code in LINQPad as opposed to Visual Studio.
Go to the top of the page
 
+Quote Post
shlomiw
post May 4 2009, 02:03 AM
Post #5


New Member
*

Group: Members
Posts: 1
Joined: 4-May 09
Member No.: 17,942



Hi Joe,
I was looking for a way to integrate LINQPad queries results as a quick reports generator, leveraging the html output, on my admin site.

This Linqpad Automation Interface can really suit these needs.

Hope it'll be released soon,
Thanks,
Shlomi
Go to the top of the page
 
+Quote Post
ifwdev
post May 6 2009, 12:33 PM
Post #6


New Member
*

Group: Members
Posts: 4
Joined: 13-January 09
Member No.: 1,988



Please please please blink.gif
Go to the top of the page
 
+Quote Post
JoeAlbahari
post May 14 2009, 01:34 AM
Post #7


Advanced Member
******

Group: Members
Posts: 215
Joined: 15-February 08
From: Perth, Australia
Member No.: 90



You can now vote on this feature on UserVoice

Joe

This post has been edited by JoeAlbahari: May 14 2009, 01:35 AM
Go to the top of the page
 
+Quote Post
mschwab
post May 15 2009, 09:04 AM
Post #8


New Member
*

Group: Members
Posts: 2
Joined: 15-May 09
Member No.: 18,143



Yes, please build the automation interface. Almost daily I think to myself "LinqPad really needs a Build button". It would be so nice to be able to hand an exe that does what my LinqPad script does over to less developer-minded people I work with. It seems with the automation interface that would be such a trivial task.

Thanks for the work you do on this!
Go to the top of the page
 
+Quote Post
RossHale
post May 18 2009, 12:09 PM
Post #9


New Member
*

Group: Members
Posts: 1
Joined: 18-May 09
Member No.: 18,188



Hi Joe,

Like frankkampas, I call .NET code and objects from other languages. In my case Dyalog APL.
While manipulating the EDM graph of .NET objects and building text snippets for EntitySQL methods works well, C# scripting for LINQ not so well.

Automation that allowed sending generated C# scripts for LINQ (or other snippets) to LINQPad
and return of results such as collections, possibly through html piping would be wonderful!

Ross
Go to the top of the page
 
+Quote Post
mcintyre321
post May 26 2009, 08:40 AM
Post #10


New Member
*

Group: Members
Posts: 3
Joined: 16-April 09
Member No.: 17,653



It would be really cool if .linq files were actually compiled exes which we could then call from the command line or reference in our .NET projects. The script content itself could be read from some metadata.
Go to the top of the page
 
+Quote Post
mcintyre321
post Jul 10 2009, 06:36 AM
Post #11


New Member
*

Group: Members
Posts: 3
Joined: 16-April 09
Member No.: 17,653



Is there any news on this front?
Go to the top of the page
 
+Quote Post
JoeAlbahari
post Jul 15 2009, 05:43 AM
Post #12


Advanced Member
******

Group: Members
Posts: 215
Joined: 15-February 08
From: Perth, Australia
Member No.: 90



Development on LINQPad has been quite slow lately - because I'm completing on C# 4.0 in a Nutshell. Most of the work on this will be finished soon - and they I'll start on the next LINQPad update. They'll almost certainly be something to support automation - whether it allows the compilation of standalone EXEs, I'm not sure though. I would have to see how easily I can remove the dependencies on LINQPad.

Cheers
Joe
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 22nd November 2009 - 04:51 PM