コード例 #1
0
        private static BindingMetadata ParseBindingMetadata(JObject binding, INameResolver nameResolver)
        {
            BindingMetadata  bindingMetadata       = null;
            string           bindingTypeValue      = (string)binding["type"];
            string           bindingDirectionValue = (string)binding["direction"];
            string           connection            = (string)binding["connection"];
            BindingType      bindingType           = default(BindingType);
            BindingDirection bindingDirection      = default(BindingDirection);

            if (!string.IsNullOrEmpty(bindingDirectionValue) &&
                !Enum.TryParse <BindingDirection>(bindingDirectionValue, true, out bindingDirection))
            {
                throw new FormatException(string.Format(CultureInfo.InvariantCulture, "'{0}' is not a valid binding direction.", bindingDirectionValue));
            }

            if (!string.IsNullOrEmpty(bindingTypeValue) &&
                !Enum.TryParse <BindingType>(bindingTypeValue, true, out bindingType))
            {
                throw new FormatException(string.Format("'{0}' is not a valid binding type.", bindingTypeValue));
            }

            if (!string.IsNullOrEmpty(connection) &&
                string.IsNullOrEmpty(Utility.GetAppSettingOrEnvironmentValue(connection)))
            {
                throw new FormatException("Invalid Connection value specified.");
            }

            switch (bindingType)
            {
            case BindingType.EventHubTrigger:
            case BindingType.EventHub:
                bindingMetadata = binding.ToObject <EventHubBindingMetadata>();
                break;

            case BindingType.QueueTrigger:
            case BindingType.Queue:
                bindingMetadata = binding.ToObject <QueueBindingMetadata>();
                break;

            case BindingType.BlobTrigger:
            case BindingType.Blob:
                bindingMetadata = binding.ToObject <BlobBindingMetadata>();
                break;

            case BindingType.ServiceBusTrigger:
            case BindingType.ServiceBus:
                bindingMetadata = binding.ToObject <ServiceBusBindingMetadata>();
                break;

            case BindingType.HttpTrigger:
                bindingMetadata = binding.ToObject <HttpTriggerBindingMetadata>();
                break;

            case BindingType.Http:
                bindingMetadata = binding.ToObject <HttpBindingMetadata>();
                break;

            case BindingType.Table:
                bindingMetadata = binding.ToObject <TableBindingMetadata>();
                break;

            case BindingType.ManualTrigger:
                bindingMetadata = binding.ToObject <BindingMetadata>();
                break;

            case BindingType.TimerTrigger:
                bindingMetadata = binding.ToObject <TimerBindingMetadata>();
                break;

            case BindingType.EasyTable:
                bindingMetadata = binding.ToObject <EasyTableBindingMetadata>();
                break;

            case BindingType.DocumentDB:
                bindingMetadata = binding.ToObject <DocumentDBBindingMetadata>();
                break;

            case BindingType.NotificationHub:
                bindingMetadata = binding.ToObject <NotificationHubBindingMetadata>();
                break;

            case BindingType.ApiHub:
            case BindingType.ApiHubTrigger:
                bindingMetadata = binding.ToObject <ApiHubBindingMetadata>();
                break;
            }

            bindingMetadata.Type       = bindingType;
            bindingMetadata.Direction  = bindingDirection;
            bindingMetadata.Connection = connection;

            nameResolver.ResolveAllProperties(bindingMetadata);

            return(bindingMetadata);
        }
コード例 #2
0
        private static BindingMetadata ParseBindingMetadata(JObject binding, INameResolver nameResolver)
        {
            BindingMetadata bindingMetadata = null;
            string bindingTypeValue = (string)binding["type"];
            string bindingDirectionValue = (string)binding["direction"];
            string connection = (string)binding["connection"];
            BindingType bindingType = default(BindingType);
            BindingDirection bindingDirection = default(BindingDirection);

            if (!string.IsNullOrEmpty(bindingDirectionValue) &&
                !Enum.TryParse<BindingDirection>(bindingDirectionValue, true, out bindingDirection))
            {
                throw new FormatException(string.Format(CultureInfo.InvariantCulture, "'{0}' is not a valid binding direction.", bindingDirectionValue));
            }

            if (!string.IsNullOrEmpty(bindingTypeValue) &&
                !Enum.TryParse<BindingType>(bindingTypeValue, true, out bindingType))
            {
                throw new FormatException(string.Format("'{0}' is not a valid binding type.", bindingTypeValue));
            }

            if (!string.IsNullOrEmpty(connection) && 
                string.IsNullOrEmpty(Utility.GetAppSettingOrEnvironmentValue(connection)))
            {
                throw new FormatException("Invalid Connection value specified.");
            }

            switch (bindingType)
            {
                case BindingType.EventHubTrigger:
                case BindingType.EventHub:
                    bindingMetadata = binding.ToObject<EventHubBindingMetadata>();
                    break;
                case BindingType.QueueTrigger:
                case BindingType.Queue:
                    bindingMetadata = binding.ToObject<QueueBindingMetadata>();
                    break;
                case BindingType.BlobTrigger:
                case BindingType.Blob:
                    bindingMetadata = binding.ToObject<BlobBindingMetadata>();
                    break;
                case BindingType.ServiceBusTrigger:
                case BindingType.ServiceBus:
                    bindingMetadata = binding.ToObject<ServiceBusBindingMetadata>();
                    break;
                case BindingType.HttpTrigger:
                    bindingMetadata = binding.ToObject<HttpTriggerBindingMetadata>();
                    break;
                case BindingType.Http:
                    bindingMetadata = binding.ToObject<HttpBindingMetadata>();
                    break;
                case BindingType.Table:
                    bindingMetadata = binding.ToObject<TableBindingMetadata>();
                    break;
                case BindingType.ManualTrigger:
                    bindingMetadata = binding.ToObject<BindingMetadata>();
                    break;
                case BindingType.TimerTrigger:
                    bindingMetadata = binding.ToObject<TimerBindingMetadata>();
                    break;
                case BindingType.EasyTable:
                    bindingMetadata = binding.ToObject<EasyTableBindingMetadata>();
                    break;
                case BindingType.DocumentDB:
                    bindingMetadata = binding.ToObject<DocumentDBBindingMetadata>();
                    break;
                case BindingType.NotificationHub:
                    bindingMetadata = binding.ToObject<NotificationHubBindingMetadata>();
                    break;
                case BindingType.ApiHub:
                case BindingType.ApiHubTrigger:
                    bindingMetadata = binding.ToObject<ApiHubBindingMetadata>();
                    break;
            }

            bindingMetadata.Type = bindingType;
            bindingMetadata.Direction = bindingDirection;
            bindingMetadata.Connection = connection;

            nameResolver.ResolveAllProperties(bindingMetadata);

            return bindingMetadata;
        }