Esempio n. 1
0
        internal QueryEditSession(IPreviousNextStack <string> alreadyEditedQueries)
        {
            Debug.Assert(alreadyEditedQueries != null);

            Console.CancelKeyPress += this.On_Ctrl_C_Pressed;

            m_AlreadyEditedQueries = alreadyEditedQueries;

            m_ConsoleWriter = new ConsoleWriter();

            m_UndoRedoStates = new PreviousNextStack <State>(
                new State[] {},
                State.DefaultState,
                (s1, s2) => !s1.IsDifferentThan(s2));

            m_KeyHandlers = new IKeyHandler[] {
                // Order of keyHandlers declaration matters!
                new KeyHandlerCtrl(m_UndoRedoStates),
                new KeyHandlerCursor(ConsoleWriter.AvailableWidth),
                new KeyHandlerChar(ConsoleWriter.AvailableWidth)
            };
        }
Esempio n. 2
0
        public void Run()
        {
            var analysisResult = ProjectAnalysisUtils.ChooseAnalysisResult();


            var codeBase = analysisResult.CodeBase;
            Func <string, IQueryCompiled> compileQueryProc = queryString => queryString.Compile(codeBase);

            // ... but if we can get a compareContext, then compile and execute the query against the compareContext
            ICompareContext compareContext;

            if (ProjectAnalysisUtils.TryGetCompareContextDefinedByBaseline(analysisResult, out compareContext))
            {
                Debug.Assert(compareContext != null);
                compileQueryProc = queryString => queryString.Compile(compareContext);
            }

            //
            // Fill queriesPreviouslyEdited with current project queries
            //
            IPreviousNextStack <string> queriesPreviouslyEdited = new PreviousNextStack <string>(
                analysisResult.AnalysisResultRef.Project.CodeQueries.CodeQueriesSet.AllQueriesRecursive.Reverse().Select(q => q.QueryString),
                "",
                (s1, s2) => s1 == s2);

            // With this line, make sure to begin with the first queries of the project.
            queriesPreviouslyEdited.GetPrevious();


            //
            // Loop for each query edition
            //
            while (true)
            {
                IQueryCompiled queryCompiled;
                using (var queryEditSession = new QueryEditSession(queriesPreviouslyEdited)) {
                    var queryString = queryEditSession.GetQueryString();
COMPILE_QUERY:
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ForegroundColor = ConsoleColor.White;
                    if (queryString == null)
                    {
                        break;
                    }

                    // Try compile query
                    queryCompiled = compileQueryProc(queryString);
                    var queryCompiledError = queryCompiled.QueryCompiledError;
                    if (queryCompiledError != null)
                    {
                        queryString = queryEditSession.ShowCompilatioErrorsAndThenGetQueryString(queryCompiledError);
                        goto COMPILE_QUERY;
                    }
                }

                // Execute query compiled
                var queryCompiledSuccess = queryCompiled.QueryCompiledSuccess;
                Debug.Assert(queryCompiledSuccess != null);
                var result = queryCompiledSuccess.Execute();
                if (result.Status != QueryExecutionStatus.Success)
                {
                    var exception = result.Exception;
                    // The error must be an Exception thrown by the query, since we don't use the Execute(...) overload with time-out!
                    Debug.Assert(exception != null);
                    DisplayQueryThrowAnException(exception);
                    continue;
                }

                QueryExecutionResultDisplayer.Go(result.SuccessResult);
                Console.WriteLine();
            }
        }