Ejemplo n.º 1
0
        /// <summary>
        /// Executes the planning task and writes the result.
        /// </summary>
        public void Execute()
        {
            Planner.Search.IHeuristicSearch searchEngine = GetHeuristicSearch();
            searchEngine.Start();

            Planner.Search.SearchResults results = searchEngine.GetSearchResults();
            ProcessResults(results);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the results of search.
        /// </summary>
        /// <param name="results">Search results.</param>
        private void ProcessResults(Planner.Search.SearchResults results)
        {
            if (OutputType == OutputType.Unspecified)
            {
                OutputType = ResultsProcessor != null ? OutputType.CustomResultsProcessor : OutputType.ToConsole;
            }

            switch (OutputType)
            {
            case OutputType.CustomResultsProcessor:
            {
                ResultsProcessor?.Invoke(results);
                break;
            }

            case OutputType.ToConsole:
            {
                string taskOutput = results.GetFullDescription();
                lock (OutputMutex)
                {
                    Console.WriteLine(taskOutput);
                }
                break;
            }

            case OutputType.ToFile:
            {
                if (System.IO.File.Exists(OutputFile))
                {
                    System.IO.File.Delete(OutputFile);
                }

                string taskOutput = results.GetFullDescription();
                using (var writer = System.IO.File.CreateText(OutputFile))
                {
                    writer.Write(taskOutput);
                }
                break;
            }

            case OutputType.Unspecified:
            {
                throw new InvalidOperationException("Unspecified output type!");
            }

            default:
            {
                throw new NotImplementedException("Unknown output type!");
            }
            }
        }