コード例 #1
0
        public ExcelParamCollection GetExcelParams(string templateName)
        {
            ExcelParamCollection collection = null;

            var cachedParams = GetCachedExcelParams();

            cachedParams.TryGetValue(templateName, out collection);

            return(collection);
        }
コード例 #2
0
        private IDictionary <string, ExcelParamCollection> GetCachedExcelParams()
        {
            var cachedParams = _cacheService.Get <IDictionary <string, ExcelParamCollection> >(EXCEL_PARAMS_CACHE_NAME);

            if (cachedParams == null)
            {
                cachedParams = new Dictionary <string, ExcelParamCollection>();

                XDocument doc         = XDocument.Load(_webHelper.ExcelParamConfigFile);
                var       excelParams = doc.Element("ExcelParams");
                if (excelParams != null)
                {
                    foreach (var templateElement in excelParams.Elements("Template"))
                    {
                        var templateName = templateElement.Attribute("name")?.Value;
                        var collection   = new ExcelParamCollection()
                        {
                            TemplateName = templateName
                        };
                        foreach (var param in templateElement.Elements("Param"))
                        {
                            var paramName = param.Attribute("name");
                            if (paramName != null)
                            {
                                collection[paramName.Value] = param.Value; // if there are 2 parmas with the same key, last param is used
                            }
                        }

                        cachedParams[templateName] = collection;
                    }
                }

                _cacheService.Set(EXCEL_PARAMS_CACHE_NAME, cachedParams);
            }

            return(cachedParams);
        }
コード例 #3
0
ファイル: ExcelParamManager.cs プロジェクト: 3grkt/ABO
        private IDictionary <string, ExcelParamCollection> GetCachedExcelParams()
        {
            var cachedParams = System.Web.HttpContext.Current.Cache[EXCEL_PARAMS_CACHE_NAME] as IDictionary <string, ExcelParamCollection>;

            if (cachedParams == null)
            {
                cachedParams = new Dictionary <string, ExcelParamCollection>();

                XDocument doc = XDocument.Load(_webHelper.ExcelParamConfigFile);
                foreach (var templateElement in doc.Element("ExcelParams").Elements("Template"))
                {
                    var templateName = templateElement.Attribute("name").Value;
                    var collection   = new ExcelParamCollection()
                    {
                        TemplateName = templateName
                    };
                    foreach (var param in templateElement.Elements("Param"))
                    {
                        collection[param.Attribute("name").Value] = param.Value; // if there are 2 parmas with the same key, last param is used
                    }

                    cachedParams[templateName] = collection;
                }

                System.Web.HttpContext.Current.Cache.Add(
                    EXCEL_PARAMS_CACHE_NAME,
                    cachedParams,
                    new System.Web.Caching.CacheDependency(_webHelper.ExcelParamConfigFile),
                    System.Web.Caching.Cache.NoAbsoluteExpiration,
                    TimeSpan.FromMinutes(60), // hard-code 60 minutes
                    System.Web.Caching.CacheItemPriority.Normal,
                    null);
            }

            return(cachedParams);
        }