internal static void ConvertCustomAnnotations(MetadataProviderEdmModel model, IEnumerable <KeyValuePair <string, object> > customAnnotations, IEdmElement target)
 {
     foreach (IEdmDirectValueAnnotation annotation in ConvertCustomAnnotations(model, customAnnotations))
     {
         model.SetAnnotationValue(target, annotation.NamespaceUri, annotation.Name, annotation.Value);
     }
 }
 internal MetadataProviderEdmEntityContainer(MetadataProviderEdmModel model, string containerName, string entityContainerSchemaNamespace)
 {
     this.model = model;
     this.containerName = containerName;
     this.containerNamespace = entityContainerSchemaNamespace;
     this.entitySetCache = new Dictionary<string, IEdmEntitySet>(StringComparer.Ordinal);
     this.functionImportCache = new Dictionary<string, List<MetadataProviderEdmFunctionImport>>(StringComparer.Ordinal);
 }
 internal MetadataProviderEdmEntityContainer(MetadataProviderEdmModel model, string containerName, string entityContainerSchemaNamespace)
 {
     this.model               = model;
     this.containerName       = containerName;
     this.containerNamespace  = entityContainerSchemaNamespace;
     this.entitySetCache      = new Dictionary <string, IEdmEntitySet>(StringComparer.Ordinal);
     this.functionImportCache = new Dictionary <string, List <MetadataProviderEdmFunctionImport> >(StringComparer.Ordinal);
 }
示例#4
0
        internal MetadataProviderEdmModel GetMetadataProviderEdmModel(DataServiceOperationContext operationContext)
        {
            MetadataProviderEdmModel model;

            if (!this.metadataProviderEdmModels.TryGetValue(operationContext, out model))
            {
                model = new MetadataProviderEdmModel(this, operationContext, this.dataService.StreamProvider);
                this.metadataProviderEdmModels[operationContext] = model;
            }
            return(model);
        }
        internal MetadataProviderEdmFunctionImport(MetadataProviderEdmModel model, MetadataProviderEdmEntityContainer container, OperationWrapper operation)
        {
            this.container = container;
            this.model     = model;
            this.operation = operation;
            if (operation.Kind == OperationKind.Action)
            {
                this.isSideEffecting = true;
                this.isComposable    = false;
                this.isBindable      = this.operation.BindingParameter != null;
            }
            else
            {
                this.isComposable    = false;
                this.isSideEffecting = true;
                this.isBindable      = false;
            }
            ResourceSetPathExpression resultSetPathExpression = operation.ResultSetPathExpression;

            this.entitySetPath = (resultSetPathExpression == null) ? null : resultSetPathExpression.PathExpression;
            if (operation.Kind == OperationKind.ServiceOperation)
            {
                model.SetHttpMethod(this, operation.Method);
            }
            string mimeType = operation.MimeType;

            if (!string.IsNullOrEmpty(mimeType))
            {
                model.SetMimeType(this, mimeType);
            }
            if (operation.OperationParameterBindingKind == OperationParameterBindingKind.Always)
            {
                model.SetIsAlwaysBindable(this, true);
            }
            ReadOnlyCollection <OperationParameter> parameters = operation.Parameters;

            if ((parameters != null) && (parameters.Count > 0))
            {
                List <IEdmFunctionParameter> list = new List <IEdmFunctionParameter>(parameters.Count);
                foreach (OperationParameter parameter in parameters)
                {
                    IEdmTypeReference typeReference = this.model.EnsureTypeReference(parameter.ParameterType, null);
                    if (!typeReference.IsNullable && (this.model.GetEdmVersion() < DataServiceProtocolVersion.V3.ToVersion()))
                    {
                        typeReference = typeReference.Clone(true);
                    }
                    EdmFunctionParameter item = new EdmFunctionParameter(this, parameter.Name, typeReference, EdmFunctionParameterMode.In);
                    list.Add(item);
                }
                this.parameters = new ReadOnlyCollection <IEdmFunctionParameter>(list);
            }
        }
        internal static void ConvertEntityPropertyMappings(MetadataProviderEdmModel model, ResourceType resourceType, EdmEntityType entityType)
        {
            IEnumerable <EntityPropertyMappingAttribute> allEpmInfo = resourceType.AllEpmInfo;

            if (allEpmInfo != null)
            {
                ODataEntityPropertyMappingCollection mappings = new ODataEntityPropertyMappingCollection();
                foreach (EntityPropertyMappingAttribute attribute in allEpmInfo)
                {
                    mappings.Add(attribute);
                }
                model.SetAnnotationValue <ODataEntityPropertyMappingCollection>(entityType, mappings);
            }
        }
 internal MetadataProviderEdmFunctionImport(MetadataProviderEdmModel model, MetadataProviderEdmEntityContainer container, OperationWrapper operation)
 {
     this.container = container;
     this.model = model;
     this.operation = operation;
     if (operation.Kind == OperationKind.Action)
     {
         this.isSideEffecting = true;
         this.isComposable = false;
         this.isBindable = this.operation.BindingParameter != null;
     }
     else
     {
         this.isComposable = false;
         this.isSideEffecting = true;
         this.isBindable = false;
     }
     ResourceSetPathExpression resultSetPathExpression = operation.ResultSetPathExpression;
     this.entitySetPath = (resultSetPathExpression == null) ? null : resultSetPathExpression.PathExpression;
     if (operation.Kind == OperationKind.ServiceOperation)
     {
         model.SetHttpMethod(this, operation.Method);
     }
     string mimeType = operation.MimeType;
     if (!string.IsNullOrEmpty(mimeType))
     {
         model.SetMimeType(this, mimeType);
     }
     if (operation.OperationParameterBindingKind == OperationParameterBindingKind.Always)
     {
         model.SetIsAlwaysBindable(this, true);
     }
     ReadOnlyCollection<OperationParameter> parameters = operation.Parameters;
     if ((parameters != null) && (parameters.Count > 0))
     {
         List<IEdmFunctionParameter> list = new List<IEdmFunctionParameter>(parameters.Count);
         foreach (OperationParameter parameter in parameters)
         {
             IEdmTypeReference typeReference = this.model.EnsureTypeReference(parameter.ParameterType, null);
             if (!typeReference.IsNullable && (this.model.GetEdmVersion() < DataServiceProtocolVersion.V3.ToVersion()))
             {
                 typeReference = typeReference.Clone(true);
             }
             EdmFunctionParameter item = new EdmFunctionParameter(this, parameter.Name, typeReference, EdmFunctionParameterMode.In);
             list.Add(item);
         }
         this.parameters = new ReadOnlyCollection<IEdmFunctionParameter>(list);
     }
 }
 internal static IEnumerable <IEdmDirectValueAnnotation> ConvertCustomAnnotations(MetadataProviderEdmModel model, IEnumerable <KeyValuePair <string, object> > customAnnotations)
 {
     if (customAnnotations != null)
     {
         foreach (KeyValuePair <string, object> iteratorVariable0 in customAnnotations)
         {
             object iteratorVariable1 = iteratorVariable0.Value;
             Type   iteratorVariable2 = (iteratorVariable1 == null) ? null : iteratorVariable1.GetType();
             bool   iteratorVariable3 = iteratorVariable2 == typeof(XElement);
             int    length            = iteratorVariable0.Key.LastIndexOf(":", StringComparison.Ordinal);
             if (length == -1)
             {
                 if (!iteratorVariable3)
                 {
                     string iteratorVariable5 = ConvertAttributeAnnotationValue(iteratorVariable0.Value);
                     yield return(new EdmDirectValueAnnotation(string.Empty, iteratorVariable0.Key, new EdmStringConstant(EdmCoreModel.Instance.GetString(true), iteratorVariable5)));
                 }
             }
             else
             {
                 string namespaceUri = iteratorVariable0.Key.Substring(0, length);
                 string name         = iteratorVariable0.Key.Substring(length + 1);
                 if ((iteratorVariable1 == null) || !iteratorVariable3)
                 {
                     string iteratorVariable8 = ConvertAttributeAnnotationValue(iteratorVariable0.Value);
                     yield return(new EdmDirectValueAnnotation(namespaceUri, name, new EdmStringConstant(EdmCoreModel.Instance.GetString(true), iteratorVariable8)));
                 }
                 else if ((iteratorVariable1 != null) && (iteratorVariable2 == typeof(XElement)))
                 {
                     XElement          xmlElement         = (XElement)iteratorVariable1;
                     string            iteratorVariable10 = CreateElementAnnotationStringRepresentation(xmlElement);
                     EdmStringConstant iteratorVariable11 = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), iteratorVariable10);
                     iteratorVariable11.SetIsSerializedAsElement(model, true);
                     yield return(new EdmDirectValueAnnotation(namespaceUri, name, iteratorVariable11));
                 }
             }
         }
     }
 }