Exemplo n.º 1
0
        internal bool TryWriteback(out ResponseMessage serializationErrorMessage, string operation = null)
        {
            serializationErrorMessage = null;

            if (this.CurrentStateAccess == StateAccess.Deleted)
            {
                this.State.EntityState  = null;
                this.State.EntityExists = false;
                this.CurrentStateAccess = StateAccess.NotAccessed;
            }
            else if (this.CurrentStateAccess == StateAccess.Accessed)
            {
                try
                {
                    this.State.EntityState  = this.messageDataConverter.Serialize(this.CurrentState);
                    this.State.EntityExists = true;
                }
                catch (Exception e)
                {
                    // we cannot serialize the entity state - this is an application error.
                    var serializationException = new EntitySchedulerException(
                        $"Failed to serialize state of '{this.FunctionName}' entity: {e.Message}", e);

                    this.CaptureApplicationError(serializationException);

                    serializationErrorMessage = new ResponseMessage();
                    serializationErrorMessage.SetExceptionResult(serializationException, operation, this.errorDataConverter);
                }

                this.CurrentState       = null;
                this.CurrentStateAccess = StateAccess.NotAccessed;
            }

            return(serializationErrorMessage == null);
        }
Exemplo n.º 2
0
        internal bool TryWriteback(out ResponseMessage serializationErrorMessage)
        {
            serializationErrorMessage = null;

            if (this.StateWasAccessed)
            {
                try
                {
                    this.State.EntityState = this.dataConverter.MessageConverter.Serialize(this.CurrentState);
                }
                catch (Exception e)
                {
                    // we cannot serialize the entity state - this is an application error.
                    var serializationException = new EntitySchedulerException(
                        $"Failed to serialize state of '{this.FunctionName}' entity: {e.Message}", e);

                    this.CaptureApplicationError(serializationException);

                    // Since for all of the operations in the batch, their effect on the entity state
                    // is lost, we don't want the calling orchestrations to think everything is o.k.
                    // They should be notified, so we replace all non-error operation results
                    // with an exception result.
                    serializationErrorMessage = new ResponseMessage()
                    {
                        ExceptionType = serializationException.GetType().AssemblyQualifiedName,
                        Result        = this.dataConverter.ErrorConverter.Serialize(serializationException),
                    };
                }

                this.CurrentState     = null;
                this.StateWasAccessed = false;
            }

            return(serializationErrorMessage == null);
        }