public void ProcessRequest(HttpContext context)
        {
            string url = context.Request.Path;

            context.Response.ContentType = "text/javascript";
            StringBuilder content = new StringBuilder(5000);

            string filepath    = context.Server.MapPath(url);
            object filecontent = CacheUtil.GetCache(url);

            if (filecontent == null || context.Request.Params["rc"] == "1" || Global.isCache == false)
            {
                filecontent = FileUtil.readFile(filepath);
                if (filecontent != null)
                {
                    CacheUtil.SetCache(url, filecontent);
                }
                else
                {
                    filecontent = $"console.log('{url} load error')";
                }
            }
            filecontent = filecontent.ToString().Replace("[localhostIp]", ip);
            context.Response.Write(filecontent.ToString());
            context.Response.Flush();
        }
示例#2
0
 public byte[] GetNecessaryFileData(string fileName)
 {
     using (var tryLock = new CacheLock())
     {
         if (CacheUtil.GetCache(fileName) != null)
         {
             return((byte[])CacheUtil.GetCache(fileName));
         }
         else
         {
             byte[] otaFile = context.NecessaryFile.FirstOrDefault(x => x.FileName == fileName).Data;
             CacheUtil.SetCache(fileName, otaFile);
             return(otaFile);
         }
     }
 }
        public void RemovePolicyFromCache(string renewalPolicyId)
        {
            var updateCache = new Action(() =>             // TODO: This all looks a bit messy (lots of conditional returns, etc)
            {
                if (string.IsNullOrEmpty(renewalPolicyId))
                {
                    return;
                }
                var cacheClient = CacheUtil.GetCache(Constants.ConsoleCacheKey);
                var cacheItem   = cacheClient.GetCacheItem(Constants.RenewalCacheKey);
                var policies    = cacheItem.Value as List <RenewalPolicyDetailed>;
                if (policies == null)
                {
                    return;
                }
                // TODO: Doesn't the simplified ReSharper Linq expression work ?
                // ReSharper disable SimplifyLinqExpression
                if (!policies.Any(p => p.PolicyId == renewalPolicyId))
                {
                    return;
                }
                // ReSharper restore SimplifyLinqExpression
                policies.Remove(policies.First(p => p.PolicyId == renewalPolicyId));
                cacheClient.Put(Constants.RenewalCacheKey, policies, cacheItem.Version,
                                DateTime.Today.AddDays(1).Date - DateTime.Now);
            });

            var retry = true;

            do
            {
                try
                {
                    updateCache();
                    retry = false;
                }
                catch (DataCacheException dataCacheException)
                {
                    if (dataCacheException.ErrorCode == DataCacheErrorCode.CacheItemVersionMismatch)
                    {
                        retry = true;
                        Thread.Sleep(100);
                    }
                }
            } while (retry);
        }
示例#4
0
        /// <summary>
        /// 获取数据,包含缓存(缓存有就取,没有就执行方法获取)
        /// </summary>
        /// <typeparam name="T">要获取的对象</typeparam>
        /// <param name="fn">缓存没有执行的方法</param>
        private T GetDataWithCache <T>(Func <T> fn, string key) where T : class
        {
            var cachekey  = KeyCenter.KeyStrPrefix + key;
            var cachedata = CacheUtil.GetCache(cachekey) as T;

            if (cachedata == null)
            {
                if (fn == null)
                {
                    return(null);
                }

                var fr = fn.Invoke().AsyncInsertCache(cachekey);
                return(fr);
            }

            return(cachedata);
        }
        public List <RenewalPolicyDetailed> GetRenewalPolicies(bool bypassCache)
        {
            var policies = CacheUtil.GetCache(Constants.ConsoleCacheKey)
                           .Get(Constants.RenewalCacheKey) as List <RenewalPolicyDetailed>;

            if (bypassCache || policies == null)
            {
                policies = new List <RenewalPolicyDetailed>();

                using (var conn = new SqlConnection(Properties.Settings.Default.SubscribeSQL))
                {
                    using (var cmd = new SqlCommand("rpt_RnwlMonitor", conn))
                    {
                        cmd.CommandTimeout = 240;
                        cmd.CommandType    = CommandType.StoredProcedure;

                        cmd.Parameters.Add("@ORIGOFF", SqlDbType.VarChar, 10).Value = "ALL";
                        cmd.Parameters.Add("@COB", SqlDbType.VarChar, 10).Value     = "ALL";
                        cmd.Parameters.Add("@IsBound", SqlDbType.Bit).Value         = 1;
                        cmd.Parameters.Add("@ExclDECLAR", SqlDbType.Bit).Value      = Properties.Settings.Default.RenewalExclDeclar;
                        cmd.Parameters.Add("@ExclNR", SqlDbType.Bit).Value          = 1;
                        cmd.Parameters.Add("@ExclRenBOUND", SqlDbType.Bit).Value    = 1;
                        cmd.Parameters.Add("@ExclRenNTU", SqlDbType.Bit).Value      = 1;
                        cmd.Parameters.Add("@ExclRenQuote", SqlDbType.Bit).Value    = 1;
                        cmd.Parameters.Add("@Bkr", SqlDbType.VarChar, 4).Value      = "";
                        cmd.Parameters.Add("@UserID", SqlDbType.VarChar, 255).Value = _currentHttpContext.CurrentUser.Identity.Name;
                        cmd.Parameters.Add("@FrDt", SqlDbType.DateTime).Value       = DateTime.Today.AddDays(-10);
                        cmd.Parameters.Add("@ToDt", SqlDbType.DateTime).Value       = DateTime.Today.AddDays(100);

                        conn.Open();

                        using (var r = cmd.ExecuteReader())
                        {
                            while (r.Read())
                            {
                                var detail = new RenewalPolicyDetailed();

                                Utility.SetObjectPropertyValue(detail, "COB", r, "COB");
                                Utility.SetObjectPropertyValue(detail, "OriginatingOffice", r, "ORIGOFF");
                                Utility.SetObjectPropertyValue(detail, "Underwriter", r, "UWR");
                                Utility.SetObjectPropertyValue(detail, "Leader", r, "Leader");
                                Utility.SetObjectPropertyValue(detail, "Broker", r, "Broker");
                                Utility.SetObjectPropertyValue(detail, "BrokerContact", r, "Contact");
                                Utility.SetObjectPropertyValue(detail, "PolicyId", r, "Expiring Ref");
                                Utility.SetObjectPropertyValue(detail, "UMR", r, "UMR");
                                Utility.SetObjectPropertyValue(detail, "InsuredName", r, "InsdNm");
                                Utility.SetObjectPropertyValue(detail, "Description", r, "Description");
                                Utility.SetObjectPropertyValue(detail, "InceptionDate", r, "Inception");
                                Utility.SetObjectPropertyValue(detail, "ExpiryDate", r, "Expiry");
                                Utility.SetObjectPropertyValue(detail, "St", r, "St");
                                Utility.SetObjectPropertyValue(detail, "Line", r, "Line");
                                Utility.SetObjectPropertyValue(detail, "Currency", r, "Ccy");
                                Utility.SetObjectPropertyValue(detail, "MarketGrossPremium", r, "MktGrPm");
                                Utility.SetObjectPropertyValue(detail, "SyndicateGrossPremium", r, "SynGrPm");
                                Utility.SetObjectPropertyValue(detail, "SyndicateNetPremium", r, "SynNetPm");
                                Utility.SetObjectPropertyValue(detail, "SignedPremium", r, "Signed Pm");
                                Utility.SetObjectPropertyValue(detail, "PercentageOfEPI", r, "% of EPI");
                                Utility.SetObjectPropertyValue(detail, "HasClaims", r, "Clm");
                                Utility.SetObjectPropertyValue(detail, "RenewalPosition", r, "Non-renewable");
                                Utility.SetObjectPropertyValue(detail, "RenewalNotes", r, "Renewal Note");
                                Utility.SetObjectPropertyValue(detail, "ToBroker", r, "ToBroker");
                                Utility.SetObjectPropertyValue(detail, "ToBrokerContact", r, "ToContact");
                                Utility.SetObjectPropertyValue(detail, "ToPolicyId", r, "ToPolId");
                                Utility.SetObjectPropertyValue(detail, "ToStatus", r, "ToSt");
                                Utility.SetObjectPropertyValue(detail, "ToSubmissionStatus", r, "ToSubmSt");
                                Utility.SetObjectPropertyValue(detail, "ToEntryStatus", r, "ToEntSt");

                                policies.Add(detail);
                            }
                        }
                    }
                }

                try
                {
                    CacheUtil.GetCache("Console")
                    .Put(Constants.RenewalCacheKey, policies, DateTime.Today.AddDays(1).Date - DateTime.Now);
                }
                catch (DataCacheException ex)
                {
                    this._logHandler.WriteLog(ex.ToString(), LogSeverity.Error, LogCategory.BusinessComponent);
                }
            }

            return(policies);
        }
示例#6
0
 /// <summary>
 /// Gets the permision.
 /// </summary>
 /// <returns></returns>
 public static string GetPermision()
 {
     return(CacheUtil.GetCache <string>("GLV_SYS_PERMISION"));
 }
示例#7
0
 /// <summary>
 /// Gets the cache.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key">The key.</param>
 /// <param name="defaultValue">The default value.</param>
 /// <returns></returns>
 public T GetCache <T>(string key, object defaultValue = null)
 {
     return(CacheUtil.GetCache <T>(key, defaultValue));
 }