private async Task Load() { CloudTableClient client = _account.CreateCloudTableClient(); var table = client.GetTableReference(CantonConstants.CursorTable); var op = TableOperation.Retrieve <CursorEntry>("cursors", Key); var result = await table.ExecuteAsync(op); if (result.Result == null) { _position = CantonConstants.MinSupportedDateTime; await Save(); } else { CursorEntry entry = (CursorEntry)result.Result; _position = entry.Position; if (!String.IsNullOrEmpty(entry.DependantCursors)) { _dependantCursors = new List <string>(entry.DependantCursors.Split('|')); } if (!String.IsNullOrEmpty(entry.Metadata)) { _metadata = JObject.Parse(entry.Metadata); } if (entry.LockId != Guid.Empty && entry.LockExpiration > DateTime.UtcNow) { throw new Exception("Unable to use locked cursor"); } } }
/// <summary> /// Saves the cursor to storage. Make sure ALL items with this position have been completed first. /// </summary> public async Task Save() { var client = _account.CreateCloudTableClient(); var table = client.GetTableReference(CantonConstants.CursorTable); CursorEntry entry = new CursorEntry(this); // TODO: Add locking var op = TableOperation.InsertOrReplace(entry); await table.ExecuteAsync(op); }