Exemplo n.º 1
0
 /// <summary>
 /// Сохранить черновик.
 /// </summary>
 /// <param name="data">Данные.</param>
 /// <returns>Черновик.</returns>
 public async Task SaveDraft(DraftPostingData data)
 {
     await DbAccessManager.QueueAction(async () =>
     {
         var db = await CachedDb.Load();
         if (db == null)
         {
             db = new DraftCollection() {Drafts = new Dictionary<Guid, DraftReference>()};
         }
         db.Drafts[data.Reference.Id] = data.Reference;
         var fileName = string.Format("{0}.cache", data.Reference.Id);
         var folder = await GetCacheFolder();
         var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
         await WriteCacheXmlObject(file, folder, data, true);
         await CachedDb.SaveSync(db);
         return EmptyResult;
     });
 }
Exemplo n.º 2
0
 /// <summary>
 /// Удалить черновик.
 /// </summary>
 /// <param name="id">Идентификатор.</param>
 /// <returns>Таск.</returns>
 public async Task DeleteDraft(Guid id)
 {
     await DbAccessManager.QueueAction(async () =>
     {
         var db = await CachedDb.Load();
         if (db == null)
         {
             db = new DraftCollection() {Drafts = new Dictionary<Guid, DraftReference>()};
         }
         db.Drafts.Remove(id);
         var folder = await GetCacheFolder();
         var fileName = string.Format("{0}.cache", id);
         var file = await folder.GetFileAsync(fileName);
         await file.DeleteAsync();
         await CachedDb.SaveSync(db);
         return EmptyResult;
     });
 }
Exemplo n.º 3
0
 /// <summary>
 /// Перечислить черновики.
 /// </summary>
 /// <returns>Черновики.</returns>
 public async Task<DraftReference[]> ListDrafts()
 {
     return (DraftReference[]) await DbAccessManager.QueueAction(async () =>
     {
         var db = await CachedDb.Load();
         if (db == null)
         {
             db = new DraftCollection() {Drafts = new Dictionary<Guid, DraftReference>()};
         }
         return db.Drafts.Values.ToArray();
     });
 }