public virtual void Reload() { if ((m_sessionUniqueId == Guid.Empty) || (m_sourceUniqueId == Guid.Empty)) { throw new MigrationException( string.Format(MigrationToolkitResources.Culture, MigrationToolkitResources.UninitializedHighWaterMark, m_name)); } using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { var highwaterMarksQuery = from hwm in context.RTHighWaterMarkSet where hwm.SessionUniqueId.Equals(m_sessionUniqueId) && hwm.SourceUniqueId.Equals(m_sourceUniqueId) && hwm.Name.Equals(m_name) select hwm; RTHighWaterMark rtHighWaterMark = null; if (highwaterMarksQuery.Count() > 0) { rtHighWaterMark = highwaterMarksQuery.First(); if (rtHighWaterMark.Value != null) { m_current = CreateValueFromString(rtHighWaterMark.Value); } else { m_current = default(T); } } else { rtHighWaterMark = RTHighWaterMark.CreateRTHighWaterMark(0, m_sessionUniqueId, m_sourceUniqueId, m_name); context.AddToRTHighWaterMarkSet(rtHighWaterMark); context.TrySaveChanges(); m_current = default(T); } } /* * using (TfsMigrationConsolidatedDBEntities context = TfsMigrationConsolidatedDBEntities.CreateInstance()) * { * HighWaterMarkEntity highWaterMarkEntity = context.CreateHighWaterMark * (m_sessionUniqueId, * m_sourceUniqueId, * m_name).First<HighWaterMarkEntity>(); * * * // ToDo error handling * if (highWaterMarkEntity.Value == null) * { * m_current = default(T); * } * else * { * m_current = CreateValueFromString(highWaterMarkEntity.Value); * } * }*/ }
public virtual void Update(T newValue) { if (newValue == null) { throw new ArgumentNullException("newValue"); } if ((m_sessionUniqueId == Guid.Empty) || (m_sourceUniqueId == Guid.Empty)) { throw new MigrationException( string.Format(MigrationToolkitResources.Culture, MigrationToolkitResources.UninitializedHighWaterMark, m_name)); } string newValueString = GetValueAsString(newValue); // Todo We probably could use EDM eventing , OnBeforeUpdate(newValue); using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { var highwaterMarksQuery = from hwm in context.RTHighWaterMarkSet where hwm.SessionUniqueId.Equals(m_sessionUniqueId) && hwm.SourceUniqueId.Equals(m_sourceUniqueId) && hwm.Name.Equals(m_name) select hwm; if (highwaterMarksQuery.Count() > 0) { RTHighWaterMark rtHighWaterMark = highwaterMarksQuery.First(); rtHighWaterMark.Value = newValueString; context.TrySaveChanges(); } else { RTHighWaterMark rtHighWaterMark = new RTHighWaterMark(); rtHighWaterMark.SessionUniqueId = m_sessionUniqueId; rtHighWaterMark.SourceUniqueId = m_sourceUniqueId; rtHighWaterMark.Name = m_name; rtHighWaterMark.Value = newValueString; context.AddToRTHighWaterMarkSet(rtHighWaterMark); context.TrySaveChanges(); } } m_current = newValue; }