Exemple #1
0
        public virtual void GenerateDatabase(GenerateDatabaseOptions options, Action <int> onExit = null)
        {
            var req = new PythonTypeDatabaseCreationRequest {
                Factory       = this,
                OutputPath    = DatabasePath,
                SkipUnchanged = options.HasFlag(GenerateDatabaseOptions.SkipUnchanged)
            };

            GenerateDatabase(req, onExit);
        }
        public static void Generate(PythonTypeDatabaseCreationRequest request)
        {
            var onExit = request.OnExit;

            GenerateAsync(request).ContinueWith(t => {
                var exc = t.Exception;
                if (exc == null)
                {
                    return;
                }

                try {
                    var message = string.Format(
                        "ERROR_STDLIB: {0}\\{1}{2}{3}",
                        request.Factory.Id,
                        request.Factory.Configuration.Version,
                        Environment.NewLine,
                        (exc.InnerException ?? exc).ToString()
                        );

                    Debug.WriteLine(message);

                    var glogPath = Path.Combine(CompletionDatabasePath, "AnalysisLog.txt");
                    File.AppendAllText(glogPath, message);
                } catch (IOException) {
                } catch (ArgumentException) {
                } catch (SecurityException) {
                } catch (UnauthorizedAccessException) {
                }

                if (onExit != null)
                {
                    onExit(PythonTypeDatabase.InvalidOperationExitCode);
                }
            }, TaskContinuationOptions.OnlyOnFaulted);
        }
Exemple #3
0
        protected virtual void GenerateDatabase(PythonTypeDatabaseCreationRequest request, Action <int> onExit = null)
        {
            WatchingLibrary = false;
            _generating     = true;

            PythonTypeDatabase.GenerateAsync(request).ContinueWith(t => {
                int exitCode;
                try {
                    exitCode = t.Result;
                } catch (Exception ex) {
                    Debug.Fail(ex.ToString());
                    exitCode = PythonTypeDatabase.InvalidOperationExitCode;
                }

                if (exitCode != PythonTypeDatabase.AlreadyGeneratingExitCode)
                {
                    _generating = false;
                }
                if (onExit != null)
                {
                    onExit(exitCode);
                }
            });
        }
        public static void Generate(PythonTypeDatabaseCreationRequest request) {
            var onExit = request.OnExit;

            GenerateAsync(request).ContinueWith(t => {
                var exc = t.Exception;
                if (exc == null) {
                    return;
                }

                try {
                    var message = string.Format(
                        "ERROR_STDLIB: {0}\\{1}{2}{3}",
                        request.Factory.Id,
                        request.Factory.Configuration.Version,
                        Environment.NewLine,
                        (exc.InnerException ?? exc).ToString()
                    );

                    Debug.WriteLine(message);

                    var glogPath = Path.Combine(CompletionDatabasePath, "AnalysisLog.txt");
                    File.AppendAllText(glogPath, message);
                } catch (IOException) {
                } catch (ArgumentException) {
                } catch (SecurityException) {
                } catch (UnauthorizedAccessException) {
                }

                if (onExit != null) {
                    onExit(PythonTypeDatabase.InvalidOperationExitCode);
                }
            }, TaskContinuationOptions.OnlyOnFaulted);
        }
        public static async Task<int> GenerateAsync(PythonTypeDatabaseCreationRequest request) {
            var fact = request.Factory;
            var evt = request.OnExit;
            if (fact == null || !Directory.Exists(fact.Configuration.LibraryPath)) {
                if (evt != null) {
                    evt(NotSupportedExitCode);
                }
                return NotSupportedExitCode;
            }
            var outPath = request.OutputPath;

            var analyzerPath = NodejsToolsInstallPath.GetFile("Microsoft.NodejsTools.Analyzer.exe");

            Directory.CreateDirectory(CompletionDatabasePath);

            var baseDb = BaselineDatabasePath;
            if (request.ExtraInputDatabases.Any()) {
                baseDb = baseDb + ";" + string.Join(";", request.ExtraInputDatabases);
            }

            var logPath = Path.Combine(outPath, "AnalysisLog.txt");
            var glogPath = Path.Combine(CompletionDatabasePath, "AnalysisLog.txt");

            using (var output = ProcessOutput.RunHiddenAndCapture(
                analyzerPath,
                "/id", fact.Id.ToString("B"),
                "/version", fact.Configuration.Version.ToString(),
                "/python", fact.Configuration.InterpreterPath,
                "/library", fact.Configuration.LibraryPath,
                "/outdir", outPath,
                "/basedb", baseDb,
                (request.SkipUnchanged ? null : "/all"),  // null will be filtered out; empty strings are quoted
                "/log", logPath,
                "/glog", glogPath,
                "/wait", (request.WaitFor != null ? AnalyzerStatusUpdater.GetIdentifier(request.WaitFor) : "")
            )) {
                output.PriorityClass = ProcessPriorityClass.BelowNormal;
                int exitCode = await output;

                if (exitCode > -10 && exitCode < 0) {
                    try {
                        File.AppendAllLines(
                            glogPath,
                            new[] { string.Format("FAIL_STDLIB: ({0}) {1}", exitCode, output.Arguments) }
                                .Concat(output.StandardErrorLines)
                        );
                    } catch (IOException) {
                    } catch (ArgumentException) {
                    } catch (SecurityException) {
                    } catch (UnauthorizedAccessException) {
                    }
                }

                if (evt != null) {
                    evt(exitCode);
                }
                return exitCode;
            }
        }
        public static async Task <int> GenerateAsync(PythonTypeDatabaseCreationRequest request)
        {
            var fact = request.Factory;
            var evt  = request.OnExit;

            if (fact == null || !Directory.Exists(fact.Configuration.LibraryPath))
            {
                if (evt != null)
                {
                    evt(NotSupportedExitCode);
                }
                return(NotSupportedExitCode);
            }
            var outPath = request.OutputPath;

            var analyzerPath = NodejsToolsInstallPath.GetFile("Microsoft.NodejsTools.Analyzer.exe");

            Directory.CreateDirectory(CompletionDatabasePath);

            var baseDb = BaselineDatabasePath;

            if (request.ExtraInputDatabases.Any())
            {
                baseDb = baseDb + ";" + string.Join(";", request.ExtraInputDatabases);
            }

            var logPath  = Path.Combine(outPath, "AnalysisLog.txt");
            var glogPath = Path.Combine(CompletionDatabasePath, "AnalysisLog.txt");

            using (var output = ProcessOutput.RunHiddenAndCapture(
                       analyzerPath,
                       "/id", fact.Id.ToString("B"),
                       "/version", fact.Configuration.Version.ToString(),
                       "/python", fact.Configuration.InterpreterPath,
                       "/library", fact.Configuration.LibraryPath,
                       "/outdir", outPath,
                       "/basedb", baseDb,
                       (request.SkipUnchanged ? null : "/all"), // null will be filtered out; empty strings are quoted
                       "/log", logPath,
                       "/glog", glogPath,
                       "/wait", (request.WaitFor != null ? AnalyzerStatusUpdater.GetIdentifier(request.WaitFor) : "")
                       )) {
                output.PriorityClass = ProcessPriorityClass.BelowNormal;
                int exitCode = await output;

                if (exitCode > -10 && exitCode < 0)
                {
                    try {
                        File.AppendAllLines(
                            glogPath,
                            new[] { string.Format("FAIL_STDLIB: ({0}) {1}", exitCode, output.Arguments) }
                            .Concat(output.StandardErrorLines)
                            );
                    } catch (IOException) {
                    } catch (ArgumentException) {
                    } catch (SecurityException) {
                    } catch (UnauthorizedAccessException) {
                    }
                }

                if (evt != null)
                {
                    evt(exitCode);
                }
                return(exitCode);
            }
        }
        protected virtual void GenerateDatabase(PythonTypeDatabaseCreationRequest request, Action<int> onExit = null) {
            WatchingLibrary = false;
            _generating = true;

            PythonTypeDatabase.GenerateAsync(request).ContinueWith(t => {
                int exitCode;
                try {
                    exitCode = t.Result;
                } catch (Exception ex) {
                    Debug.Fail(ex.ToString());
                    exitCode = PythonTypeDatabase.InvalidOperationExitCode;
                }

                if (exitCode != PythonTypeDatabase.AlreadyGeneratingExitCode) {
                    _generating = false;
                }
                if (onExit != null) {
                    onExit(exitCode);
                }
            });
        }
        public virtual void GenerateDatabase(GenerateDatabaseOptions options, Action<int> onExit = null) {
            var req = new PythonTypeDatabaseCreationRequest {
                Factory = this,
                OutputPath = DatabasePath,
                SkipUnchanged = options.HasFlag(GenerateDatabaseOptions.SkipUnchanged)
            };

            GenerateDatabase(req, onExit);
        }