Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeliveryClient"/> class for retrieving content of the specified project.
        /// </summary>
        /// <param name="deliveryOptions">The settings of the Kentico Cloud project.</param>
        public DeliveryClient(DeliveryOptions deliveryOptions)
        {
            _deliveryOptions = deliveryOptions ?? throw new ArgumentNullException(nameof(deliveryOptions), "The Delivery options object is not specified.");

            if (_deliveryOptions.ProjectId == null)
            {
                throw new ArgumentNullException(nameof(_deliveryOptions.ProjectId), "Kentico Cloud project identifier is not specified.");
            }

            if (_deliveryOptions.ProjectId == string.Empty)
            {
                throw new ArgumentException("Kentico Cloud project identifier is not specified.", nameof(_deliveryOptions.ProjectId));
            }

            Guid projectIdGuid;

            if (!Guid.TryParse(_deliveryOptions.ProjectId, out projectIdGuid))
            {
                throw new ArgumentException("Provided string is not a valid project identifier ({ProjectId}). Haven't you accidentally passed the Preview API key instead of the project identifier?", nameof(_deliveryOptions.ProjectId));
            }

            if (_deliveryOptions.UsePreviewApi)
            {
                if (_deliveryOptions.PreviewApiKey == null)
                {
                    throw new ArgumentNullException(nameof(_deliveryOptions.PreviewApiKey), "The Preview API key is not specified.");
                }

                if (_deliveryOptions.PreviewApiKey == string.Empty)
                {
                    throw new ArgumentException("The Preview API key is not specified.", nameof(_deliveryOptions.PreviewApiKey));
                }
            }

            _deliveryOptions.ProjectId = projectIdGuid.ToString("D");
        }
 public DeliveryEndpointUrlBuilder(DeliveryOptions deliveryOptions)
 {
     _deliveryOptions = deliveryOptions;
 }