コード例 #1
0
ファイル: AjaxAlloction.cs プロジェクト: NickQi/TianheDemo
        public ResultConfigLog GetConfigLog()
        {
            var inputValue = HttpContext.Current.Request.Form["Inputs"];
            var StartTime = HttpContext.Current.Request.Form["StartTime"];
            var endTime = HttpContext.Current.Request.Form["EndTime"];
            var areaId = HttpContext.Current.Request.Form["AreaID"];
            QueryConfigLog model = Newtonsoft.Json.JsonConvert.DeserializeObject<QueryConfigLog>(inputValue);
            if (model == null)
                return null;

            if (!string.IsNullOrEmpty(StartTime))
            {
                DateTime dt = DateTime.Parse(StartTime.ToString());
                model.StartTime = dt;
            }
            if (!string.IsNullOrEmpty(endTime))
            {
                DateTime dt = DateTime.Parse(endTime.ToString());
                model.EndTime = dt;
            }
            if (!string.IsNullOrEmpty(areaId))
            {
                model.AreaID = int.Parse(areaId.ToString());
            }
            ResultConfigLog result = new AlloctionBLL().GetConfigLog(model);
            System.Web.Caching.Cache c = new System.Web.Caching.Cache();

            CacheHelper.SetCache("ConfigLog", result);

            return result;
        }
コード例 #2
0
 public WebCacheAdapter()
 {
     if (System.Web.HttpContext.Current != null)
         _cache = System.Web.HttpContext.Current.Cache;
     else
         throw new InvalidOperationException("No HttpContext, unable to use the web cache");
 }
コード例 #3
0
        public MemoryCache()
        {
            HttpContext.Current = new HttpContext(
                new HttpRequest(null, "http://switcheroo.io", null),
                new HttpResponse(null));

            cache = HttpContext.Current.Cache;
        }
コード例 #4
0
 public CacheAutoComplete(
     IProvider<Place> placeRepository,
     IProvider<Building> buildingRepository,
     System.Web.Caching.Cache cacheRepository)
     : base(placeRepository, buildingRepository)
 {
     this.cache = HttpRuntime.Cache;
     this.CacheTimeOut = 3000;
 }
コード例 #5
0
ファイル: CacheHelper.cs プロジェクト: wwwfox111/danfoss
 /// <summary>
 /// 设置数据缓存
 /// </summary>
 public static void SetCache(string cacheKey, object obj, TimeSpan timeout)
 {
     System.Web.Caching.Cache cache = HttpRuntime.Cache;
     cache.Insert(cacheKey, obj, null, DateTime.MaxValue, timeout,
                  System.Web.Caching.CacheItemPriority.NotRemovable, null);
 }
コード例 #6
0
ファイル: CacheHelper.cs プロジェクト: wwwfox111/danfoss
 /// <summary>
 /// 移除指定数据缓存
 /// </summary>
 public static void RemoveCache(string cacheKey)
 {
     System.Web.Caching.Cache cache = HttpRuntime.Cache;
     cache.Remove(cacheKey);
 }
コード例 #7
0
ファイル: CacheHelper.cs プロジェクト: wwwfox111/danfoss
 /// <summary>
 /// 设置数据缓存
 /// </summary>
 public static void SetCache(string cacheKey, object obj)
 {
     System.Web.Caching.Cache cache = HttpRuntime.Cache;
     cache.Insert(cacheKey, obj);
 }
コード例 #8
0
ファイル: CacheHelper.cs プロジェクト: wwwfox111/danfoss
 /// <summary>
 /// 设置数据缓存
 /// </summary>
 /// <param name="cacheKey">缓存Key</param>
 /// <param name="obj">缓存对象</param>
 /// <param name="cacheSeconds">缓存多少秒</param>
 public static void SetCache(string cacheKey, object obj, int cacheSeconds)
 {
     System.Web.Caching.Cache cache = HttpRuntime.Cache;
     cache.Insert(cacheKey, obj, null, DateTime.Now.AddSeconds(cacheSeconds), System.Web.Caching.Cache.NoSlidingExpiration);
 }
コード例 #9
0
            public LocalHttpContext(Uri url, string rawUrl, string applicationPath, HttpServerUtility utility, System.Web.Caching.Cache cache)
            {
                request = new LocalHttpRequest(url, rawUrl, applicationPath);
                response = new LocalHttpResponse();
                this.cache = cache;

                this.utility = new HttpServerUtilityWrapper(utility);
            }
コード例 #10
0
ファイル: Dados.cs プロジェクト: cleocomprazer/ops.net.br
        public void CarregaValores(System.Web.Caching.Cache cache, ListBox listParlamentar, ListBox listDespesas, ListBox listPartidos)
        {
            MenorAno = DateTime.Today.Year;

            try
            {
                using (Banco banco = new Banco())
                {
                    if (cache["menorAno"] == null)
                    {
                        using (MySqlDataReader reader = banco.ExecuteReader("SELECT * FROM parametros"))
                        {
                            if (reader.Read())
                            {
                                try { MenorAno = Convert.ToInt32(reader["menorAno"]); }
                                catch { MenorAno = DateTime.Today.Year; }

                                try { UltimaAtualizacao = Convert.ToDateTime(reader["ultima_atualizacao"]); }
                                catch { }
                            }

                            reader.Close();
                        }

                        try
                        {
                            cache.Add("menorAno", MenorAno, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                            cache.Add("ultima_atualizacao", UltimaAtualizacao, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else
                    {
                        MenorAno          = Convert.ToInt32(cache["menorAno"]);
                        UltimaAtualizacao = Convert.ToDateTime(cache["ultima_atualizacao"]);
                    }

                    if (cache["tableParlamentar"] == null)
                    {
                        using (DataTable table = banco.GetTable("SELECT ideCadastro, txNomeParlamentar FROM parlamentares ORDER BY txNomeParlamentar"))
                        {
                            foreach (DataRow row in table.Rows)
                            {
                                listParlamentar.Items.Add(new ListItem(Convert.ToString(row["txNomeParlamentar"]), Convert.ToString(row["ideCadastro"])));
                            }

                            try
                            {
                                cache.Add("tableParlamentar", table, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    else
                    {
                        DataTable table = (DataTable)cache["tableParlamentar"];

                        foreach (DataRow row in table.Rows)
                        {
                            listParlamentar.Items.Add(new ListItem(Convert.ToString(row["txNomeParlamentar"]), Convert.ToString(row["ideCadastro"])));
                        }
                    }

                    if (cache["tableDespesa"] == null)
                    {
                        using (DataTable table = banco.GetTable("SELECT numSubCota, txtDescricao FROM despesas ORDER BY txtDescricao"))
                        {
                            foreach (DataRow row in table.Rows)
                            {
                                listDespesas.Items.Add(new ListItem(Convert.ToString(row["txtDescricao"]), Convert.ToString(row["numSubCota"])));
                            }

                            try
                            {
                                cache.Add("tableDespesa", table, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    else
                    {
                        DataTable table = (DataTable)cache["tableDespesa"];

                        foreach (DataRow row in table.Rows)
                        {
                            listDespesas.Items.Add(new ListItem(Convert.ToString(row["txtDescricao"]), Convert.ToString(row["numSubCota"])));
                        }
                    }

                    if (cache["tablePartido"] == null)
                    {
                        using (DataTable table = banco.GetTable("SELECT sgPartido, sgPartido FROM partidos ORDER BY sgPartido"))
                        {
                            foreach (DataRow row in table.Rows)
                            {
                                listPartidos.Items.Add(new ListItem(Convert.ToString(row["sgPartido"]), Convert.ToString(row["sgPartido"])));
                            }

                            try
                            {
                                cache.Add("tablePartido", table, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    else
                    {
                        DataTable table = (DataTable)cache["tablePartido"];

                        foreach (DataRow row in table.Rows)
                        {
                            listPartidos.Items.Add(new ListItem(Convert.ToString(row["sgPartido"]), Convert.ToString(row["sgPartido"])));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MsgErro = ex.Message;
            }
        }
コード例 #11
0
 /// <summary>
 /// 移除当前应用程序中指定的缓存值
 /// </summary>
 /// <param name="CacheKey"></param>
 public void RemoveCache(string CacheKey)
 {
     System.Web.Caching.Cache _cache = HttpRuntime.Cache;
     _cache.Remove(CacheKey);
 }
コード例 #12
0
ファイル: DataCache.cs プロジェクト: rebornchen/FileManager
 /// <summary>
 /// 设置当前应用程序指定CacheKey的Cache值
 /// </summary>
 /// <param name="CacheKey"></param>
 /// <param name="objObject"></param>
 public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     objCache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
 }
コード例 #13
0
        ///// <summary>
        ///// 设置当前应用程序指定CacheKey的Cache值
        ///// </summary>
        ///// <param name="CacheKey"></param>
        ///// <param name="objObject"></param>
        //public static void SetCache(string CacheKey, object objObject)
        //{
        //    System.Web.Caching.Cache objCache = HttpRuntime.Cache;
        //    objCache.Insert(CacheKey, objObject);
        //}


        /// <summary>
        /// 设置当前应用程序指定CacheKey的Cache值
        /// </summary>
        /// <param name="CacheKey"></param>
        /// <param name="objObject"></param>
        public static void SetCache(string CacheKey, object objObject, DateTime TimeOut)
        {
            System.Web.Caching.Cache objCache = HttpRuntime.Cache;
            objCache.Insert(CacheKey, objObject, null, TimeOut, System.Web.Caching.Cache.NoSlidingExpiration);
        }
コード例 #14
0
 /// <summary>
 /// 设置当前应用程序指定CacheKey的Cache值
 /// </summary>
 /// <param name="CacheKey"></param>
 /// <param name="objObject"></param>
 /// <param name="Timeout"></param>
 public void SetCache(string CacheKey, object objObject, TimeSpan Timeout)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     objCache.Insert(CacheKey, objObject, null, DateTime.MaxValue, Timeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);
 }
コード例 #15
0
 public static object RemoveCache(string CacheKey)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     return(objCache.Remove(CacheKey));
 }
コード例 #16
0
 /// <summary>
 /// 设置当前应用程序指定CacheKey的Cache值
 /// </summary>
 /// <param name="CacheKey"></param>
 /// <param name="objObject"></param>
 public static void SetCache(string CacheKey, object objObject)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     objCache.Insert(CacheKey, objObject, null, System.Web.Caching.Cache.NoAbsoluteExpiration,
                     TimeSpan.FromHours(2));
 }
コード例 #17
0
 /// <summary>
 /// 设定绝对的过期时间
 /// </summary>
 /// <param name="CacheKey"></param>
 /// <param name="objObject"></param>
 /// <param name="seconds">超过多少秒后过期</param>
 public static void SetCacheDateTime(string CacheKey, object objObject, long Seconds)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     objCache.Insert(CacheKey, objObject, null, DateTime.Now.AddSeconds(Seconds), TimeSpan.Zero);
 }
コード例 #18
0
ファイル: DataCache.cs プロジェクト: rebornchen/FileManager
 /// <summary>
 ///
 /// </summary>
 /// <param name="CacheKey"></param>
 /// <returns></returns>
 public static object GetCache(string CacheKey)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     return(objCache[CacheKey]);
 }
コード例 #19
0
ファイル: CacheUtlity.cs プロジェクト: KevSop/CEA_CR_net40
 /// <summary>
 /// 清除单一键缓存
 /// </summary>
 /// <param name="key"></param>
 public static void RemoveOneCache(string CacheKey)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     objCache.Remove(CacheKey);
 }
コード例 #20
0
ファイル: DataCache.cs プロジェクト: rebornchen/FileManager
 /// <summary>
 /// 设置当前应用程序指定CacheKey的Cache值
 /// </summary>
 /// <param name="CacheKey"></param>
 /// <param name="objObject"></param>
 public static void SetCache(string CacheKey, object objObject)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     objCache.Insert(CacheKey, objObject);
 }
コード例 #21
0
ファイル: StringHelper.cs プロジェクト: yujianjob/promotion
 static StringHelper()
 {
     dictCharacter = new Dictionary<string, string>();
     //dictCharacter.Add("<", "&lt");
     //dictCharacter.Add(">", "&gt;");
     //dictCharacter.Add("&", "&amp;");
     //dictCharacter.Add("\"", "&quot;");
     dictCharacter.Add("'", "''");
     dictCharacter.Add("[", "[[]");
     myCache = System.Web.HttpContext.Current.Cache;
 }
コード例 #22
0
ファイル: WebCache.cs プロジェクト: jorik041/X.Google
 public WebCache(System.Web.Caching.Cache cache)
 {
     _cache = cache;
     CacheTimeout = 10 * 60;
 }
コード例 #23
0
        private void InstanceRequest(HttpApplication app)
        {
            System.Web.Caching.Cache Cache = app.Context.Cache;
            CacheData item = null;

            object messagesLock = new object();

            if (app.Request[Tenor.Configuration.TenorModuleSection.NoCache] == string.Empty)
            {
                lock (messagesLock)
                {
                    item = Cache.Get("instance:" + app.Request.QueryString.ToString()) as CacheData;
                }
            }

            if (item != null)
            {
                //data is already in cache for the current url
                WriteHeaders(app, item);
                WriteStream(((Stream)item.Object), app);
            }
            else
            {
                //data is not yet on cache.


                _class = QueryString("cl");

                //Hexadecimal hash - the new method
                try
                {
                    _class = Tenor.Text.Strings.FromAscHex(_class);
                }
                catch (Exception)
                {
                    try
                    {
                        //Old method, for backward compatibility.
                        //TODO: do we really need this?
                        _class = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(_class));
                    }
                    catch (Exception)
                    {
                        throw (new TenorException("Invalid \'cl\' parameter. Value: " + _class));
                    }
                }


                Type classeT = null;

                Assembly ass;

                lock (messagesLock)
                {
                    try
                    {
                        ass = Array.Find <Assembly>(AppDomain.CurrentDomain.GetAssemblies(), new Predicate <Assembly>(FindAssembly));
                        if (ass != null)
                        {
                            classeT = ass.GetType(_class, false, true);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                if (classeT == null)
                {
                    //We cannot find the type, try on other assemblies.
                    foreach (string file in System.IO.Directory.GetFiles(AppDomain.CurrentDomain.RelativeSearchPath, "*.dll"))
                    {
                        try
                        {
                            Assembly ass2 = Assembly.LoadFile(file);
                            if (ass2 != null)
                            {
                                classeT = ass2.GetType(_class, false, true);
                                if (classeT != null)
                                {
                                    break;
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }

                    if (classeT == null)
                    {
                        throw (new TenorException("Cannot find class \'" + _class + "\'."));
                        //return; //404
                    }
                    //Else
                    //    classeT = ass.GetType(_class, False, True)
                }

                //Search for a constructor that have an integer parameter.
                //TODO: Make this mor flexible, with more than one parameter and type.
                ConstructorInfo classeC = classeT.GetConstructor(new Type[] { typeof(int) });

                if (classeC == null)
                {
                    //no constructor found.
                    throw (new TenorException("Cannot find any suitable constructor to call for class \'" + _class + "\'."));
                    //return; //404
                }
                //parse parameters.
                string valorO = QueryString("p1");
                int    valorI = 0;
                if (!int.TryParse(valorO, out valorI))
                {
                    //invalid parameter
                    throw (new TenorException("Invalid parameter value."));
                    //return; //404
                }
                else
                {
                    try
                    {
                        object          instance       = classeC.Invoke(new object[] { valorI });
                        IResponseObject responseObject = null;

                        if (classeT.GetInterface(typeof(IResponseObject).FullName) == null)
                        {
                            PropertyInfo prop = Array.Find <PropertyInfo>(classeT.GetProperties(), new Predicate <PropertyInfo>(FindProperty));
                            if (prop != null)
                            {
                                responseObject = (IResponseObject)(prop.GetValue(instance, null));
                            }
                        }
                        else
                        {
                            responseObject = (IResponseObject)instance;
                        }
                        if (responseObject == null)
                        {
                            //This class does not have IResponseObject nor a property that returns one.
                            throw (new TenorException("Invalid response stream."));
                            //return; //404
                        }

                        IImage img = responseObject as IImage;
                        if (img != null)
                        {
                            if (!string.IsNullOrEmpty(QueryString("w")) || !string.IsNullOrEmpty(QueryString("h")) || !string.IsNullOrEmpty(QueryString("l")))
                            {
                                //image manipulation.
                                int l = 0;
                                int.TryParse(QueryString("l"), out l);



                                int w = 0;
                                int.TryParse(QueryString("w"), out w);
                                int h = 0;
                                int.TryParse(QueryString("h"), out h);

                                ResizeMode mode = ResizeMode.Proportional;

                                if (!string.IsNullOrEmpty(QueryString("m")))
                                {
                                    try
                                    {
                                        mode = (ResizeMode)(int.Parse(QueryString("m")));
                                    }
                                    catch (Exception)
                                    {
                                        throw (new HttpException("Invalid image parameters", 500));
                                    }
                                }

                                if (w > 0 || h > 0)
                                {
                                    img.Resize(w, h, mode);
                                }
                                if (l != 0)
                                {
                                    img.LowQuality = true;
                                }
                                //If crop Then
                                //    img.Resize(w, h, Drawing.ResizeMode.Crop)
                                //Else
                                //    If w = 0 Then
                                //        img.ResizeByHeight(h)
                                //    ElseIf h = 0 Then
                                //        img.ResizeByWidth(w)
                                //    Else
                                //        img.Resize(w, h, Drawing.ResizeMode.Stretch)
                                //    End If
                                //End If
                                img = null;
                            }
                        }


                        Stream File = null;
                        File = responseObject.WriteContent();

                        CacheData cacheData = new CacheData();
                        cacheData.Expires       = Tenor.Configuration.TenorModuleSection.DefaultExpiresTime;
                        cacheData.ContentType   = responseObject.ContentType;
                        cacheData.ContentLength = File.Length;


                        if (!string.IsNullOrEmpty(QueryString("fn")))
                        {
                            cacheData.FileName = QueryString("fn");
                            if (!cacheData.FileName.Contains("."))
                            {
                                cacheData.FileName += "." + IO.BinaryFile.GetExtension(cacheData.ContentType);
                            }
                        }
                        else
                        {
                            cacheData.FileName = valorI.ToString() + "." + IO.BinaryFile.GetExtension(cacheData.ContentType);
                        }


                        if (!string.IsNullOrEmpty(QueryString("dl")))
                        {
                            try
                            {
                                cacheData.ForceDownload = Convert.ToBoolean(int.Parse(QueryString("dl")));
                            }
                            catch (Exception)
                            {
                            }
                        }

                        if (string.IsNullOrEmpty(cacheData.ContentType))
                        {
                            cacheData.ContentType = GetMimeType(File);
                        }

                        WriteHeaders(app, cacheData);
                        WriteStream(File, app);


                        cacheData.Object = File;
                        if (app.Request[Tenor.Configuration.TenorModuleSection.NoCache] == string.Empty)
                        {
                            lock (messagesLock)
                            {
                                Cache.Add("instance:" + app.Request.QueryString.ToString(), cacheData, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 20, 0), System.Web.Caching.CacheItemPriority.Default, new System.Web.Caching.CacheItemRemovedCallback(Cache_onItemRemoved));
                            }
                        }
                    }
                    catch (Exception)
                    {
                        /*
                         * app.Context.ClearError()
                         * app.Context.AddError(New HttpException(500, "server error", ex.InnerException))
                         * app.Context.Response.StatusCode = 500
                         */
                        throw;
                    }
                }
            }
        }
コード例 #24
0
ファイル: CacheUtil.cs プロジェクト: lxny2004/JCE.FIx
 /// <summary>
 /// 设置数据缓存
 /// </summary>
 /// <param name="cacheKey">缓存键</param>
 /// <param name="objValue">对象值</param>
 public static void Set(string cacheKey, object objValue)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     objCache.Insert(cacheKey, objValue);
 }
コード例 #25
0
 public static void SetCache(string CacheKey, object objObject, DateTime absdate)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     objCache.Insert(CacheKey, objObject, null, absdate, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, null);
 }
コード例 #26
0
        public void SetGetPropertiesTest() {

            var init = new MockInitPage();
            var page = new MockPage();
            init.ChildPage = page;

            // Context
            var context = new Mock<HttpContextBase>().Object;
            init.Context = context;
            Assert.AreEqual(context, init.Context);
            Assert.AreEqual(context, page.Context);

            // Request/Response/Server/Cache/Session/Application
            var request = new Mock<HttpRequestBase>().Object;
            var response = new Mock<HttpResponseBase>().Object;
            var server = new Mock<HttpServerUtilityBase>().Object;
            var cache = new System.Web.Caching.Cache();
            var app = new Mock<HttpApplicationStateBase>().Object;
            var session = new Mock<HttpSessionStateBase>().Object;

            var contextMock = new Mock<HttpContextBase>();
            contextMock.Setup(c => c.Request).Returns(request);
            contextMock.Setup(c => c.Response).Returns(response);
            contextMock.Setup(c => c.Cache).Returns(cache);
            contextMock.Setup(c => c.Server).Returns(server);
            contextMock.Setup(c => c.Application).Returns(app);
            contextMock.Setup(c => c.Session).Returns(session);

            context = contextMock.Object;
            page.Context = context;
            Assert.AreEqual(request, init.Request);
            Assert.AreEqual(response, init.Response);
            Assert.AreEqual(cache, init.Cache);
            Assert.AreEqual(server, init.Server);
            Assert.AreEqual(session, init.Session);
            Assert.AreEqual(app, init.AppState);
        }
コード例 #27
0
 public static void RemoveAllCache(CacheTypeNames ctype)
 {
     System.Web.Caching.Cache _cache = HttpRuntime.Cache;
     _cache.Remove(ctype.ToString());
 }
コード例 #28
0
ファイル: CacheContext.cs プロジェクト: thinhtp/openauth
 public override T Get <T>(string key)
 {
     System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     return((T)objCache[key]);
 }
コード例 #29
0
 public void Run(HttpApplicationState application, System.Web.Caching.Cache cache)
 {
     cambiarEstadoTarjetas();
     cambiarEstadoFacturas();
 }