예제 #1
0
                                                   TimeSpan.FromDays(365 * 10)); //10 years

            private static byte[] getRawStemsFromServer(KeyAndId smlouvaKeyId)
            {
                Smlouva s = Smlouva.Load(smlouvaKeyId.ValueForData);

                if (s == null)
                {
                    return(null);
                }

                var settings = new JsonSerializerSettings();

                settings.ContractResolver = new HlidacStatu.Util.FirstCaseLowercaseContractResolver();

                string stemmerResponse = CallEndpoint("stemmer",
                                                      JsonConvert.SerializeObject(s, settings),
                                                      s.Id,
                                                      1000 * 60 * 30);

                try
                {
                    var jtoken = JToken.Parse(stemmerResponse);
                }
                catch (JsonReaderException e)
                {
                    Util.Consts.Logger.Error($"Stemmer returned incomplete json for {smlouvaKeyId.ValueForData}", e);
                    throw;
                }

                return(Encoding.UTF8.GetBytes(stemmerResponse));
            }
예제 #2
0
        private static byte[] GetBinaryDataFromUrl(KeyAndId ki)
        {
            byte[] data = null;

            try
            {
                using (Devmasters.Net.HttpClient.URLContent net = new Devmasters.Net.HttpClient.URLContent(ki.ValueForData))
                {
                    net.Timeout          = 7000;
                    net.IgnoreHttpErrors = true;
                    data = net.GetBinary().Binary;
                }
            }
            catch (Exception e)
            {
                HlidacStatu.Util.Consts.Logger.Error("Manager Save", e);
            }
            if (data == null || data.Length == 0)
            {
                return(System.IO.File.ReadAllBytes(HlidacStatu.Lib.Init.WebAppRoot + @"content\icons\largetile.png"));
            }
            else
            {
                return(data);
            }
        }
예제 #3
0
            public static void InvalidateStemCache(string smlouvaId)
            {
                var key = new KeyAndId()
                {
                    ValueForData = smlouvaId, CacheNameOnDisk = $"stem_smlouva_{smlouvaId}"
                };

                Util.Consts.Logger.Debug("Deleting stems cache for " + smlouvaId);

                stemCacheManager.Delete(key);
            }
                                                   TimeSpan.FromDays(365 * 10)); //10 years

            private static byte[] getRawStemsFromServer(KeyAndId smlouvaKeyId)
            {
                Smlouva s = Smlouva.Load(smlouvaKeyId.ValueForData);

                if (s == null)
                {
                    return(null);
                }

                var settings = new JsonSerializerSettings();

                settings.ContractResolver = new HlidacStatu.Util.FirstCaseLowercaseContractResolver();


                using (Devmasters.Net.Web.URLContent stem = new Devmasters.Net.Web.URLContent(classificationBaseUrl() + "/stemmer"))
                {
                    stem.Method = Devmasters.Net.Web.MethodEnum.POST;
                    stem.Tries  = 3;
                    stem.TimeInMsBetweenTries = 5000;
                    stem.Timeout     = 1000 * 60 * 30; //30min
                    stem.ContentType = "application/json; charset=utf-8";
                    stem.RequestParams.RawContent = Newtonsoft.Json.JsonConvert.SerializeObject(s, settings);
                    Devmasters.Net.Web.BinaryContentResult stems = null;
                    try
                    {
                        Util.Consts.Logger.Debug("Getting stems from " + stem.Url);

                        stems = stem.GetBinary();
                        return(stems.Binary);
                    }
                    catch (Exception e)
                    {
                        Util.Consts.Logger.Error("Classification Stemmer API error " + stem.Url, e);
                        throw;
                    }
                }
            }
예제 #5
0
            public static string GetRawStems(Smlouva s, bool rewriteStems = false)
            {
                if (s == null)
                {
                    return(null);
                }
                var key = new KeyAndId()
                {
                    ValueForData = s.Id, CacheNameOnDisk = $"stem_smlouva_{s.Id}"
                };

                if (rewriteStems)
                {
                    InvalidateStemCache(s.Id);
                }
                var data = stemCacheManager.Get(key);

                if (data == null)
                {
                    return(null);
                }

                return(System.Text.Encoding.UTF8.GetString(data));
            }