public bool Compile(CodeDomProvider codeProvider, string source, TempFileRef dataContextAssembly, QueryLanguage queryKind, string compilerOptions) { if (this.IsMyExtensions) { string directoryName = Path.GetDirectoryName(MyExtensions.QueryFilePath); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } TempFileRef ref2 = new TempFileRef(Path.ChangeExtension(MyExtensions.QueryFilePath, ".dll")) { AutoDelete = false }; this.OutputFile = ref2; TempFileRef ref3 = new TempFileRef(Path.ChangeExtension(MyExtensions.QueryFilePath, ".pdb")) { AutoDelete = false }; this.PDBFile = ref3; } else { this.OutputFile = TempFileRef.GetRandom("query", ".dll"); this.PDBFile = new TempFileRef(Path.ChangeExtension(this.OutputFile.FullPath, ".pdb")); } List<string> references = new List<string>(this.References); if (!((dataContextAssembly == null) || string.IsNullOrEmpty(dataContextAssembly.FullPath))) { references.Add(dataContextAssembly.FullPath); } return base.Compile(codeProvider, references, source.ToString(), this.OutputFile.FullPath, compilerOptions); }
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; }
public DataContextInfo(LINQPad.Repository repository, bool busy, string status, string error, TempFileRef assemblyPath, IEnumerable<ExplorerItem> schema) { this.Repository = repository; this.Busy = busy; this.Status = status; this.Error = error; this.AssemblyPath = assemblyPath; this.Schema = schema; }
internal void RegisterRemoteAssemblyFile(TempFileRef a) { lock (this._executionLock) { if (!this._remotelyLoadedAssemblies.Contains(a)) { this._remotelyLoadedAssemblies.Add(a); } } }
private void UpdateSchema() { object obj2; LINQPad.Repository repository; lock ((obj2 = this._locker)) { if ((this._worker != Thread.CurrentThread) || this._disposed) { return; } this._status = "Populating"; } this.NotifyChange(); TempFileRef random = TempFileRef.GetRandom("TypedDataContext", ".dll"); AssemblyName assemblyToBuild = new AssemblyName(Path.GetFileNameWithoutExtension(random.FileName)) { CodeBase = random.FullPath }; lock ((obj2 = this._locker)) { if ((this._worker != Thread.CurrentThread) || this._disposed) { return; } repository = this._repository.Clone(); } IEnumerable <ExplorerItem> enumerable = null; string nameSpace = "LINQPad.User"; string typeName = "TypedDataContext"; IDictionary <string, object> sessionData = null; using (DomainIsolator isolator = new DomainIsolator(repository.DriverLoader.CreateNewDriverDomain("LINQPad Schema Generator", null, null))) { enumerable = isolator.GetInstance <SchemaBuilder>().GetSchemaAndBuildAssembly(repository.GetStore().ToString(), assemblyToBuild, ref nameSpace, ref typeName, Program.AllowOneToOne, out sessionData); } lock ((obj2 = this._locker)) { if (this._worker == Thread.CurrentThread) { this._repository.AutoGenNamespace = nameSpace; this._repository.AutoGenTypeName = typeName; this._repository.IsAutoGenAssemblyAvailable = true; if (sessionData != null) { this._repository.SessionData = sessionData; } this._schema = enumerable; this._assemblyPath = random; } } }
private void CreateShadow() { string lastShadow = this._shadowFolder; if ((this._lastVolatileRefs != null) && (this._lastVolatileRefs.Length > 0)) { do { this._shadowFolder = Path.Combine(Program.TempFolder, "shadow_" + TempFileRef.GetRandomName(6)); }while (Directory.Exists(this._shadowFolder)); Directory.CreateDirectory(this._shadowFolder); foreach (FileWithVersionInfo info in this._lastVolatileRefs) { this.CopyFileToShadow(lastShadow, info); } } else { this._shadowFolder = null; } if (lastShadow != null) { this.DeleteShadow(lastShadow); } }
private static void Run(string queryToLoad, bool runQuery, string activationCode, bool deactivate, bool noForward, bool noUpdate, string caller) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (Environment.OSVersion.Version.Major >= 6) { try { SetProcessDPIAware(); } catch { } } AutoSaver.Start(); Wheeler.Register(); if (Environment.OSVersion.Version.Major < 6) { ToolStripManager.RenderMode = ToolStripManagerRenderMode.System; } if (!((activationCode != null) || deactivate)) { Splash = new LINQPad.UI.Splash(); Splash.Show(); Splash.Update(); } Log.add_StringWriter(new Action <string>(Log.Write)); Log.add_ExceptionWriter(new Action <Exception>(Log.Write)); TypeResolver.ManyToOne = Resources.ManyToOne; TypeResolver.OneToMany = Resources.OneToMany; TypeResolver.OneToOne = Resources.OneToOne; TypeResolver.ManyToMany = Resources.ManyToMany; TypeResolver.Results = Resources.Results; TypeResolver.Column = Resources.Column; TypeResolver.Key = Resources.Key; TypeResolver.Database = Resources.Database; TypeResolver.GetSameFolderReferences = new Func <string, string[]>(AssemblyProber.GetSameFolderReferences); WSAgent.WebClientFactory = new Func <WebClient>(WebHelper.GetWebClient); WSAgent.FastWebClientFactory = new Func <WebClient>(WebHelper.GetFastWebClient); WSAgent.BackupWebClientFactory = new Func <WebClient>(WebHelper.GetBackupWebClient); WSAgent.CurrentVersionString = VersionString; AutocompletionManager.PassiveAutocompletion = UserOptions.Instance.PassiveAutocompletion; AutocompletionManager.DisableLambdaSnippets = UserOptions.Instance.DisableLambdaSnippets; SnippetManager.set_LINQPadSnippetsFolder(UserOptions.Instance.GetCustomSnippetsFolder(false)); WSAgent.DiagnosticMode = DiagnosticMode; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException); if (deactivate) { WSAgent.Remove(true); } else { if (activationCode != null) { using (RegisterForm form = new RegisterForm(activationCode)) { form.ShowDialog(); return; } } if (!noUpdate) { Thread thread = new Thread(new ParameterizedThreadStart(UpdateAgent.RunServerComms)) { Name = "Update Agent", IsBackground = true }; _updateThread = thread; _updateThread.Start(caller); } if (!string.IsNullOrEmpty(caller)) { new Thread(delegate { try { Thread.Sleep(0xbb8); if (File.Exists(caller)) { FileInfo info = new FileInfo(caller); if (((info.Directory == null) || (info.Directory.Parent == null)) || (info.Directory.Parent.Name.ToLowerInvariant() != "updates")) { if (info.IsReadOnly) { info.IsReadOnly = false; } if (!File.Exists(caller + ".config")) { try { File.WriteAllText(caller + ".config", "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<configuration>\r\n <startup useLegacyV2RuntimeActivationPolicy=\"true\">\r\n <supportedRuntime version=\"v4.0\"/>\r\n </startup>\r\n <runtime>\r\n <legacyUnhandledExceptionPolicy enabled=\"1\" />\r\n </runtime>\r\n</configuration>"); } catch { } } string path = Assembly.GetExecutingAssembly().Location + ".config"; if (!File.Exists(path)) { try { File.WriteAllText(path, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<configuration>\r\n <startup useLegacyV2RuntimeActivationPolicy=\"true\">\r\n <supportedRuntime version=\"v4.0\"/>\r\n </startup>\r\n <runtime>\r\n <legacyUnhandledExceptionPolicy enabled=\"1\" />\r\n </runtime>\r\n</configuration>"); } catch { } } try { File.Copy(Assembly.GetExecutingAssembly().Location, caller, true); } catch { Thread.Sleep(0x1388); File.Copy(Assembly.GetExecutingAssembly().Location, caller, true); } } } } catch { } }) { Name = "Update patcher" }.Start(); } UnpackDb(); QueryOneToOne(); QueryStudioKeys(noForward); StartSemanticParsingService(); new Thread(delegate { try { Thread.Sleep(0x3e8); if (GacResolver.IsLINQPadGaced()) { MessageBox.Show("Warning: A different revision of LINQPad has been installed to the Global Assembly Cache. This will prevent correct operation.", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch { } }) { IsBackground = true }.Start(); Application.Run(new MainForm(queryToLoad, runQuery)); TempFileRef.DeleteAll(); } }
public DataContextInfo(LINQPad.Repository repository, bool busy, string status, string error, TempFileRef assemblyPath, IEnumerable <ExplorerItem> schema) { this.Repository = repository; this.Busy = busy; this.Status = status; this.Error = error; this.AssemblyPath = assemblyPath; this.Schema = schema; }
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; }
public abstract bool Compile(string queryText, QueryCore query, TempFileRef dataContextAssembly);
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; }
private void UpdateSchema() { object obj2; LINQPad.Repository repository; lock ((obj2 = this._locker)) { if ((this._worker != Thread.CurrentThread) || this._disposed) { return; } this._status = "Populating"; } this.NotifyChange(); TempFileRef random = TempFileRef.GetRandom("TypedDataContext", ".dll"); AssemblyName assemblyToBuild = new AssemblyName(Path.GetFileNameWithoutExtension(random.FileName)) { CodeBase = random.FullPath }; lock ((obj2 = this._locker)) { if ((this._worker != Thread.CurrentThread) || this._disposed) { return; } repository = this._repository.Clone(); } IEnumerable<ExplorerItem> enumerable = null; string nameSpace = "LINQPad.User"; string typeName = "TypedDataContext"; IDictionary<string, object> sessionData = null; using (DomainIsolator isolator = new DomainIsolator(repository.DriverLoader.CreateNewDriverDomain("LINQPad Schema Generator", null, null))) { enumerable = isolator.GetInstance<SchemaBuilder>().GetSchemaAndBuildAssembly(repository.GetStore().ToString(), assemblyToBuild, ref nameSpace, ref typeName, Program.AllowOneToOne, out sessionData); } lock ((obj2 = this._locker)) { if (this._worker == Thread.CurrentThread) { this._repository.AutoGenNamespace = nameSpace; this._repository.AutoGenTypeName = typeName; this._repository.IsAutoGenAssemblyAvailable = true; if (sessionData != null) { this._repository.SessionData = sessionData; } this._schema = enumerable; this._assemblyPath = random; } } }