public IEnumerable<KeysDataRow> EnumerateTemplates()
 {
   string templatesFolder = TemplateCashProvider.TemplatesFolder();
   foreach (string path in Directory.EnumerateFiles(templatesFolder, "*.dbo"))
   {
     Guid id;
     if (!Guid.TryParse(Path.GetFileNameWithoutExtension(path), out id))
       this._log.Warn((object) ("Unable to parse id from file name" + Path.GetFileName(path)));
     KeysDataRow template = this.TryReadTemplateFromCache(id);
     if (template != null)
       yield return template;
   }
 }
 public bool TryAdd(KeysDataRow templateData)
 {
   try
   {
     using (FileStream fileStream = new FileStream(TemplateCashProvider.GetCachedTemplateFileName(templateData.Id), FileMode.Create, FileAccess.Write))
       new BinaryFormatter().Serialize((Stream) fileStream, (object) templateData);
     return true;
   }
   catch (Exception ex)
   {
     this._log.Warn((object) ex.Message);
     return false;
   }
 }
 private KeysDataRow TryReadTemplateFromCache(Guid id)
 {
   string templateFileName = TemplateCashProvider.GetCachedTemplateFileName(id);
   try
   {
     using (FileStream fileStream = new FileStream(templateFileName, FileMode.Open, FileAccess.Read))
       return new BinaryFormatter().Deserialize((Stream) fileStream) as KeysDataRow;
   }
   catch (SerializationException ex)
   {
     this._log.Warn((object) ("Delete invalid template file " + Path.GetFileName(templateFileName)));
     this.TryDeleteFile(templateFileName);
     return (KeysDataRow) null;
   }
 }
 public bool TryRemove(Guid id)
 {
   try
   {
     string templateFileName = TemplateCashProvider.GetCachedTemplateFileName(id);
     if (File.Exists(templateFileName))
       File.Delete(templateFileName);
     return true;
   }
   catch (Exception ex)
   {
     this._log.Warn((object) ex.Message);
     return false;
   }
 }