Exemplo n.º 1
0
 /// <summary>
 /// Retrieves the file data content based based on filename: dataKey.txt
 /// Files must be located same folder as running routine.
 /// Exceptions - ApplicationException for any issue.
 /// </summary>
 /// <param name="dataKey">filename without extension.</param>
 /// <returns>Text file content.</returns>
 public virtual DataRetrievalResult GetDataBasedOnKey(string dataKey)
 {
     try
     {
         DateTime            retrievedOn = DateTime.UtcNow;
         string              path        = dataKey + ".txt";
         string              fileContent = System.IO.File.ReadAllText(path);
         DataRetrievalResult result      = new DataRetrievalResult(dataKey, fileContent, retrievedOn);
         return(result);
     }
     catch (Exception ex)
     {
         throw new ApplicationException(string.Format("Error reding file for dataKey: {0}", dataKey), ex);
     }
 }
Exemplo n.º 2
0
        void Caching()
        {
            ObjectCache         cache        = MemoryCache.Default;
            DataRetrievalResult fileContents = cache[result.DataKey] as DataRetrievalResult;

            if (fileContents == null)
            {
                CacheItemPolicy policy = new CacheItemPolicy();
                policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(1);
                List <DataRetrievalResult> filePaths = new List <DataRetrievalResult>();
                filePaths.Add(result);
                cache.Add(result.DataKey, result, policy);
            }
            else
            {
                result = fileContents;
            }
        }
Exemplo n.º 3
0
 public override DataRetrievalResult GetDataBasedOnKey(string dataKey)
 {
     result = base.GetDataBasedOnKey(dataKey);
     Caching();
     return(result);
 }