public void PrintShortInfo(SearchResultLine selectedLine)
        {
            var startTime = selectedLine.StartTime.Text;
            var priceRu   = selectedLine.Price.Text;

            CurrencySelect.SelectItemByName("$ доллары");
            var priseEn = selectedLine.Price.Text;

            Console.Write($"Данные о рейсе:\n" +
                          $"Время отправления - {startTime}\n" +
                          $"Цена в рублях - {priceRu}\n" +
                          $"Цена в долларах - {priseEn}");
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userSessionId"></param>
        /// <param name="searchText"></param>
        /// <returns></returns>
        /// <remarks>
        /// I should update parameter for GetSessionDetailByUserSessionId to be a string and decouple dependency from MongoDb ObjectId Model
        /// I should also create my own "OcrResult" to decouple dependency from Microsoft Azure Models
        /// </remarks>
        public async Task <SearchResultsDto> SearchUserSession(string userSessionId, string searchText)
        {
            var result = new SearchResultsDto();
            var sessionDetailsFound = await _sessionDetailRepo.GetSessionDetailByUserSessionId(ObjectId.Parse(userSessionId)).ConfigureAwait(false);

            //var rawText = String.Empty;
            try
            {
                var detail  = sessionDetailsFound.PrintedTextResult;
                var regions = detail.Regions;
                foreach (OcrRegion region in regions)
                {
                    var lines = region.Lines;
                    foreach (OcrLine line in lines)
                    {
                        var words = line.Words;
                        foreach (OcrWord word in words)
                        {
                            if (word.Text.ToLower().Contains(searchText.ToLower())) //Searh for match
                            {
                                //find how many regions to exclude
                                var regionFoundIndex = regions.IndexOf(region);
                                var skipLastCount    = regions.Count - regionFoundIndex;
                                if (skipLastCount < 0)
                                {
                                    skipLastCount = 0;
                                }
                                //find haw many lines of text there are to find the word
                                var reg = regions.SkipLast(skipLastCount);
                                var linesInPriorRegions = 0;
                                if (reg.Any())
                                {
                                    linesInPriorRegions = reg.Sum(x => x.Lines.Count());
                                }
                                var lineNumber = linesInPriorRegions + region.Lines.IndexOf(line) + 1;

                                //find how many words to exclude
                                var wordsFoundIndex   = words.IndexOf(word);
                                var skipLastWordCount = words.Count - wordsFoundIndex;
                                if (skipLastWordCount < 0)
                                {
                                    skipLastWordCount = 0;
                                }
                                //find how many characters to find the word in the line
                                var filteredWords    = words.SkipLast(skipLastWordCount);
                                var charInPriorWords = 0;
                                if (filteredWords.Any())
                                {
                                    charInPriorWords = filteredWords.Sum(w => w.Text.Length);
                                }
                                var intPosition = charInPriorWords + filteredWords.Count(); //count number of words and spaces. will not include special characters.

                                //Map from Ocr classes to custom classes (to reduce dependency on Ocr classes
                                var resultText = new SearchResultText()
                                {
                                    BoundingBox = word.BoundingBox,
                                    Text        = word.Text
                                };

                                var resultLine = new SearchResultLine()
                                {
                                    BoundingBox = line.BoundingBox,
                                    Text        = words.Select(w => new SearchResultText()
                                    {
                                        BoundingBox = w.BoundingBox, Text = w.Text
                                    }).ToList()
                                };

                                var resultRegion = new SearchResultRegion()
                                {
                                    BoundingBox = region.BoundingBox,
                                    Lines       = new List <SearchResultLine>()
                                    {
                                        resultLine
                                    }
                                };

                                var resultDetail = new SearchResultDetail()
                                {
                                    Language    = detail.Language,
                                    TextAngle   = detail.TextAngle,
                                    Orientation = detail.Orientation,
                                    Regions     = new List <SearchResultRegion>()
                                    {
                                        resultRegion
                                    }
                                };

                                //build result details
                                var resultDetails = new SearchResultDetails(resultText, resultLine, resultRegion, resultDetail, lineNumber, intPosition);

                                //add to results
                                result.ResultDetails.Add(resultDetails);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (sessionDetailsFound != null)
                {
                    sessionDetailsFound = null;
                }
            }

            return(result);
        }