Exemple #1
0
        public async Task <IHttpActionResult> Get(long id1, long id2)
        {
            var sw       = Stopwatch.StartNew();
            var analyzer = AnalyzerFactory.GetAnalyzer();

            try
            {
                var paths = await analyzer.FindPathsAsync(id1, id2);

                // 返回只要 Id 就可以了。
                // 由于结构比较简单,所以可以强行 json 。
                var resultBuilder = new StringBuilder("[");
                var isFirst       = true;
                foreach (var path in paths)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        resultBuilder.Append(",\n");
                    }
                    resultBuilder.Append("[");
                    for (int j = 0; j < path.Length; j++)
                    {
                        if (j > 0)
                        {
                            resultBuilder.Append(",");
                        }
                        resultBuilder.Append(path[j].Id);
                    }
                    resultBuilder.Append("]");
                }
                resultBuilder.Append("]");
                var resp = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(resultBuilder.ToString(), null, Utility.JsonMediaType)
                };
                AnalyzerFactory.PutAnalyzer(analyzer);
                return(new ResponseMessageResult(resp));
            }
            finally
            {
                analyzer.LogStatistics();
                analyzer.SearchClient.LogStatistics();
                TimerLogger.TraceTimer("MagikController", sw);
            }
        }