public RequestUrlData GetRequestUrlData(HttpContext context, DateTime dateTime) { if (null == context) throw new ArgumentNullException("context"); RequestUrlData data = null; try { // Create the directory if it doesn't already exist. if (!Directory.Exists(Path.Combine(Statistic.GetStatisticsPath(context), "Requests"))) Directory.CreateDirectory(Path.Combine(Statistic.GetStatisticsPath(context), "Requests")); lock (lockObject) { string fileName = Path.Combine(Statistic.GetStatisticsPath(context), @"Requests\Requests_{0}_{1}.xml"); fileName = string.Format(CultureInfo.InvariantCulture, fileName, dateTime.Year, dateTime.Month); // Try to get the login statistics data from the cache. // If the data is not in the cache, try to load the file. // At last, if the file doesn't exist, create a new data object. object obj = context.Cache.Get(fileName); if ((null != obj) && obj.GetType().Equals(typeof(RequestUrlData))) { data = (RequestUrlData)obj; } else if (File.Exists(fileName)) { data = new RequestUrlData(); data.ReadXml(fileName); } else { data = new RequestUrlData(); } } } catch (UnauthorizedAccessException ex) { HandleNoAccessException(Statistic.GetStatisticsPath(context), ex); } catch (SecurityException ex) { HandleNoAccessException(Statistic.GetStatisticsPath(context), ex); } catch (Exception ex) { HandleException(Statistic.GetStatisticsPath(context), ex); } return data; }
internal void SaveRequestUrlData(HttpContext context, RequestUrlData data) { if (null == context) throw new ArgumentNullException("context"); if (null == data) throw new ArgumentNullException("data"); lock (lockObject) { string fileName = Path.Combine(Statistic.GetStatisticsPath(context), @"Requests\Requests_{0}_{1}.xml"); fileName = string.Format(CultureInfo.InvariantCulture, fileName, context.Timestamp.Year, context.Timestamp.Month); // At last, write the data back to the login statistics file and // put the data object back to the cache. try { data.WriteXml(fileName); } catch (UnauthorizedAccessException ex) { HandleNoAccessException(Statistic.GetStatisticsPath(context), ex); } catch(SecurityException ex) { HandleNoAccessException(Statistic.GetStatisticsPath(context), ex); } catch (Exception ex) { HandleException(Statistic.GetStatisticsPath(context), ex); } context.Cache.Insert(fileName, data, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration); } }