Jump to content


Photo
- - - - -

Linqpad Automation Interface - What Are Your Thoughts?


  • Please log in to reply
24 replies to this topic

#1 JoeAlbahari

JoeAlbahari

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 529 posts
  • Gender:Male
  • Location:Perth, Australia

Posted 20 March 2009 - 11:28 PM

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


#2 Terry Aney

Terry Aney

    Active Member

  • Members
  • PipPip
  • 19 posts

Posted 23 March 2009 - 06:46 AM

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

#3 JoeAlbahari

JoeAlbahari

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 529 posts
  • Gender:Male
  • Location:Perth, Australia

Posted 24 March 2009 - 04:36 AM

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


#4 frankkampas

frankkampas

    New Member

  • Members
  • Pip
  • 1 posts

Posted 26 March 2009 - 06:39 AM

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.

#5 shlomiw

shlomiw

    New Member

  • Members
  • Pip
  • 1 posts

Posted 04 May 2009 - 02:03 AM

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

#6 ifwdev

ifwdev

    New Member

  • Members
  • Pip
  • 4 posts

Posted 06 May 2009 - 12:33 PM

Please please please blink.gif

#7 JoeAlbahari

JoeAlbahari

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 529 posts
  • Gender:Male
  • Location:Perth, Australia

Posted 14 May 2009 - 01:34 AM

You can now vote on this feature on UserVoice

Joe

Edited by JoeAlbahari, 14 May 2009 - 01:35 AM.


#8 mschwab

mschwab

    New Member

  • Members
  • Pip
  • 2 posts

Posted 15 May 2009 - 09:04 AM

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!

#9 RossHale

RossHale

    New Member

  • Members
  • Pip
  • 1 posts

Posted 18 May 2009 - 12:09 PM

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

#10 mcintyre321

mcintyre321

    New Member

  • Members
  • Pip
  • 5 posts

Posted 26 May 2009 - 08:40 AM

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.

#11 mcintyre321

mcintyre321

    New Member

  • Members
  • Pip
  • 5 posts

Posted 10 July 2009 - 06:36 AM

Is there any news on this front?

#12 JoeAlbahari

JoeAlbahari

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 529 posts
  • Gender:Male
  • Location:Perth, Australia

Posted 15 July 2009 - 05:43 AM

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

#13 AnunayKumar

AnunayKumar

    New Member

  • Members
  • Pip
  • 2 posts

Posted 14 January 2010 - 07:05 PM

I would like to call Dump() extension method from within Visual Studio. Is this possible? The output HTML could be written to Console, Output window or to the disk. It would be great if instead of HTML, the output of dump could be plain formatted text which is printed to the console or output window.

#14 JoeAlbahari

JoeAlbahari

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 529 posts
  • Gender:Male
  • Location:Perth, Australia

Posted 16 January 2010 - 07:11 PM

You can use LINQPad's XHTML Dump engine from within Visual Studio by adding a reference to LINQPad.exe and then doing this:

var writer = LINQPad.Util.CreateXhtmlWriter();

To call Dump(), simply call Write or WriteLine on the writer object.

When you want to view the output. call ToString() on the writer - if you write the output to a file, you can then view it in a web browser.

Cheers
Joe



#15 AnunayKumar

AnunayKumar

    New Member

  • Members
  • Pip
  • 2 posts

Posted 21 January 2010 - 01:16 AM

Joe, thanks for adding this to the new Beta. I have written following extension method to simplify debugging in Visual Studio.
CODE
public static string Print<T>(this T o)
{
var writer = LINQPad.Util.CreateXhtmlWriter();
writer.Write(o);
return writer.ToString();
}
To view contents of any variable during debugging, I simply add myVariable.Print() to the watch window and use Visual Studio's built in HTML visualizer to see the formatted XHTML.

Thanks a ton
Anunay

Edited by AnunayKumar, 21 January 2010 - 01:17 AM.


#16 JoeAlbahari

JoeAlbahari

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 529 posts
  • Gender:Male
  • Location:Perth, Australia

Posted 24 January 2010 - 06:25 AM

Nice smile.gif

Joe

#17 War Wizard

War Wizard

    New Member

  • Members
  • Pip
  • 1 posts

Posted 12 February 2010 - 09:49 AM

Any more updates?

#18 JoeAlbahari

JoeAlbahari

    Super Veteran Member

  • Members
  • PipPipPipPipPipPipPipPipPipPipPip
  • 529 posts
  • Gender:Male
  • Location:Perth, Australia

Posted 13 February 2010 - 04:47 AM

regarding XHTML output or automation?

#19 mattipton

mattipton

    New Member

  • Members
  • Pip
  • 1 posts

Posted 07 March 2010 - 12:19 AM

My 2 cents worth- First, LinqPad is awesome. And yes, the automation would be absolutely without a doubt a killer feature. In my opinion, as far as the automation goes, I'm not sure that building into an exe is not a "must have"... but just having the ability to automate execution is the main thing... Like say having the ability to make a command line call to execute a given .linq script would be fine with me. You know, like say for me, I'm always wanting to batch stuff up but keep in separate .linq files for organization... so command line call would be perfect... anyway, there is my use case. Keep up the great work!

Edited by mattipton, 07 March 2010 - 12:26 AM.


#20 Naveen S

Naveen S

    New Member

  • Members
  • Pip
  • 2 posts

Posted 23 March 2010 - 09:44 AM

QUOTE (JoeAlbahari @ Feb 13 2010, 04:47 AM) <{POST_SNAPBACK}>
regarding XHTML output or automation?


On Automation?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users