public override bool Compile(string queryText, QueryCore query, TempFileRef dataContextAssembly)
 {
     bool flag;
     StringBuilder builder = new StringBuilder(this.GetHeader(query));
     base.LineOffset = builder.ToString().Count<char>(c => c == '\n');
     builder.AppendLine(Regex.Replace(queryText.Trim(), "(?<!\r)\n", "\r\n"));
     builder.Append(this.GetFooter(query));
     string str = "v4.0";
     Dictionary<string, string> providerOptions = new Dictionary<string, string>();
     providerOptions.Add("CompilerVersion", str);
     VBCodeProvider codeProvider = new VBCodeProvider(providerOptions);
     if ((!(flag = base.Compile(codeProvider, builder.ToString(), dataContextAssembly, query.QueryKind, this.GetCompilerOptions(query))) && (query.QueryKind == QueryLanguage.VBExpression)) && (base.ErrorMessage == ") expected"))
     {
         base.ErrorMessage = ") or end of expression expected";
         return flag;
     }
     if (!(flag || !base.ErrorMessage.ToLowerInvariant().Contains("predicatebuilder")))
     {
         base.ErrorMessage = base.ErrorMessage + QueryCompiler.PredicateBuilderMessage;
         return flag;
     }
     if (!(((flag || (query.QueryKind != QueryLanguage.VBStatements)) || !(base.ErrorMessage == "Expression is not a method.")) || query.Source.TrimStart(new char[0]).StartsWith("dim", StringComparison.OrdinalIgnoreCase)))
     {
         base.ErrorMessage = base.ErrorMessage + "\r\n(Try setting the query language to 'VB Expression' rather than 'VB Statements')";
         return flag;
     }
     if ((!flag && (query.QueryKind == QueryLanguage.VBExpression)) && (base.ErrorMessage == "Expression expected."))
     {
         base.ErrorMessage = base.ErrorMessage + "\r\n(Set the query language to 'VB Statement(s)' for a statement-based code)";
     }
     return flag;
 }
Example #2
0
 public Client(QueryCore query, string querySelection, bool compileOnly, QueryCompilationEventArgs lastCompilation, Func<Client, Server> serverGenerator, PluginWindowManager pluginWinManager)
 {
     this._query = query;
     this._partialSource = !string.IsNullOrEmpty(querySelection);
     this._source = this._partialSource ? querySelection : this._query.Source;
     this._compileOnly = compileOnly;
     this._lastCompilation = lastCompilation;
     this._serverGenerator = serverGenerator;
     this._pluginWinManager = pluginWinManager;
 }
 public override string GetFooter(QueryCore query)
 {
     StringBuilder builder = new StringBuilder();
     if (query.QueryKind == QueryLanguage.VBExpression)
     {
         builder.AppendLine("LINQPad.Extensions.Dump(linqPadQuery)");
     }
     if (query.QueryKind != QueryLanguage.VBProgram)
     {
         builder.AppendLine("End Sub");
     }
     builder.AppendLine("End Class");
     return builder.ToString();
 }
Example #4
0
 public AutoSaveToken(QueryCore q)
 {
     if (AutoSaver._enabled)
     {
         this._query = q;
         try
         {
             this._fileStream = File.Create(this.FilePath);
         }
         catch
         {
         }
     }
 }
Example #5
0
 public static void UpdateAdditionalRefs(QueryCore q)
 {
     try
     {
         _query = q;
         _additionalRefs = q.AllFileReferences.Union<string>((from r in q.AdditionalGACReferences
             select GacResolver.FindPath(r) into r
             where r != null
             select r)).ToArray<string>();
     }
     catch
     {
         _additionalRefs = "".Split(new char[0]);
     }
 }
Example #6
0
 public static void UpdateAdditionalRefs(QueryCore q)
 {
     try
     {
         _query          = q;
         _additionalRefs = q.AllFileReferences.Union <string>((from r in q.AdditionalGACReferences
                                                               select GacResolver.FindPath(r) into r
                                                               where r != null
                                                               select r)).ToArray <string>();
     }
     catch
     {
         _additionalRefs = "".Split(new char[0]);
     }
 }
Example #7
0
 public QueryProps(QueryCore q)
 {
     this._query = q;
     this.InitializeComponent();
     foreach (string str in q.AdditionalReferences)
     {
         this.AddListViewAssembly(str);
     }
     foreach (string str in q.AdditionalGACReferences)
     {
         this.AddListViewAssembly(new AssemblyName(str));
     }
     if (q.IsMyExtensions)
     {
         Label label = new Label {
             Dock = DockStyle.Top,
             AutoSize = true,
             Text = "My Extensions: References that you add here will apply to all queries",
             Padding = new Padding(0, 0, 0, 3),
             Font = new Font(FontManager.GetDefaultFont(), FontStyle.Bold)
         };
         this.tabPage1.Controls.Add(label);
         this.btnSetAsDefault.Enabled = false;
     }
     else
     {
         QueryCore query = MyExtensions.Query;
         if (query != null)
         {
             foreach (string str in query.AdditionalReferences)
             {
                 this.FlagAsInherited(this.AddListViewAssembly(str));
             }
             foreach (string str in query.AdditionalGACReferences)
             {
                 this.FlagAsInherited(this.AddListViewAssembly(new AssemblyName(str)));
             }
         }
     }
     this.txtNS.Lines = q.AdditionalNamespaces.ToArray<string>();
     this.chkIncludePredicateBuilder.Checked = q.IncludePredicateBuilder;
     this._origNS = this.txtNS.Text.Trim();
     this.EnableControls();
     this.lvRefs.Sorting = SortOrder.Ascending;
     this.lvRefs.MouseMove += new MouseEventHandler(this.lvRefs_MouseMove);
     this.lvRefs.MouseDown += new MouseEventHandler(this.lvRefs_MouseDown);
     this.tc.TabPages[2].Dispose();
 }
 protected QueryCompiler(QueryCore query, bool addReferences)
 {
     this.IsMyExtensions = query.IsMyExtensions;
     if (this.IsMyExtensions)
     {
         MyExtensions.UpdateAdditionalRefs(query);
     }
     if (GacResolver.IsEntityFrameworkAvailable)
     {
         this.References.Add("System.Data.Entity.dll");
     }
     DataContextDriver driver = query.GetDriver(true);
     if ((query.Repository != null) && (driver != null))
     {
         this.ImportedNamespaces.RemoveRange(driver.GetNamespacesToRemoveInternal(query.Repository));
         this.ImportedNamespaces.AddRange(driver.GetNamespacesToAddInternal(query.Repository));
         if (addReferences)
         {
             this.References.AddRange(query.Repository.GetDriverAssemblies());
         }
     }
     if (addReferences)
     {
         this.References.AddRange(PluginAssembly.GetCompatibleAssemblies(query.IsMyExtensions));
     }
     this.ImportedNamespaces.AddRange(query.AdditionalNamespaces);
     if (!string.IsNullOrEmpty(query.QueryBaseClassNamespace))
     {
         this.ImportedNamespaces.Add(query.QueryBaseClassNamespace);
     }
     if (addReferences)
     {
         this.References.AddRange(query.AllFileReferences);
         foreach (string str in query.AdditionalGACReferences)
         {
             string item = GacResolver.FindPath(str);
             if (item != null)
             {
                 this.References.Add(item);
             }
         }
         this.References.AddRange(query.GetStaticSchemaSameFolderReferences());
         if (!this.IsMyExtensions)
         {
             this.References.AddRange(MyExtensions.AdditionalRefs);
         }
     }
 }
Example #9
0
 public static void UpdateAdditionalRefs()
 {
     if (File.Exists(QueryFilePath))
     {
         try
         {
             QueryCore q = new QueryCore();
             q.Open(QueryFilePath);
             UpdateAdditionalRefs(q);
             return;
         }
         catch
         {
         }
     }
     _additionalRefs = new string[0];
 }
Example #10
0
 public static void UpdateAdditionalRefs()
 {
     if (File.Exists(QueryFilePath))
     {
         try
         {
             QueryCore q = new QueryCore();
             q.Open(QueryFilePath);
             UpdateAdditionalRefs(q);
             return;
         }
         catch
         {
         }
     }
     _additionalRefs = new string[0];
 }
Example #11
0
        private QueryCore GetSnapshotForExecution()
        {
            QueryCore core = new QueryCore();

            using (core.TransactChanges())
            {
                core.AdditionalGACReferences = base.AdditionalGACReferences;
                core.AdditionalNamespaces    = base.AdditionalNamespaces;
                core.AdditionalReferences    = base.AdditionalReferences;
                core.IncludePredicateBuilder = base.IncludePredicateBuilder;
                core.ToDataGrids             = base.ToDataGrids;
                core.FilePath       = base.FilePath;
                core.Name           = base.Name;
                core.QueryKind      = base.QueryKind;
                core.Repository     = base.Repository;
                core.Source         = base.Source;
                core.IsMyExtensions = base.IsMyExtensions;
            }
            return(core);
        }
 public override string GetHeader(QueryCore query)
 {
     StringBuilder builder = new StringBuilder("#Const LINQPAD = True\r\n");
     builder.AppendLine(string.Join("\r\n", (from n in base.ImportedNamespaces select "Imports " + n).ToArray<string>()));
     builder.AppendLine();
     if (query.IncludePredicateBuilder)
     {
         builder.AppendLine("Public Module PredicateBuilder\r\n    <System.Runtime.CompilerServices.Extension> _\r\n    Public Function [And](Of T)(ByVal expr1 As Expression(Of Func(Of T, Boolean)), ByVal expr2 As Expression(Of Func(Of T, Boolean))) As Expression(Of Func(Of T, Boolean))\r\n        Dim invokedExpr As Expression = Expression.Invoke(expr2, expr1.Parameters.Cast(Of Expression)())\r\n        Return Expression.Lambda(Of Func(Of T, Boolean))(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters)\r\n    End Function\r\n\r\n    Public Function [False](Of T)() As Expression(Of Func(Of T, Boolean))\r\n      Return Function(f) False\r\n    End Function\r\n\r\n    <System.Runtime.CompilerServices.Extension> _\r\n    Public Function [Or](Of T)(ByVal expr1 As Expression(Of Func(Of T, Boolean)), ByVal expr2 As Expression(Of Func(Of T, Boolean))) As Expression(Of Func(Of T, Boolean))\r\n        Dim invokedExpr As Expression = Expression.Invoke(expr2, expr1.Parameters.Cast(Of Expression)())\r\n        Return Expression.Lambda(Of Func(Of T, Boolean))(Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters)\r\n    End Function\r\n\r\n    Public Function [True](Of T)() As Expression(Of Func(Of T, Boolean))\r\n      Return Function(f) True\r\n    End Function\r\n\r\nEnd Module\r\n");
     }
     builder.AppendLine("Public Class UserQuery");
     if (query.QueryBaseClassName != null)
     {
         builder.AppendLine("  Inherits " + query.QueryBaseClassName);
     }
     builder.AppendLine();
     builder.AppendLine();
     DataContextDriver driver = query.GetDriver(true);
     if (driver != null)
     {
         ParameterDescriptor[] contextConstructorParams = base.GetContextConstructorParams(driver, query.Repository);
         builder.Append("  Public Sub New (");
         builder.Append(string.Join(", ", (from p in contextConstructorParams select "ByVal " + p.ParameterName + " As " + p.FullTypeName).ToArray<string>()));
         builder.AppendLine(")");
         builder.Append("    MyBase.New(");
         builder.Append(string.Join(", ", (from p in contextConstructorParams select p.ParameterName).ToArray<string>()));
         builder.AppendLine(")");
         builder.AppendLine("  End Sub");
         builder.AppendLine();
     }
     builder.AppendLine("  Private Sub RunUserAuthoredQuery()");
     if (query.QueryKind == QueryLanguage.VBExpression)
     {
         builder.Append("Dim linqPadQuery = ");
     }
     else if (query.QueryKind == QueryLanguage.VBProgram)
     {
         builder.AppendLine("  Main\r\nEnd Sub");
     }
     return builder.ToString();
 }
Example #13
0
 public AutoSaveToken(QueryCore q)
 {
     if (AutoSaver._enabled)
     {
         this._query = q;
         try
         {
             this._fileStream = File.Create(this.FilePath);
         }
         catch
         {
         }
     }
 }
 public override string GetCompilerOptions(QueryCore queryCore)
 {
     return (MainForm.Instance.OptimizeQueries ? "--optimize+" : "");
 }
Example #15
0
 public abstract bool Compile(string queryText, QueryCore query, TempFileRef dataContextAssembly);
Example #16
0
 public void Dispose()
 {
     lock (this._locker)
     {
         if (!this._isDisposed)
         {
             this._isDisposed = true;
             this.ReadLineRequested = null;
             this.QueryCompiled = null;
             this.QueryCompleted = null;
             this.PluginsReady = null;
             this.CustomClickComplete = null;
             this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Finished;
             this._cancelRequest = true;
             this.ClearServer();
             this._query = null;
             this._source = null;
             try
             {
                 RemotingServices.Disconnect(this);
             }
             catch
             {
             }
         }
     }
 }
Example #17
0
 private QueryCore GetSnapshotForExecution()
 {
     QueryCore core = new QueryCore();
     using (core.TransactChanges())
     {
         core.AdditionalGACReferences = base.AdditionalGACReferences;
         core.AdditionalNamespaces = base.AdditionalNamespaces;
         core.AdditionalReferences = base.AdditionalReferences;
         core.IncludePredicateBuilder = base.IncludePredicateBuilder;
         core.ToDataGrids = base.ToDataGrids;
         core.FilePath = base.FilePath;
         core.Name = base.Name;
         core.QueryKind = base.QueryKind;
         core.Repository = base.Repository;
         core.Source = base.Source;
         core.IsMyExtensions = base.IsMyExtensions;
     }
     return core;
 }
Example #18
0
 internal ChangeTx(QueryCore query)
 {
     this._query = query;
     this._query._suspendEventCount++;
 }
Example #19
0
 public static QueryCompiler Create(QueryCore query, bool addReferences)
 {
     if (query.QueryKind.ToString().StartsWith("VB", StringComparison.Ordinal))
     {
         return new VBQueryCompiler(query, addReferences);
     }
     if (query.QueryKind.ToString().StartsWith("FSharp", StringComparison.Ordinal))
     {
         return new FSharpQueryCompiler(query, addReferences);
     }
     return new CSharpQueryCompiler(query, addReferences);
 }
 public override string GetHeader(QueryCore q)
 {
     StringBuilder builder = new StringBuilder("#define LINQPAD\r\n");
     builder.AppendLine(string.Join("\r\n", (from n in base.ImportedNamespaces select "using " + n + ";").ToArray<string>()));
     if (q.IncludePredicateBuilder)
     {
         builder.AppendLine("public static class PredicateBuilder\r\n{\r\n\tpublic static System.Linq.Expressions.Expression<Func<T, bool>> True<T> () { return f => true; }\r\n\tpublic static System.Linq.Expressions.Expression<Func<T, bool>> False<T> () { return f => false; }\r\n\r\n\tpublic static System.Linq.Expressions.Expression<Func<T, bool>> Or<T> (this System.Linq.Expressions.Expression<Func<T, bool>> expr1, System.Linq.Expressions.Expression<Func<T, bool>> expr2)\r\n\t{\r\n\t\tSystem.Linq.Expressions.Expression invokedExpr = System.Linq.Expressions.Expression.Invoke (\r\n\t\t  expr2, expr1.Parameters.Cast<System.Linq.Expressions.Expression> ());\r\n\r\n\t\treturn System.Linq.Expressions.Expression.Lambda<Func<T, bool>> (\r\n\t\t  System.Linq.Expressions.Expression.OrElse (expr1.Body, invokedExpr), expr1.Parameters);\r\n\t}\r\n\r\n\tpublic static System.Linq.Expressions.Expression<Func<T, bool>> And<T> (this System.Linq.Expressions.Expression<Func<T, bool>> expr1, System.Linq.Expressions.Expression<Func<T, bool>> expr2)\r\n\t{\r\n\t\tSystem.Linq.Expressions.Expression invokedExpr = System.Linq.Expressions.Expression.Invoke (\r\n\t\t  expr2, expr1.Parameters.Cast<System.Linq.Expressions.Expression> ());\r\n\r\n\t\treturn System.Linq.Expressions.Expression.Lambda<Func<T, bool>> (\r\n\t\t  System.Linq.Expressions.Expression.AndAlso (expr1.Body, invokedExpr), expr1.Parameters);\r\n\t}\r\n}");
     }
     builder.Append("\r\npublic partial class UserQuery");
     if (q.QueryBaseClassName != null)
     {
         builder.Append(" : " + q.QueryBaseClassName);
     }
     builder.AppendLine("\r\n{");
     DataContextDriver driver = q.GetDriver(true);
     if (driver != null)
     {
         builder.Append("  public UserQuery (");
         ParameterDescriptor[] contextConstructorParams = base.GetContextConstructorParams(driver, q.Repository);
         builder.Append(string.Join(", ", (from p in contextConstructorParams select p.FullTypeName + " " + p.ParameterName).ToArray<string>()));
         builder.Append(") : base (");
         builder.Append(string.Join(", ", (from p in contextConstructorParams select p.ParameterName).ToArray<string>()));
         builder.AppendLine(") { }");
     }
     builder.AppendLine("\r\n  [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]");
     builder.AppendLine("  void RunUserAuthoredQuery()");
     builder.AppendLine("  {");
     if (q.QueryKind == QueryLanguage.Expression)
     {
         builder.AppendLine("  LINQPad.Extensions.Dump<object> (");
     }
     else if (q.QueryKind == QueryLanguage.Program)
     {
         builder.AppendLine("  Main();");
         builder.AppendLine("}");
     }
     return builder.ToString();
 }
 public override string GetFooter(QueryCore query)
 {
     StringBuilder builder = new StringBuilder();
     builder.AppendLine();
     if (query.QueryKind == QueryLanguage.Expression)
     {
         builder.AppendLine("  );");
     }
     if (query.QueryKind != QueryLanguage.Program)
     {
         builder.AppendLine("  }");
     }
     builder.AppendLine("}");
     return builder.ToString();
 }
 public override string GetCompilerOptions(QueryCore queryCore)
 {
     bool flag = queryCore.Source.Contains("#LINQPad /optimize-");
     return ("/unsafe" + ((!MainForm.Instance.OptimizeQueries || flag) ? "" : " /optimize"));
 }
Example #23
0
 public abstract string GetFooter(QueryCore query);
 public override bool Compile(string queryText, QueryCore query, TempFileRef dataContextAssembly)
 {
     Process process;
     string str9;
     bool flag2;
     StringBuilder builder = new StringBuilder(this.GetHeader(query));
     base.LineOffset = builder.ToString().Count<char>(c => c == '\n');
     if (queryText.Trim().Length == 0)
     {
         queryText = "\"\"";
     }
     string str = queryText.Replace("\t", "".PadRight(UserOptions.Instance.TabSizeActual));
     if (query.QueryKind == QueryLanguage.FSharpExpression)
     {
         str = "  " + str.Replace("\r\n", "\r\n  ");
     }
     builder.AppendLine(str);
     builder.Append(this.GetFooter(query));
     base.OutputFile = TempFileRef.GetRandom("query", (query.QueryKind == QueryLanguage.FSharpExpression) ? ".dll" : ".exe");
     base.PDBFile = new TempFileRef(Path.ChangeExtension(base.OutputFile.FullPath, ".pdb"));
     List<string> list = new List<string>(base.References);
     if (dataContextAssembly != null)
     {
         list.Add(dataContextAssembly.FullPath);
     }
     string str2 = @"Microsoft F#\v4.0\fsc.exe";
     string path = Path.Combine(PathHelper.ProgramFiles, str2);
     string str4 = Path.Combine(PathHelper.ProgramFilesX86, str2);
     if (!(File.Exists(path) || File.Exists(str4)))
     {
         base.ReportError("Cannot locate " + str4 + " - is F# installed?");
         return false;
     }
     string str5 = File.Exists(str4) ? str4 : path;
     string str6 = Path.ChangeExtension(base.OutputFile.FullPath, ".fs");
     string str7 = (query.QueryKind == QueryLanguage.FSharpExpression) ? "library" : "exe";
     string str8 = (("-o:\"" + base.OutputFile.FullPath + "\" -g --debug:full --target:" + str7 + " --utf8output " + this.GetCompilerOptions(query) + " ") + string.Join(" ", (from r in list select "-r:\"" + r + "\"").ToArray<string>())) + " \"" + str6 + "\"";
     ProcessStartInfo startInfo = new ProcessStartInfo {
         FileName = str5,
         Arguments = str8,
         RedirectStandardError = true,
         UseShellExecute = false,
         CreateNoWindow = true
     };
     File.WriteAllText(str6, builder.ToString());
     Stopwatch stopwatch = Stopwatch.StartNew();
     try
     {
         process = Process.Start(startInfo);
         str9 = process.StandardError.ReadToEnd();
     }
     finally
     {
         try
         {
             File.Delete(str6);
         }
         catch
         {
         }
     }
     stopwatch.Stop();
     if (!(flag2 = process.ExitCode == 0))
     {
         this.ParseError(str9);
     }
     return flag2;
 }
 public VBQueryCompiler(QueryCore query, bool addReferences) : base(query, addReferences)
 {
 }
 public override string GetHeader(QueryCore q)
 {
     StringBuilder builder = new StringBuilder();
     if (q.QueryKind == QueryLanguage.FSharpExpression)
     {
         builder.AppendLine("namespace global\r\n");
     }
     builder.AppendLine(string.Join("\r\n", (from n in base.ImportedNamespaces select "open " + n).ToArray<string>()));
     builder.AppendLine("open LINQPad.FSharpExtensions");
     if (q.QueryKind == QueryLanguage.FSharpProgram)
     {
         builder.AppendLine("let Dump = Extensions.Dump");
     }
     DataContextDriver driver = q.GetDriver(true);
     StringBuilder builder2 = new StringBuilder();
     if (q.QueryKind == QueryLanguage.FSharpExpression)
     {
         builder.Append("\r\ntype UserQuery(");
         if ((driver != null) && (q.QueryKind == QueryLanguage.FSharpExpression))
         {
             builder2.Append(" inherit " + q.QueryBaseClassName + "(");
             ParameterDescriptor[] contextConstructorParams = base.GetContextConstructorParams(driver, q.Repository);
             builder.Append(string.Join(", ", (from p in contextConstructorParams select p.ParameterName + " : " + p.FullTypeName).ToArray<string>()));
             builder.Append(") as this ");
             builder2.Append(string.Join(", ", (from p in contextConstructorParams select p.ParameterName).ToArray<string>()));
             builder2.Append(")");
         }
         else
         {
             builder.Append(")");
         }
         builder.AppendLine(" = class");
         if (builder2.Length > 0)
         {
             builder.AppendLine(builder2.ToString());
         }
         builder.AppendLine(" member private dc.RunUserAuthoredQuery() =");
         builder.AppendLine("  (");
     }
     return builder.ToString();
 }
 public override string GetFooter(QueryCore query)
 {
     StringBuilder builder = new StringBuilder();
     builder.AppendLine();
     if (query.QueryKind == QueryLanguage.FSharpExpression)
     {
         builder.AppendLine("  ).Dump()");
         builder.AppendLine("end");
     }
     return builder.ToString();
 }
Example #28
0
 public void Run(string querySelection, bool compileOnly, QueryCompilationEventArgs lastCompiler, LINQPad.UI.PluginWindowManager winManager)
 {
     lock (this._executionLock)
     {
         FileWithVersionInfo[] infoArray;
         FileWithVersionInfo[] infoArray2;
         if (this.IsRunning)
         {
             return;
         }
         this.GetAssemblyReferenceMap(out infoArray, out infoArray2);
         bool flag2 = this.NeedsRefresh(this._lastVolatileRefs, infoArray);
         bool flag3 = this.NeedsRefresh(this._lastNonvolatileRefs, infoArray2);
         bool flag4 = (!flag2 && (this._lastVolatileRefs != null)) && (this._lastVolatileRefs.Length > infoArray.Length);
         this._lastVolatileRefs = infoArray;
         this._lastNonvolatileRefs = infoArray2;
         if (flag2 || flag3)
         {
             this.PolluteCachedDomain(true);
         }
         if (this._client != null)
         {
             if ((this._cachedDomainPolluted || Program.FreshAppDomains) || ((!Program.PreserveAppDomains && !this.IsUserCachePresent()) && (((this._loadedAssemblyCount > 40) || (this._cumulativeFootprint > 0x1312d00L)) || this._client.LastWorkerThreadAborted())))
             {
                 this._client.Cancel(false, true);
                 this._cachedDomain = null;
             }
             this._client.Dispose();
         }
         this._queryStarting = true;
         this._querySnapshot = this.GetSnapshotForExecution();
         if ((querySelection != null) && (this._querySnapshot.QueryKind == QueryLanguage.Program))
         {
             if (querySelection.TrimEnd(new char[0]).EndsWith(";"))
             {
                 this._querySnapshot.QueryKind = QueryLanguage.Statements;
             }
             else if (!(querySelection.Trim().Contains("\n") && querySelection.Contains<char>('{')))
             {
                 this._querySnapshot.QueryKind = QueryLanguage.Expression;
             }
         }
         else if (((querySelection != null) && (this._querySnapshot.QueryKind == QueryLanguage.Statements)) && !querySelection.Contains<char>(';'))
         {
             this._querySnapshot.QueryKind = QueryLanguage.Expression;
         }
         this._client = new Client(this._querySnapshot, querySelection, compileOnly, lastCompiler, new Func<Client, Server>(this.CreateServer), winManager);
         this._client.QueryCompiled += new EventHandler<QueryCompilationEventArgs>(this._client_QueryCompiled);
         this._client.QueryCompleted += new EventHandler<QueryStatusEventArgs>(this._client_QueryCompleted);
         this._client.ReadLineRequested += new EventHandler<ReadLineEventArgs>(this._client_ReadLineRequested);
         this._client.PluginsReady += new EventHandler(this._client_PluginsReady);
         this._client.CustomClickComplete += new EventHandler(this._client_CustomClickComplete);
         if (this.AllowShadow())
         {
             Stopwatch stopwatch = Stopwatch.StartNew();
             if (flag2)
             {
                 this.CreateShadow();
             }
             else if (flag4)
             {
                 this.UpdateShadow();
             }
             stopwatch.Stop();
         }
     }
     ThreadPool.QueueUserWorkItem(delegate (object _) {
         try
         {
             base.AutoSave(true);
         }
         catch
         {
         }
     });
     new Thread(new ThreadStart(this._client.Start)) { IsBackground = true, Name = "Query Starter" }.Start();
     this._queryWatch.Reset();
     this._queryWatch.Start();
 }
 public override string GetCompilerOptions(QueryCore queryCore)
 {
     return ("/optioninfer+" + (MainForm.Instance.OptimizeQueries ? " /optimize" : "") + (UserOptions.Instance.CompileVBInStrictMode ? " /optionstrict" : ""));
 }
 public override bool Compile(string queryText, QueryCore query, TempFileRef dataContextAssembly)
 {
     string str = "";
     if (queryText.Contains("#LINQPad /optimize-"))
     {
         queryText = queryText.Replace("#LINQPad /optimize-", "".PadRight("#LINQPad /optimize-".Length));
     }
     bool flag = queryText.Contains("#define NONEST");
     if (queryText.Contains("#define"))
     {
         string str2 = queryText.Replace("\r\n", "\n");
         int preprocessorDirectiveEndOffset = this.GetPreprocessorDirectiveEndOffset(str2);
         if (preprocessorDirectiveEndOffset > 0)
         {
             str = str2.Substring(0, preprocessorDirectiveEndOffset) + "\n";
             queryText = str2.Substring(preprocessorDirectiveEndOffset);
         }
     }
     if (queryText.Contains("Util.DisplayControl"))
     {
     }
     if (!((CS$<>9__CachedAnonymousMethodDelegate13 != null) || base.References.Any<string>(CS$<>9__CachedAnonymousMethodDelegate13)))
     {
         base.References.Add("System.Windows.Forms.dll");
     }
     string header = this.GetHeader(query);
     base.LineOffset = header.Count<char>(c => c == '\n');
     if (str.Length > 0)
     {
         base.LineOffset++;
     }
     StringBuilder builder = new StringBuilder(str + header);
     if (queryText.Trim().Length == 0)
     {
         queryText = "\"\"";
     }
     builder.AppendLine(queryText + "\r\n");
     builder.Append(this.GetFooter(query));
     if (base.IsMyExtensions || flag)
     {
         builder = new StringBuilder(this.ExtractNestedTypes(builder.ToString(), false));
     }
     string str4 = "v4.0";
     Dictionary<string, string> providerOptions = new Dictionary<string, string>();
     providerOptions.Add("CompilerVersion", str4);
     CSharpCodeProvider codeProvider = new CSharpCodeProvider(providerOptions);
     string compilerOptions = this.GetCompilerOptions(query);
     Stopwatch stopwatch = Stopwatch.StartNew();
     bool flag2 = base.Compile(codeProvider, builder.ToString(), dataContextAssembly, query.QueryKind, compilerOptions);
     stopwatch.Stop();
     if (!flag2)
     {
         IEnumerable<CompilerError> source = base.Errors.Cast<CompilerError>().Where<CompilerError>(delegate (CompilerError e) {
             if (e.ErrorNumber == "CS0006")
             {
             }
             return (CS$<>9__CachedAnonymousMethodDelegate1a == null) && (e.ErrorText.Count<char>(CS$<>9__CachedAnonymousMethodDelegate1a) == 2);
         });
         if (source.Any<CompilerError>())
         {
             List<CompilerError> list = new List<CompilerError>();
             foreach (CompilerError error in source)
             {
                 string filename = error.ErrorText.Substring(error.ErrorText.IndexOf('\'') + 1);
                 try
                 {
                     filename = Path.GetFileName(filename.Substring(0, filename.IndexOf('\'')));
                 }
                 catch
                 {
                     continue;
                 }
                 string key = base.References.FirstOrDefault<string>(r => Path.GetFileName(r).Equals(filename, StringComparison.InvariantCultureIgnoreCase));
                 if (key != null)
                 {
                     base.References.Remove(key);
                     list.Add(error);
                 }
             }
             if (list.Any<CompilerError>())
             {
                 if (flag2 = base.Compile(codeProvider, builder.ToString(), dataContextAssembly, query.QueryKind, compilerOptions))
                 {
                     list.Reverse();
                     foreach (CompilerError error in list)
                     {
                         error.IsWarning = true;
                         base.Errors.Insert(0, error);
                     }
                 }
                 if (!flag2)
                 {
                     string errorMessage = base.ErrorMessage;
                     string[] strArray = new string[] { errorMessage, "\r\n", (list.Count == 1) ? "There was also an assembly reference error" : "There were also assembly reference errors", " - press F4 to fix:\r\n", string.Join("\r\n", (from s in list select "   " + s.ErrorText).ToArray<string>()) };
                     base.ErrorMessage = string.Concat(strArray);
                 }
             }
         }
     }
     if (!flag2 && (query.QueryKind == QueryLanguage.Statements))
     {
     }
     if ((CS$<>9__CachedAnonymousMethodDelegate17 == null) && base.Errors.Cast<CompilerError>().Any<CompilerError>(CS$<>9__CachedAnonymousMethodDelegate17))
     {
         builder.Replace("void RunUserAuthoredQuery()", "async System.Threading.Tasks.Task RunUserAuthoredQuery()", 0, (str + header).Length);
         flag2 = base.Compile(codeProvider, builder.ToString(), dataContextAssembly, query.QueryKind, compilerOptions);
     }
     if ((!flag2 && (base.ErrorNumber == "CS0012")) && base.ErrorMessage.Contains("'System.Windows.Forms,"))
     {
         base.References.Add("System.Windows.Forms.dll");
         flag2 = base.Compile(codeProvider, builder.ToString(), dataContextAssembly, query.QueryKind, compilerOptions);
     }
     if (((!flag2 && (base.ErrorNumber == "CS1502")) && (query.QueryKind == QueryLanguage.Expression)) && base.ErrorMessage.Contains("cannot convert from 'method group' to 'object'"))
     {
         base.ErrorMessage = "Cannot convert from a method group to an expression. Try adding '()' after the method name.";
         return false;
     }
     if ((!flag2 && !flag) && !base.IsMyExtensions)
     {
     }
     if ((CS$<>9__CachedAnonymousMethodDelegate18 == null) && base.Errors.Cast<CompilerError>().Any<CompilerError>(CS$<>9__CachedAnonymousMethodDelegate18))
     {
         string str8 = this.ExtractNestedTypes(builder.ToString(), true);
         if (str8 != null)
         {
             if (!(flag2 = base.Compile(codeProvider, str8, dataContextAssembly, query.QueryKind, compilerOptions)))
             {
             }
             if ((CS$<>9__CachedAnonymousMethodDelegate19 == null) && base.Errors.Cast<CompilerError>().Any<CompilerError>(CS$<>9__CachedAnonymousMethodDelegate19))
             {
                 str8 = this.ExtractNestedTypes(builder.ToString(), false);
                 if (str8 != null)
                 {
                     flag2 = base.Compile(codeProvider, str8, dataContextAssembly, query.QueryKind, compilerOptions);
                 }
             }
         }
     }
     if (!flag2)
     {
         if ((query.QueryKind == QueryLanguage.Expression) && (base.ErrorMessage == ") expected"))
         {
             base.ErrorMessage = ") or end of expression expected";
             if (queryText.Contains<char>(';'))
             {
                 base.ErrorMessage = base.ErrorMessage + " (change the Query Language to 'C# Statements' for multi-statement queries)";
             }
         }
         else if (base.ErrorNumber == "CS0012")
         {
             base.ErrorMessage = base.ErrorMessage + " (Press F4)";
         }
         else
         {
             base.ErrorMessage = base.ErrorMessage.Replace("are you missing a using directive or an assembly reference?", "press F4 to add a using directive or assembly reference");
         }
         if (base.ErrorMessage.Contains("PredicateBuilder"))
         {
             base.ErrorMessage = base.ErrorMessage + QueryCompiler.PredicateBuilderMessage;
         }
     }
     return flag2;
 }
Example #31
0
 public abstract string GetHeader(QueryCore query);
Example #32
0
 public void Run(string querySelection, bool compileOnly, QueryCompilationEventArgs lastCompiler, LINQPad.UI.PluginWindowManager winManager)
 {
     lock (this._executionLock)
     {
         FileWithVersionInfo[] infoArray;
         FileWithVersionInfo[] infoArray2;
         if (this.IsRunning)
         {
             return;
         }
         this.GetAssemblyReferenceMap(out infoArray, out infoArray2);
         bool flag2 = this.NeedsRefresh(this._lastVolatileRefs, infoArray);
         bool flag3 = this.NeedsRefresh(this._lastNonvolatileRefs, infoArray2);
         bool flag4 = (!flag2 && (this._lastVolatileRefs != null)) && (this._lastVolatileRefs.Length > infoArray.Length);
         this._lastVolatileRefs    = infoArray;
         this._lastNonvolatileRefs = infoArray2;
         if (flag2 || flag3)
         {
             this.PolluteCachedDomain(true);
         }
         if (this._client != null)
         {
             if ((this._cachedDomainPolluted || Program.FreshAppDomains) || ((!Program.PreserveAppDomains && !this.IsUserCachePresent()) && (((this._loadedAssemblyCount > 40) || (this._cumulativeFootprint > 0x1312d00L)) || this._client.LastWorkerThreadAborted())))
             {
                 this._client.Cancel(false, true);
                 this._cachedDomain = null;
             }
             this._client.Dispose();
         }
         this._queryStarting = true;
         this._querySnapshot = this.GetSnapshotForExecution();
         if ((querySelection != null) && (this._querySnapshot.QueryKind == QueryLanguage.Program))
         {
             if (querySelection.TrimEnd(new char[0]).EndsWith(";"))
             {
                 this._querySnapshot.QueryKind = QueryLanguage.Statements;
             }
             else if (!(querySelection.Trim().Contains("\n") && querySelection.Contains <char>('{')))
             {
                 this._querySnapshot.QueryKind = QueryLanguage.Expression;
             }
         }
         else if (((querySelection != null) && (this._querySnapshot.QueryKind == QueryLanguage.Statements)) && !querySelection.Contains <char>(';'))
         {
             this._querySnapshot.QueryKind = QueryLanguage.Expression;
         }
         this._client = new Client(this._querySnapshot, querySelection, compileOnly, lastCompiler, new Func <Client, Server>(this.CreateServer), winManager);
         this._client.QueryCompiled       += new EventHandler <QueryCompilationEventArgs>(this._client_QueryCompiled);
         this._client.QueryCompleted      += new EventHandler <QueryStatusEventArgs>(this._client_QueryCompleted);
         this._client.ReadLineRequested   += new EventHandler <ReadLineEventArgs>(this._client_ReadLineRequested);
         this._client.PluginsReady        += new EventHandler(this._client_PluginsReady);
         this._client.CustomClickComplete += new EventHandler(this._client_CustomClickComplete);
         if (this.AllowShadow())
         {
             Stopwatch stopwatch = Stopwatch.StartNew();
             if (flag2)
             {
                 this.CreateShadow();
             }
             else if (flag4)
             {
                 this.UpdateShadow();
             }
             stopwatch.Stop();
         }
     }
     ThreadPool.QueueUserWorkItem(delegate(object _) {
         try
         {
             base.AutoSave(true);
         }
         catch
         {
         }
     });
     new Thread(new ThreadStart(this._client.Start))
     {
         IsBackground = true, Name = "Query Starter"
     }.Start();
     this._queryWatch.Reset();
     this._queryWatch.Start();
 }
Example #33
0
 internal ChangeTx(QueryCore query)
 {
     this._query = query;
     this._query._suspendEventCount++;
 }