コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public abstract bool Compile(string queryText, QueryCore query, TempFileRef dataContextAssembly);
コード例 #5
0
 public QueryCompilationEventArgs(QueryCompiler c, TempFileRef dataContextDLL, bool partialSource)
 {
     this.Compiler       = c;
     this.DataContextDLL = dataContextDLL;
     this.PartialSource  = partialSource;
 }
コード例 #6
0
        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);
        }