public static InsolvenceSearchResult SimpleSearch(InsolvenceSearchResult search, bool withHighlighting = false)
        {
            var client = Manager.GetESClient_Insolvence();
            var page   = search.Page - 1 < 0 ? 0 : search.Page - 1;

            var sw = new StopWatchEx();

            sw.Start();

            search.Q = SearchTools.FixInvalidQuery(search.Q ?? "", queryShorcuts, queryOperators);


            ISearchResponse <Rizeni> res = null;

            try
            {
                res = client
                      .Search <Rizeni>(s => s
                                       .Size(search.PageSize)
                                       .ExpandWildcards(Elasticsearch.Net.ExpandWildcards.All)
                                       .From(page * search.PageSize)
                                       .Source(sr => sr.Excludes(r => r.Fields("dokumenty.plainText")))
                                       .Query(q => GetSimpleQuery(search))
                                       .Sort(ss => new SortDescriptor <Rizeni>().Field(m => m.Field(f => f.PosledniZmena).Descending()))
                                       .Highlight(h => Lib.ES.SearchTools.GetHighlight <Rizeni>(withHighlighting))
                                       );
            }
            catch (Exception e)
            {
                if (res != null && res.ServerError != null)
                {
                    Manager.LogQueryError <Rizeni>(res, "Exception, Orig query:"
                                                   + search.OrigQuery + "   query:"
                                                   + search.Q
                                                   + "\n\n res:" + search.Result.ToString()
                                                   , ex: e);
                }
                else
                {
                    HlidacStatu.Util.Consts.Logger.Error("", e);
                }
                throw;
            }
            sw.Stop();

            if (res.IsValid == false)
            {
                Manager.LogQueryError <Rizeni>(res, "Exception, Orig query:"
                                               + search.OrigQuery + "   query:"
                                               + search.Q
                                               + "\n\n res:" + search.Result?.ToString()
                                               );
            }

            search.Total          = res?.Total ?? 0;
            search.IsValid        = res?.IsValid ?? false;
            search.ElasticResults = res;
            search.ElapsedTime    = sw.Elapsed;
            return(search);
        }
示例#2
0
        /// <summary>
        /// Get content of page in defined charset
        /// </summary>
        /// <param name="charset"></param>
        /// <returns></returns>
        public virtual TextContentResult GetContent(Encoding encoding)
        {
            StopWatchEx stopwatch = new StopWatchEx();

            stopwatch.Start();

            string content = FillContent(this.Url, encoding);

            stopwatch.Stop();
            this.ProcessTime = stopwatch.Elapsed;

            CookieCollection cookies = new CookieCollection();

            if (this.ResponseParams != null && this.ResponseParams.Cookies != null)
            {
                cookies.Add(this.ResponseParams.Cookies);
            }
            else
            {
                cookies = null;
            }

            WebHeaderCollection headers = new WebHeaderCollection();

            if (this.ResponseParams != null && this.ResponseParams.Headers != null)
            {
                headers.Add(this.ResponseParams.Headers);
            }
            else
            {
                headers = null;
            }
            return(new TextContentResult()
            {
                Text = content,
                Context = new UrlContentContext()
                {
                    Cookies = cookies,
                    Headers = headers,
                    Url = this.Url,
                    Referer = this.Referer
                }
            });
        }
        public DotaceSearchResult SimpleSearch(DotaceSearchResult search,
                                               bool withHighlighting = false,
                                               AggregationContainerDescriptor <Dotace> anyAggregation = null)
        {
            var page = search.Page - 1 < 0 ? 0 : search.Page - 1;

            var sw = new StopWatchEx();

            sw.Start();
            search.OrigQuery = search.Q;
            search.Q         = Lib.Searching.Tools.FixInvalidQuery(search.Q ?? "", queryShorcuts(), queryOperators);

            ISearchResponse <Dotace> res = null;

            try
            {
                res = _esClient
                      .Search <Dotace>(s => s
                                       .Size(search.PageSize)
                                       .ExpandWildcards(Elasticsearch.Net.ExpandWildcards.All)
                                       .From(page * search.PageSize)
                                       .Query(q => GetSimpleQuery(search))
                                       .Sort(ss => GetSort(search.Order))
                                       .Highlight(h => Lib.Searching.Tools.GetHighlight <Dotace>(withHighlighting))
                                       .Aggregations(aggr => anyAggregation)
                                       .TrackTotalHits((search.ExactNumOfResults || page * search.PageSize == 0) ? true : (bool?)null)
                                       );
                if (res.IsValid && withHighlighting && res.Shards.Failed > 0) //if some error, do it again without highlighting
                {
                    res = _esClient
                          .Search <Dotace>(s => s
                                           .Size(search.PageSize)
                                           .ExpandWildcards(Elasticsearch.Net.ExpandWildcards.All)
                                           .From(page * search.PageSize)
                                           .Query(q => GetSimpleQuery(search))
                                           .Sort(ss => GetSort(search.Order))
                                           .Highlight(h => Lib.Searching.Tools.GetHighlight <Dotace>(false))
                                           .Aggregations(aggr => anyAggregation)
                                           .TrackTotalHits(search.ExactNumOfResults || page * search.PageSize == 0 ? true : (bool?)null)
                                           );
                }
            }
            catch (Exception e)
            {
                Audit.Add(Audit.Operations.Search, "", "", "Dotace", "error", search.Q, null);
                if (res != null && res.ServerError != null)
                {
                    ES.Manager.LogQueryError <Dotace>(res, "Exception, Orig query:"
                                                      + search.OrigQuery + "   query:"
                                                      + search.Q
                                                      + "\n\n res:" + search.ElasticResults.ToString()
                                                      , ex: e);
                }
                else
                {
                    HlidacStatu.Util.Consts.Logger.Error("", e);
                }
                throw;
            }
            sw.Stop();

            Audit.Add(Audit.Operations.Search, "", "", "Dotace", res.IsValid ? "valid" : "invalid", search.Q, null);

            if (res.IsValid == false)
            {
                ES.Manager.LogQueryError <Dotace>(res, "Exception, Orig query:"
                                                  + search.OrigQuery + "   query:"
                                                  + search.Q
                                                  + "\n\n res:" + search.ElasticResults?.ToString()
                                                  );
            }

            search.Total          = res?.Total ?? 0;
            search.IsValid        = res?.IsValid ?? false;
            search.ElasticResults = res;
            search.ElapsedTime    = sw.Elapsed;
            return(search);
        }
示例#4
0
        public static InsolvenceSearchResult SimpleSearch(InsolvenceSearchResult search,
                                                          bool withHighlighting = false,
                                                          AggregationContainerDescriptor <Lib.Data.Insolvence.Rizeni> anyAggregation = null, bool exactNumOfResults = false)
        {
            var client = Manager.GetESClient_Insolvence();
            var page   = search.Page - 1 < 0 ? 0 : search.Page - 1;

            var sw = new StopWatchEx();

            sw.Start();
            search.OrigQuery = search.Q;
            search.Q         = Lib.Searching.Tools.FixInvalidQuery(search.Q ?? "", queryShorcuts, queryOperators);
            var sq = GetSimpleQuery(search);

            ISearchResponse <Rizeni> res = null;

            try
            {
                res = client
                      .Search <Rizeni>(s => s
                                       .Size(search.PageSize)
                                       .ExpandWildcards(Elasticsearch.Net.ExpandWildcards.All)
                                       .From(page * search.PageSize)
                                       .Source(sr => sr.Excludes(r => r.Fields("dokumenty.plainText")))
                                       .Query(q => sq)
                                       //.Sort(ss => new SortDescriptor<Rizeni>().Field(m => m.Field(f => f.PosledniZmena).Descending()))
                                       .Sort(ss => GetSort(Convert.ToInt32(search.Order)))
                                       .Highlight(h => Lib.Searching.Tools.GetHighlight <Rizeni>(withHighlighting))
                                       .Aggregations(aggr => anyAggregation)
                                       .TrackTotalHits(search.ExactNumOfResults ? true : (bool?)null)
                                       );
                if (withHighlighting && res.Shards != null && res.Shards.Failed > 0) //if some error, do it again without highlighting
                {
                    res = client
                          .Search <Rizeni>(s => s
                                           .Size(search.PageSize)
                                           .ExpandWildcards(Elasticsearch.Net.ExpandWildcards.All)
                                           .From(page * search.PageSize)
                                           .Source(sr => sr.Excludes(r => r.Fields("dokumenty.plainText")))
                                           .Query(q => sq)
                                           //.Sort(ss => new SortDescriptor<Rizeni>().Field(m => m.Field(f => f.PosledniZmena).Descending()))
                                           .Sort(ss => GetSort(Convert.ToInt32(search.Order)))
                                           .Highlight(h => Lib.Searching.Tools.GetHighlight <Rizeni>(false))
                                           .Aggregations(aggr => anyAggregation)
                                           .TrackTotalHits(search.ExactNumOfResults ? true : (bool?)null)
                                           );
                }
            }
            catch (Exception e)
            {
                Audit.Add(Audit.Operations.Search, "", "", "Insolvence", "error", search.Q, null);
                if (res != null && res.ServerError != null)
                {
                    Manager.LogQueryError <Rizeni>(res, "Exception, Orig query:"
                                                   + search.OrigQuery + "   query:"
                                                   + search.Q
                                                   + "\n\n res:" + search.Result.ToString()
                                                   , ex: e);
                }
                else
                {
                    HlidacStatu.Util.Consts.Logger.Error("", e);
                }
                throw;
            }
            sw.Stop();
            Audit.Add(Audit.Operations.Search, "", "", "Insolvence", res.IsValid ? "valid" : "invalid", search.Q, null);

            if (res.IsValid == false)
            {
                Manager.LogQueryError <Rizeni>(res, "Exception, Orig query:"
                                               + search.OrigQuery + "   query:"
                                               + search.Q
                                               + "\n\n res:" + search.Result?.ToString()
                                               );
            }

            search.Total          = res?.Total ?? 0;
            search.IsValid        = res?.IsValid ?? false;
            search.ElasticResults = res;
            search.ElapsedTime    = sw.Elapsed;
            return(search);
        }
示例#5
0
        public virtual BinaryContentResult GetBinary()
        {
            StopWatchEx stopwatch = new StopWatchEx();

            stopwatch.Start();
            byte[] data = null;
            try
            {
                data = GetRawContent(this.Url);
            }
            catch (UrlContentException ex)
            {
                if (this.IgnoreHttpErrors && ex.DownloadedContent != null)
                {
                    return(new BinaryContentResult()
                    {
                        Binary = ex.DownloadedContent,
                        Context = new UrlContentContext()
                        {
                            Url = this.Url,
                        }
                    });
                }
                else
                {
                    throw;
                }
            }
            stopwatch.Stop();
            this.ProcessTime = stopwatch.Elapsed;

            CookieCollection cookies = new CookieCollection();

            if (this.ResponseParams != null && this.ResponseParams.Cookies != null)
            {
                cookies.Add(this.ResponseParams.Cookies);
            }
            else
            {
                cookies = null;
            }

            WebHeaderCollection headers = new WebHeaderCollection();

            if (this.ResponseParams != null && this.ResponseParams.Headers != null)
            {
                headers.Add(this.ResponseParams.Headers);
            }
            else
            {
                headers = null;
            }
            return(new BinaryContentResult()
            {
                Binary = data,
                Context = new UrlContentContext()
                {
                    Cookies = cookies,
                    Headers = headers,
                    Url = this.Url,
                    Referer = this.Referer
                }
            });
        }
示例#6
0
        private Lib.Data.Logs.ProfilZadavateleDownload _processReqProfiluZadavatel(VZ.ProfilZadavatele profil, DateTime from, DateTime to)
        {
            string xmlUrlTemp = profil.Url;

            if (profil.Url?.EndsWith("/") == true)
            {
                xmlUrlTemp = xmlUrlTemp + "XMLdataVZ?od={0:ddMMyyy}&do={1:ddMMyyyy}";
            }
            else
            {
                xmlUrlTemp = xmlUrlTemp + "/XMLdataVZ?od={0:ddMMyyy}&do={1:ddMMyyyy}";
            }


            var xml = "";

            Devmasters.Core.StopWatchEx sw = new StopWatchEx();
            sw.Start();
            var surl   = string.Format(xmlUrlTemp, from, to);
            var ReqLog = new Lib.Data.Logs.ProfilZadavateleDownload()
            {
                Date = DateTime.Now, ProfileId = profil.Id, RequestedUrl = surl
            };

            try
            {
                sem.WaitOne();
                using (Devmasters.Net.Web.URLContent net = new Devmasters.Net.Web.URLContent(surl))
                {
                    //net.TimeInMsBetweenTries = 20*1000;
                    //net.Tries = 1;
                    net.Timeout      = 60 * 1000;
                    xml              = net.GetContent().Text;
                    ReqLog.HttpValid = true;
                }
            }
            catch (Devmasters.Net.Web.UrlContentException ex)
            {
                ReqLog.HttpValid = false;
                ReqLog.HttpError = ex.ToString();

                if (ex.InnerException != null && ex.InnerException.GetType() == typeof(System.Net.WebException))
                {
                    var wex = (System.Net.WebException)ex.InnerException;
                    ReqLog.HttpError = wex.ToString();
                    if (wex.Status == WebExceptionStatus.ProtocolError && wex.Response != null)
                    {
                        ReqLog.HttpErrorCode = (int)(((HttpWebResponse)wex.Response).StatusCode);
                    }
                }
                ReqLog.Save();
                profil.LastAccessResult = VZ.ProfilZadavatele.LastAccessResults.HttpError;
                profil.LastAccess       = DateTime.Now;
                profil.Save();
                return(ReqLog);
            }
            catch (System.Net.WebException wex)
            {
                ReqLog.HttpValid = false;
                ReqLog.HttpError = wex.ToString();
                if (wex.Status == WebExceptionStatus.ProtocolError && wex.Response != null)
                {
                    ReqLog.HttpErrorCode = (int)(((HttpWebResponse)wex.Response).StatusCode);
                }
                ReqLog.Save();
                profil.LastAccessResult = VZ.ProfilZadavatele.LastAccessResults.HttpError;
                profil.LastAccess       = DateTime.Now;
                profil.Save();
                return(ReqLog);
            }
            catch (Exception e)
            {
                ReqLog.HttpValid = false;
                ReqLog.HttpError = e.ToString();
                ReqLog.Save();
                profil.LastAccessResult = VZ.ProfilZadavatele.LastAccessResults.HttpError;
                profil.LastAccess       = DateTime.Now;
                profil.Save();
                return(ReqLog);
            }
            finally
            {
                sem.Release();
                sw.Stop();
                ReqLog.ResponseMs = sw.ElapsedMilliseconds;
            }


            Lib.Data.External.ProfilZadavatelu.ProfilStructure prof = null;
            try
            {
                prof            = ParserXml(xml);
                ReqLog.XmlValid = true;
            }
            catch (Exception e)
            {
                ReqLog.XmlValid          = false;
                ReqLog.XmlError          = e.ToString();
                ReqLog.XmlInvalidContent = xml;
                ReqLog.Save();

                profil.LastAccessResult = VZ.ProfilZadavatele.LastAccessResults.XmlError;
                profil.LastAccess       = DateTime.Now;
                profil.Save();
                return(ReqLog);
            }
            if (prof != null)
            {
                var cli = Lib.ES.Manager.GetESClient_VerejneZakazkyNaProfiluRaw();

                foreach (var zak in prof.zakazka)
                {
                    Lib.Data.External.ProfilZadavatelu.ZakazkaRaw myZak = new Lib.Data.External.ProfilZadavatelu.ZakazkaRaw(zak, profil);
                    myZak.Save();
                }
                ReqLog.Save();
                profil.LastAccessResult = VZ.ProfilZadavatele.LastAccessResults.OK;
                profil.LastAccess       = DateTime.Now;
                profil.Save();
            }
            return(ReqLog);
        }