Esempio n. 1
0
 /// <summary>
 /// Удалить архив.
 /// </summary>
 /// <param name="id">Идентификатор.</param>
 /// <returns>Таск.</returns>
 public async Task DeleteArchive(Guid id)
 {
     await DbAccessManager.QueueAction(async () =>
     {
         var db = await CachedDb.Load();
         if (db == null)
         {
             db = new ArchiveCollection() {Archives = new Dictionary<Guid, ArchiveReference>()};
         }
         db.Archives.Remove(id);
         var folder = await GetCacheFolder();
         var folder2 = await folder.GetFolderAsync(id.ToString());
         await folder2.DeleteAsync();
         await RemoveFolderFromSizeCache(id.ToString());
         await CachedDb.SaveSync(db);
         return EmptyResult;
     });
 }
Esempio n. 2
0
 /// <summary>
 /// Перечислить архивы.
 /// </summary>
 /// <returns>Архивы.</returns>
 public async Task<ArchiveReference[]> ListArchives()
 {
     return (ArchiveReference[]) await DbAccessManager.QueueAction(async () =>
     {
         var db = await CachedDb.Load();
         if (db == null)
         {
             db = new ArchiveCollection() {Archives = new Dictionary<Guid, ArchiveReference>()};
         }
         return db.Archives.Values.ToArray();
     });
 }
Esempio n. 3
0
 /// <summary>
 /// Сохранить архив.
 /// </summary>
 /// <param name="data">Данные.</param>
 /// <returns>Черновик.</returns>
 public async Task SaveArchive(ArchiveThreadTree data)
 {
     await DbAccessManager.QueueAction(async () =>
     {
         var db = await CachedDb.Load();
         if (db == null)
         {
             db = new ArchiveCollection() {Archives = new Dictionary<Guid, ArchiveReference>()};
         }
         db.Archives[data.Reference.Id] = data.Reference;
         const string fileName = "archive.cache";
         var folder = await (await GetCacheFolder()).CreateFolderAsync(data.Reference.Id.ToString());
         var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
         await WriteCacheXmlObject(folder, file, folder, data, true);
         await CachedDb.SaveSync(db);
         return EmptyResult;
     });
 }