bool TryGetLastSuccessfulRead(ServiceContext context, out TimeoutManagerDataEntity lastSuccessfulReadEntity) { var query = from m in context.TimeoutManagerData where m.PartitionKey == GetUniqueEndpointName() select m; lastSuccessfulReadEntity = query .AsTableServiceQuery(context) .AsEnumerable() //TSQ does only follows continuation tokens for listings, not for single entity results, yet continuation tokes can still happen in this case .SafeFirstOrDefault(); return(lastSuccessfulReadEntity != null); }
private bool TryGetLastSuccessfullRead(ServiceContext context, out TimeoutManagerDataEntity lastSuccessfullReadEntity) { try { lastSuccessfullReadEntity = (from m in context.TimeoutManagerData where m.PartitionKey == GetUniqueEndpointName() select m).FirstOrDefault(); } catch { lastSuccessfullReadEntity = null; } return(lastSuccessfullReadEntity != null); }
private void UpdateSuccesfullRead(ServiceContext context, TimeoutManagerDataEntity read) { try { if (read == null) { read = new TimeoutManagerDataEntity(GetUniqueEndpointName(), string.Empty) { LastSuccessfullRead = DateTime.UtcNow }; context.AddObject(ServiceContext.TimeoutManagerDataTableName, read); } else { context.Detach(read); context.AttachTo(ServiceContext.TimeoutManagerDataTableName, read, "*"); context.UpdateObject(read); } context.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate); } catch (DataServiceRequestException ex) // handle concurrency issues { var response = ex.Response.FirstOrDefault(); //Concurrency Exception - PreCondition Failed or Entity Already Exists if (response != null && (response.StatusCode == 412 || response.StatusCode == 409)) { return; // I assume we can ignore this condition? // Time between read and update is very small, meaning that another instance has sent // the timeout messages that this node intended to send and if not we will resend // anything after the other node's last read value anyway on next request. } throw; } }
void UpdateSuccessfulRead(ServiceContext context, TimeoutManagerDataEntity read) { try { if (read == null) { read = new TimeoutManagerDataEntity(GetUniqueEndpointName(), string.Empty) { LastSuccessfullRead = DateTime.UtcNow }; context.AddObject(ServiceContext.TimeoutManagerDataTableName, read); } else { context.Detach(read); context.AttachTo(ServiceContext.TimeoutManagerDataTableName, read, "*"); context.UpdateObject(read); } context.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate); } catch (DataServiceRequestException ex) // handle concurrency issues { var response = ex.Response.FirstOrDefault(); //Concurrency Exception - PreCondition Failed or Entity Already Exists if (response != null && (response.StatusCode == 412 || response.StatusCode == 409)) { return; // I assume we can ignore this condition? // Time between read and update is very small, meaning that another instance has sent // the timeout messages that this node intended to send and if not we will resend // anything after the other node's last read value anyway on next request. } throw; } }
bool TryGetLastSuccessfulRead(ServiceContext context, out TimeoutManagerDataEntity lastSuccessfulReadEntity) { var query = from m in context.TimeoutManagerData where m.PartitionKey == GetUniqueEndpointName() select m; lastSuccessfulReadEntity = query .AsTableServiceQuery(context) .AsEnumerable() //TSQ does only follows continuation tokens for listings, not for single entity results, yet continuation tokes can still happen in this case .SafeFirstOrDefault(); return lastSuccessfulReadEntity != null; }
bool TryGetLastSuccessfulRead(ServiceContext context, out TimeoutManagerDataEntity lastSuccessfulReadEntity) { lastSuccessfulReadEntity = (from m in context.TimeoutManagerData where m.PartitionKey == GetUniqueEndpointName() select m).SafeFirstOrDefault(); return lastSuccessfulReadEntity != null; }