private void OnOpertionEnd(string operationName)
 {
     operationNames.Pop();
     SessionManager.PopOperation();
     if (!operationNames.Any())
     {
         ApplicationSynchronizationContext.PopContext();
     }
 }
 protected void OnOperationBegin(string operationName, bool isCallback = false)
 {
     if (!isCallback && !_operations[operationName].IsAvailable)
     {
         throw new InvalidOperationException(string.Format("{0} is not available at this time.", operationName));
     }
     if (!operationNames.Any())
     {
         ApplicationSynchronizationContext.PushContext(this, operationName);
     }
     operationNames.Push(operationName);
     SessionManager.PushOperation(this, operationName);
 }
        private void SetValueAsOperation(string propertyName, Action action)
        {
            // Cannot call OnOperationBegin(propertyName) because propertyName is not an operation.
            // Call the relevant code instead.
            operationNames.Push(propertyName);
            SessionManager.PushOperation(this, propertyName);
            ApplicationSynchronizationContext.PushContext(this, propertyName);

            try {
                action();
                OnOperationSuccess(propertyName);
            }
            catch (Exception e) {
                OnOperationError(propertyName, e);
            }
        }