private SubscriptionEntity GetSubscriptionEntryForOperation(EntityEvent entityEvent, SubscriptionEntity subscriptionCurrentlyOnFile)
        {
            string entityId = GetEntityId(entityEvent);
            SubscriptionEntity subscriptionEntryToReturn = subscriptionCurrentlyOnFile;
            if (subscriptionEntryToReturn == null)
            {
                // Create a new entity, based on the current event
                subscriptionEntryToReturn = new SubscriptionEntity(entityId);

                // Populate fields specificcally for entities we are seeing for the first time
                subscriptionEntryToReturn.PreviousState = null;
            }
            else
            {
                // Update existing entity when we have seen it before
                subscriptionEntryToReturn.PreviousState = subscriptionCurrentlyOnFile.State;
            }

            // Common fields
            subscriptionEntryToReturn.State = entityEvent.EntityState.ToString();
            subscriptionEntryToReturn.Created = new DateTimeOffset(entityEvent.EntityId.Created);
            subscriptionEntryToReturn.LastOperation = entityEvent.EntityState.ToString();
            subscriptionEntryToReturn.LastOperationId = entityEvent.OperationId;
            subscriptionEntryToReturn.LastOperationTime = DateTimeOffset.UtcNow;
            subscriptionEntryToReturn.LastEventId = entityEvent.EventId;
            subscriptionEntryToReturn.Properties = SerializeProperties(entityEvent.Properties);

            // CONSIDER: Promoting common user properties as columns in the table

            return subscriptionEntryToReturn;
        }
 public void AddOrUpdateSubscription(SubscriptionEntity subscriptionEntity)
 {
     TableOperation insertOrReplaceOperation = TableOperation.InsertOrReplace(subscriptionEntity);
     Table.Execute(insertOrReplaceOperation);
 }