Esempio n. 1
0
        /// <summary>
        ///     获取数据列表(读取数据库)
        /// </summary>
        /// <param name="db">事务</param>
        public List <TInfo> GetTrueList(DbExecutor db = null)
        {
            var lst = Data.ToList(db);

            WebCache.Add(Key, lst, SystemConfigs.ConfigInfo.Cache_Db_TimeOut);
            return(lst);
        }
Esempio n. 2
0
 public static void Add(string key, object value, int expireSeconds)
 {
     if (expireSeconds == CacheManagerKey.CacheLifeSpanForever)
         WebCache.Add(key, value, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
     else
         WebCache.Add(key, value, null, DateTime.MaxValue, TimeSpan.FromSeconds(expireSeconds), CacheItemPriority.Normal, null);
 }
Esempio n. 3
0
        public byte[] Extract(string fpath)
        {
            this.Assert(!string.IsNullOrEmpty(fpath));
            if (fpath.StartsWith("/"))
            {
                fpath = fpath.TrimStart('/');
            }

            byte[] content = null;
            try
            {
                content = _webCache.Extract(fpath);
                if (content == null)
                {
                    //if (File.Exists(_pkgLocation))
                    if (Path.IsPathRooted(_pkgLocation))
                    {
                        using (FileStream fs = new FileStream(_pkgLocation, FileMode.Open, FileAccess.Read, FileShare.Read))
                            content = ZipStream.Extract(fs, fpath);
                    }
                    else
                    {
                        var assembly = System.Reflection.Assembly.GetEntryAssembly();
                        var rs       = assembly.GetManifestResourceStream(_pkgLocation);
                        content = ZipStream.Extract(rs, fpath);
                    }
                    if (content != null)
                    {
                        _webCache.Add(fpath, content);
                    }
                }
            }
            catch (Exception ex) { TraceLog.WriteException(ex); throw; }
            return(content);
        }
Esempio n. 4
0
 public static bool Add(string key, object value, DateTime expiry)
 {
     if (WebCache.KeyExists(key))
     {
         return(false);
     }
     WebCache.Add(key, value, expiry);
     return(Provider.Add(key, value, expiry));
 }
Esempio n. 5
0
        /// <summary>
        /// 从缓存中获取文件最后更新时间
        /// </summary>
        /// <returns></returns>
        private static string GetFileUpdateTime(string key, string filePath)
        {
            object tmp;

            if (!WebCache.GetCacheTryParse(key, out tmp))
            {
                tmp = LoadFileUpdateTime(filePath);
                WebCache.Add(key, tmp);
            }
            return(tmp as string);
        }
Esempio n. 6
0
        /// <summary>
        ///     添加缓存值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="t">dbBuilder.ToString():唯一标识</param>
        /// <param name="isIgnoreStatistics">是否忽略统计,直接加入缓存</param>
        private static void Set <T>(string key, T t, bool isIgnoreStatistics = false)
        {
            var cache = DataStatisticsList.FirstOrDefault(o => o.Key == key);

            if (!isIgnoreStatistics && cache.LstActiveAt.Count < CacheConfigs.ConfigInfo.VisitCount)
            {
                return;
            }

            // 加入缓存
            WebCache.Add(key, t, CacheConfigs.ConfigInfo.CacheTimeOut);
            cache.JoinCacheAt = DateTime.Now;
        }
Esempio n. 7
0
        /// <summary>
        ///     获取缓存中的列表
        /// </summary>
        /// <param name="db">事务</param>
        internal List <TInfo> ToList(DbExecutor db = null)
        {
            var lst = WebCache.Get <List <TInfo> >(Key);

            if (lst == null)
            {
                lst = GetTrueList(db) ?? new List <TInfo>();
            }
            if (lst.Count == 0)
            {
                WebCache.Add(Key, lst, SystemConfigs.ConfigInfo.Cache_Db_TimeOut);
            }
            return(lst);
        }
Esempio n. 8
0
        public HttpResponseMessage Get(string type, int?id)
        {
            var data = WebCache <IList <CommonsModel> > .Get(string.Format(Constants.Cache.DropDown, type));

            if (data == null)
            {
                data = _process.DropDown(type, id);
                WebCache <IList <CommonsModel> > .Add(Constants.Cache.DropDown, data, DateTimeOffset.Now.AddDays(1));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, new
            {
                data = data
            }));
        }
Esempio n. 9
0
        /// <summary>
        /// 将数据加载到缓存中
        /// </summary>
        /// <returns></returns>
        public List <StationInfo> GetStationInfoList()
        {
            //首页判断文件是否被改动过
            var newUpdateFileTime = LoadFileUpdateTime(NanChangStationFilePath);
            var oldUpdateFileTime = GetFileUpdateTime(cacheStationInfoUpdateTimeKey, NanChangStationFilePath);

            object tmp;

            if (!WebCache.GetCacheTryParse(cacheStationInfoListKey, out tmp) || newUpdateFileTime != oldUpdateFileTime)
            {
                tmp = LoadStationInfo();
                WebCache.Add(cacheStationInfoListKey, tmp);
            }
            return(tmp as List <StationInfo>);
        }
Esempio n. 10
0
        /// <summary>
        /// 获取西站温馨提示
        /// </summary>
        /// <returns></returns>
        public string GetWestReminderTxt()
        {
            //首页判断文件是否被改动过
            var newUpdateFileTime = LoadFileUpdateTime(NanChangWestStationTipFilePath);
            var oldUpdateFileTime = GetFileUpdateTime(cacheWestReminderUpdateTimeKey, NanChangWestStationTipFilePath);

            object tmp;

            if (!WebCache.GetCacheTryParse(cacheWestReminderTxtKey, out tmp) || newUpdateFileTime != oldUpdateFileTime)
            {
                tmp = LoadReminderTxtFromFile(NanChangWestStationTipFilePath);
                WebCache.Add(cacheWestReminderTxtKey, tmp);
            }
            return(tmp.ToString());
        }
Esempio n. 11
0
        public override void Execute()
        {
            lock (typeof(GetUrlItem))
            {
                PageCacheItem page = new PageCacheItem();
                mRequest  = (HttpWebRequest)WebRequest.Create(URL);
                mResponse = (HttpWebResponse)mRequest.GetResponse();
                int length = 0;
                foreach (string key in mResponse.Headers.Keys)
                {
                    page.Headers.Add(new HeaderItem {
                        Name = key, Value = mResponse.Headers[key]
                    });
                    if (key == "Content-Length")
                    {
                        int.TryParse(mResponse.Headers[key], out length);
                    }
                }
                page.Data = new Byte[length];
                int offset = 0;
                int count;
                using (System.IO.Stream stream = mResponse.GetResponseStream())
                {
                    count   = stream.Read(page.Data, offset, page.Data.Length - offset);
                    offset += count;
                    while (count > 0)
                    {
                        count   = stream.Read(page.Data, offset, page.Data.Length - offset);
                        offset += count;
                    }
                }

                if (Cache != null && HttpModule.MenCacheEnabled)
                {
                    Cache.Set(Key, page);
                }
                if (WebCache != null && HttpModule.WebCacheEnabled)
                {
                    WebCache.Remove(Key);
                    WebCache.Add(Key, page, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                }
            }
        }
        public override void Interpret()
        {
            if (File.Exists(context.Request.PhysicalPathFile))
            {
                using (FileStream fs = new FileStream(context.Request.PhysicalPathFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    // calculamos el hashcode para
                    string hashcode      = Conversion.CalculateHashCode(fs);
                    string mainClassName = "CodeRender_" + Path.GetFileNameWithoutExtension(context.Request.PhysicalPathFile);

                    Assembly asam = cache.Get(hashcode) as Assembly;

                    if (asam == null)
                    {
                        StreamReader reader = new StreamReader(fs, Encoding.Default, true, 4096);
                        parser             = new AspParser(context.Request.PhysicalPathFile, reader);
                        parser.TagParsed  += new TagParsedHandler(parser_TagParsed);
                        parser.TextParsed += new TextParsedHandler(parser_TextParsed);
                        parser.Error      += new ParseErrorHandler(parser_Error);

                        eb = new EvaluatorBuilder();

                        eb.BeginCompile("ASP");
                        eb.AppendNameSpace("System");
                        eb.AppendNameSpace("System.Web");

                        CodeTypeDeclaration c = eb.AppendClass(mainClassName, typeof(DinamicPage));

                        // eb.CreatePropertyGetForObject(c, context.App.GetType(), "App", "Context.App");
                        // eb.CreatePropertyGetForObject(c, context.SessionRequest == null ? typeof(Object) : context.SessionRequest.GetType(), "SessionRequest", "Context.SessionRequest");

                        m = eb.AppendMethod(c, "Render", MemberAttributes.Override);

                        parser.Parse();

                        asam = eb.EndCompile();

                        // añadimos al cache
                        cache.Add(hashcode, asam);
                    }

                    DinamicPage page = asam.CreateInstance("ASP." + mainClassName)
                                       as DinamicPage;

                    page.Me              = this;
                    page.Context         = context;
                    page.OutStream       = new StringBuilder();
                    context.Reply.Render = page;

                    try
                    {
                        page.Render();
                    }
                    catch (Exception err)
                    {
                        page.OutStream.AppendFormat("Error: {0}\n{1}", err.Message, err.StackTrace);
                    }

                    // forzar descarga de archivo
                    if (!context.Reply.ForcedFileDownload && !context.Reply.LoadedStream)
                    {
                        context.Reply.LoadText(page.OutStream.ToString());
                    }
                }
            }
            else
            {
                context.Reply.Code = Codes.NOT_FOUND;
            }
        }