Пример #1
0
        private void ValidateFields(BinarySubmitContext submitContext)
        {
            if (submitContext.Stream.CanSeek)
            {
                // Validate that the stream is not empty only when Stream CanSeek,
                // otherwise will throw NotSupportedException
                // If not CanSeek, we have to rely on out API to do Length check.
                if (submitContext.Stream.Length == 0)
                {
                    // Use the same validation style as we see in the autorest generated code
                    // (e.g., ItemSubmissionInputModel.Validate(), which is called on every submit)
                    throw new ValidationException(ValidationRules.MinLength, nameof(submitContext.Stream));
                }
            }

            if (string.IsNullOrEmpty(submitContext.ItemExternalId))
            {
                throw new ValidationException(ValidationRules.CannotBeNull, nameof(submitContext.ItemExternalId));
            }

            if (string.IsNullOrEmpty(submitContext.ExternalId))
            {
                throw new ValidationException(ValidationRules.CannotBeNull, nameof(submitContext.ExternalId));
            }

            if (submitContext.ConnectorConfigId == default(Guid))
            {
                throw new ValidationException(ValidationRules.CannotBeNull, nameof(submitContext.ConnectorConfigId));
            }
        }
        //TODO: This is currently being duplicated here and in the HttpSubmitBinaryPipelineElementBase. We should probably just use the same in both.
        //Could move to the SubmitPipelineElementBase but feels messy having binary specific validation in there. An intermediary, perhaps?
        private void ValidateFields(BinarySubmitContext submitContext)
        {
            if (submitContext.Stream == null)
            {
                // If we cannot seek on the stream, we cannot confirm that the stream length is less than the maximum allowed
                throw new ValidationException("Provided binary stream cannot seek, and so cannot confirm if stream is below maximum allowed binary length.", nameof(submitContext.Stream));
            }

            if (submitContext.Stream.CanSeek && submitContext.Stream.Length == 0)
            {
                // The stream must have a non-zero amount of data.
                // We only check this on seekable streams, as checking the length of an unseekable stream throws a NotSupportedException
                throw new ValidationException(ValidationRules.MinLength, nameof(submitContext.Stream));
            }

            if (string.IsNullOrEmpty(submitContext.ItemExternalId))
            {
                throw new ValidationException(ValidationRules.CannotBeNull, nameof(submitContext.ItemExternalId));
            }

            if (string.IsNullOrEmpty(submitContext.ExternalId))
            {
                throw new ValidationException(ValidationRules.CannotBeNull, nameof(submitContext.ExternalId));
            }

            if (submitContext.ConnectorConfigId == default(Guid))
            {
                throw new ValidationException(ValidationRules.CannotBeNull, nameof(submitContext.ConnectorConfigId));
            }
        }