Ejemplo n.º 1
0
        public IContentResponse GetResponse(string method, string rawUrl, System.Collections.Specialized.NameValueCollection headers, System.IO.Stream inputStream)
        {
            string        pageText   = null;
            StringBuilder searchText = new StringBuilder();

            string[] args = rawUrl.Substring(_urlPrefix.Length).TrimStart('?').Split('#')[0].Split('&');
            foreach (string arg in args)
            {
                if (arg.StartsWith("page="))
                {
                    pageText = arg.Substring(5);
                }
                else
                {
                    searchText.AppendFormat("{0} ", Uri.UnescapeDataString(arg.Substring(arg.IndexOf('=') + 1)).Replace('+', ' '));
                }
            }

            int page;

            if (pageText == null || !int.TryParse(pageText, out page))
            {
                page = 1;
            }

            string query = searchText.ToString().Trim();

            if (_template == null || !Object.ReferenceEquals(_templateReadFrom, _content.Storage))
            {
                _templateReadFrom = _content.Storage;
                _template         = new SearchTemplate(_content.Storage);
            }

            return(new DynamicResponse(_template.RenderResults(query, page)));
        }
Ejemplo n.º 2
0
        public ActionResult HomePartial(SearchTemplate model, string name)
        {
            List <CourseDTO> course = new List <CourseDTO>();

            if (!string.IsNullOrEmpty(name))
            {
                course = cs.CourseInfo().Where(c => c.Subject.SubjectName == name).ToList();
            }
            else
            if (string.IsNullOrEmpty(model.Search))
            {
                course = cs.SortCourse(model.SelectedFilter).ToList();
            }
            else
            {
                course = cs.SortCourse(model.SelectedFilter, model.Search).ToList();
            }
            var cvm = course.Select(d => new CourseViewModel(
                                        d.CourseName,
                                        $"{d.Teacher.TutorName}",
                                        d.Teacher.TutorID,
                                        d.Group.Where(b => b.IsBlocked == false).Select(s => $"{s.StudentName}"),
                                        d.BeginDate,
                                        d.EndDate,
                                        null,
                                        d.Description
                                        )).ToList();

            return(PartialView(cvm));
        }
Ejemplo n.º 3
0
        private void OnSearchTemplatePropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (string.Equals(e.PropertyName, "RegularExpression"))
            {
                return;
            }

            SearchTemplate.RegularExpression = SearchTemplate.IsEmpty() ? string.Empty : _regexService.ConvertToRegex(SearchTemplate.TemplateString, SearchTemplate.MatchCase, SearchTemplate.MatchWholeWord);
        }
Ejemplo n.º 4
0
        public async Task <Response> MonitorQueryAsync()
        {
            IResponse <SimpleQueryResult <Acoes.Domain.Entities.Brasil.Processo> >    queryResultBrazil    = new Response <SimpleQueryResult <Acoes.Domain.Entities.Brasil.Processo> >();
            IResponse <SimpleQueryResult <Acoes.Domain.Entities.Chile.Processo> >     queryResultChile     = new Response <SimpleQueryResult <Acoes.Domain.Entities.Chile.Processo> >();
            IResponse <SimpleQueryResult <Acoes.Domain.Entities.Argentina.Processo> > queryResultArgentina = new Response <SimpleQueryResult <Acoes.Domain.Entities.Argentina.Processo> >();

            // 1 - Retorna todas as pesquisas monitoradas
            var pesquisasMonitoradas = await queryRepository.SearchMonitoredByUserAsync();

            foreach (UserSimpleQuery pesquisa in pesquisasMonitoradas)
            {
                IResponse <User> userContent = await usuarioAcoesService.SearchByIdAsync(pesquisa.UserId);

                SearchTemplate template = userContent.Content.SearchTemplates.SingleOrDefault(e => e.SearchTemplateId == pesquisa.SearchTemplateId);

                // 2 - Verifica o histórico de monitoramentos da pesquisa atual
                List <Monitoring> historicoMonitoramentos = await monitoringRepository.SearchMonitoringByQueryAsync(pesquisa.QueryId);

                Monitoring monitoramentoAtual = new Monitoring();

                // Realiza nova pesquisa com os mesmos parâmetros
                switch (pesquisa.SearchTemplateId)
                {
                case 1:     // Brasil
                    queryResultBrazil = await brAcoesService.ConsultarProcessoAsync(pesquisa, userContent.Content, template);

                    monitoramentoAtual.QuantityNewProcesses = queryResultBrazil.Content.Total - pesquisa.TotalResult;
                    break;

                case 2:     // Chile
                    queryResultChile = await chAcoesService.ConsultarProcessoAsync(pesquisa, userContent.Content, template);

                    monitoramentoAtual.QuantityNewProcesses = queryResultChile.Content.Total - pesquisa.TotalResult;
                    break;

                case 3:     // Argentina
                    queryResultArgentina = await agAcoesService.ConsultarProcessoAsync(pesquisa, userContent.Content, template);

                    monitoramentoAtual.QuantityNewProcesses = queryResultArgentina.Content.Total - pesquisa.TotalResult;
                    break;

                default:
                    break;
                }

                // Cadastra o monitoramentos na base de dados
                monitoramentoAtual.StatusId = 2;
                monitoramentoAtual.QueryId  = pesquisa.QueryId;

                await monitoringRepository.InsertAsync(monitoramentoAtual);
            }

            return(Response.CreateResponse());
        }
Ejemplo n.º 5
0
 public void HtmlSearch(
     [Argument("site", "s", Description = "The root http address of the website copy.")]
     string site,
     [Argument("term", "t", Description = "The expression to search for, see http://lucene.apache.org/java/2_4_0/queryparsersyntax.html.")]
     string term,
     [Argument("page", "p", DefaultValue = 1, Description = "The result page to return.")]
     int page)
 {
     using (ContentStorage store = new ContentStorage(StoragePath(site), true))
     {
         SearchTemplate template = new SearchTemplate(store);
         string         tmp      = template.RenderResults(term, page);
         Console.WriteLine(tmp);
     }
 }
Ejemplo n.º 6
0
        protected override async Task <ApiResponse> InternalExecuteAsync(object request)
        {
            var jo = JsonObject.Parse(RequestBody());

            if (request != null)
            {
                jo
                .Remove(SearchTemplate.ID)
                .Add(SearchTemplate.ID, request.ToString());
            }

            var template = new SearchTemplate(jo);
            var response = await ApiSearchTemplateModules.Repository.SaveTemplateAsync(template);

            return(new ApiResponse(response.ToString(), (HttpStatusCode)(int)response.StatusCode));
        }
Ejemplo n.º 7
0
        public ActionResult HomePage()
        {
            SearchTemplate st = new SearchTemplate(sbs.SubjectInfo().Select(s => new SubjectViewModel(
                                                                                s.SubjectName,
                                                                                s.SubjectLogo,
                                                                                s.Courses.Select(c => c.CourseName).ToList()
                                                                                )).ToList(),
                                                   cs.CourseInfo().Select(d => new CourseViewModel(
                                                                              d.CourseName,
                                                                              $"{d.Teacher.TutorName}",
                                                                              d.Teacher.TutorID,
                                                                              d.Group.Where(b => b.IsBlocked == false).Select(s => $"{s.StudentName}"),
                                                                              d.BeginDate,
                                                                              d.EndDate,
                                                                              null,
                                                                              d.Description
                                                                              )).ToList()
                                                   );

            return(View(st));
        }
Ejemplo n.º 8
0
        public static MvcHtmlString AddFilter <TModel, TProperty>(this HtmlHelper <TModel> helper, string partialName, TProperty filterModel)
        {
            if (!ReferenceEquals(helper, null))
            {
                SearchTemplate filter = new SearchTemplate();
                filter.GuidID = Guid.NewGuid().ToString();
                filter.FormID = helper.ViewContext.FormContext.FormId;

                string             searchTemplate = helper.Partial("_SearchTemplate", filter).ToHtmlString();
                ViewDataDictionary viewData       = new ViewDataDictionary(helper.ViewData);
                viewData.TemplateInfo = new TemplateInfo()
                {
                    HtmlFieldPrefix = String.Format("{0}Bag", filterModel.GetType().Name)
                };

                string modelTemplate = helper.Partial(partialName, filterModel, viewData).ToHtmlString();

                searchTemplate = String.Format(searchTemplate, modelTemplate);

                return(MvcHtmlString.Create(searchTemplate));
            }
            return(MvcHtmlString.Empty);
        }
Ejemplo n.º 9
0
        private async Task <SearchRequest> GetSearchRequest(JsonObject jo)
        {
            if (jo == null || jo.IsEmpty)
            {
                return(new SearchRequest());
            }

            JsonObject temp = new JsonObject();
            IDictionary <string, object> parameters = null;
            SearchTemplate template = null;

            foreach (var jp in jo.Properties())
            {
                switch (jp.Name.ToLower())
                {
                case "params":
                case "parameters":
                    parameters = jp.Value.Get <JsonObject>().ToDictionary();
                    break;

                case "template":
                    if (jp.Value.Type == JsonType.String)
                    {
                        template = await ApiSearchTemplateModules.Repository.GetTemplateAsync(jp.Value.Get <string>());
                    }
                    else if (jp.Value.Type == JsonType.Object)
                    {
                        template = new SearchTemplate(jp.Value.Get <JsonObject>());
                    }
                    break;

                case "template_id":
                    template = await ApiSearchTemplateModules.Repository.GetTemplateAsync(jp.Value.Get <string>());

                    break;

                default:
                    temp.Add(jp);
                    break;
                }
            }

            if (template == null)
            {
                if (parameters == null)
                {
                    return(new SearchRequest(temp));
                }
                else
                {
                    return(new SearchRequest(temp.SetParameters(parameters)));
                }
            }
            else
            {
                if (parameters == null)
                {
                    parameters = temp.ToDictionary();
                }
                return(template.GetSearchRequest(parameters));
            }
        }
Ejemplo n.º 10
0
        public async Task Templates_must_be_transformed_to_correct_outputs()
        {
            //var temp = new Temp();
            //await temp.Test();

            var tests = JsonArray.Parse(File.ReadAllText("test_templates.json"))
                        .Select(e => e.Get <JsonObject>())
                        .ToArray();

            var es = new ElasticsearchClient();
            await es.DeleteIndexAsync("search_templates");

            var repo = new SearchTemplateRepository(CacheExpiration.Sliding(60 * 1000));

            foreach (var test in tests)
            {
                var    template = new SearchTemplate(test.Property <JsonObject>("template"));
                string id       = template.Id;

                var idr = await repo.SaveTemplateAsync(template, true);

                Assert.IsTrue(idr.IsSuccess);

                template = await repo.GetTemplateAsync(id);

                Assert.IsTrue(template.Id == id);

                var sr = await repo.SearchTemplatesAsync("q=id:" + id);

                Assert.IsTrue(sr.Hits.Total == 1);

                var ddr = await repo.DeleteTemplateAsync(id, true);

                Assert.IsTrue(ddr.IsSuccess);

                sr = await repo.SearchTemplatesAsync("q=id:" + id);

                Assert.IsTrue(sr.Hits.Total == 0);

                idr = await repo.SaveTemplateAsync(template);

                Assert.IsTrue(idr.IsSuccess);

                template = await repo.GetTemplateAsync(id);

                Assert.IsTrue(template.Id == id);

                var parameters = test.Property <JsonObject>("params").ToDictionary();
                var output     = test.Property <JsonObject>("output");
                var search     = template.GetSearchRequest(parameters);
                var jo         = search.ToJson();

                if (jo == null || jo.IsEmpty)
                {
                    Assert.IsTrue(output == null || output.IsEmpty);
                }
                else
                {
                    Assert.IsTrue(search.Index.Length > 0);
                    Assert.IsFalse(search.Index.StartsWith("$"));
                    Assert.IsTrue(jo.ToString(false) == output.ToString(false));
                }
            }

            repo = new SearchTemplateRepository(CacheExpiration.Sliding(1000));
            foreach (var test in tests.Take(1))
            {
                var    jo       = test.Property <JsonObject>("template");
                var    template = new SearchTemplate(jo);
                string id       = template.Id;
                string name     = template.Name;

                var idr = await repo.SaveTemplateAsync(template, true);

                Assert.IsTrue(idr.IsSuccess);

                template = await repo.GetTemplateAsync(id);

                Assert.IsTrue(template.Id == id);
                Assert.IsTrue(template.Name == name);

                string @new = name + "-updated";
                jo.Remove("name").Add("name", @new);
                template = new SearchTemplate(jo);
                idr      = await repo.SaveTemplateAsync(template, true);

                Assert.IsTrue(idr.IsSuccess);

                Thread.Sleep(1010);

                template = await repo.GetTemplateAsync(id);

                Assert.IsTrue(template.Id == id);
                Assert.IsTrue(template.Name == @new);
            }
        }