public static IBlobPathSource Create(string pattern) { if (pattern == null) { throw new FormatException("Blob paths must not be null."); } int slashIndex = pattern.IndexOf('/'); bool hasBlobName = slashIndex != -1; string containerNamePattern = pattern; string blobNamePattern = String.Empty; if (hasBlobName) { containerNamePattern = pattern.Substring(0, slashIndex); blobNamePattern = pattern.Substring(slashIndex + 1); } // There must be at least one character before the slash and one character after the slash. bool hasNonEmptyBlobAndContainerNames = slashIndex > 0 && slashIndex < pattern.Length - 1; if ((hasBlobName && !hasNonEmptyBlobAndContainerNames) || containerNamePattern.Contains('\\')) { throw new FormatException($"Invalid blob trigger path '{pattern}'. Paths must be in the format 'container/blob'."); } else if (containerNamePattern.Contains('{')) { throw new FormatException($"Invalid blob trigger path '{pattern}'. Container paths cannot contain {{resolve}} tokens."); } BindingTemplateSource template = BindingTemplateSource.FromString(pattern); if (template.ParameterNames.Count() > 0) { return(new ParameterizedBlobPathSource(containerNamePattern, blobNamePattern, template)); } BlobClientExtensions.ValidateContainerName(containerNamePattern); if (hasBlobName) { BlobClientExtensions.ValidateBlobName(blobNamePattern); } return(new FixedBlobPathSource(new BlobPath(containerNamePattern, blobNamePattern))); }
private static bool TryParseAndValidate(string value, out string errorMessage, out BlobPath path, bool isContainerBinding = false) { BlobPath possiblePath; if (!isContainerBinding && TryParseAbsUrl(value, out possiblePath)) { path = possiblePath; errorMessage = null; return(true); } if (!TryParse(value, isContainerBinding, out possiblePath)) { errorMessage = $"Invalid blob path specified : '{value}'. Blob identifiers must be in the format 'container/blob'."; path = null; return(false); } if (!BlobClientExtensions.IsValidContainerName(possiblePath.ContainerName)) { errorMessage = "Invalid container name: " + possiblePath.ContainerName; path = null; return(false); } // for container bindings, we allow an empty blob name/path string possibleErrorMessage; if (!(isContainerBinding && string.IsNullOrEmpty(possiblePath.BlobName)) && !BlobClientExtensions.IsValidBlobName(possiblePath.BlobName, out possibleErrorMessage)) { errorMessage = possibleErrorMessage; path = null; return(false); } errorMessage = null; path = possiblePath; return(true); }