コード例 #1
0
		public EdmValueTermReferenceExpression(IEdmExpression baseExpression, IEdmValueTerm term, string qualifier)
		{
			EdmUtil.CheckArgumentNull<IEdmExpression>(baseExpression, "baseExpression");
			EdmUtil.CheckArgumentNull<IEdmValueTerm>(term, "term");
			this.baseExpression = baseExpression;
			this.term = term;
			this.qualifier = qualifier;
		}
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EdmVocabularyAnnotation"/> class.
        /// </summary>
        /// <param name="target">Element the annotation applies to.</param>
        /// <param name="term">Term bound by the annotation.</param>
        /// <param name="qualifier">Qualifier used to discriminate between multiple bindings of the same property or type.</param>
        protected EdmVocabularyAnnotation(IEdmVocabularyAnnotatable target, IEdmValueTerm term, string qualifier)
        {
            EdmUtil.CheckArgumentNull(target, "target");
            EdmUtil.CheckArgumentNull(term, "term");

            this.target = target;
            this.term = term;
            this.qualifier = qualifier;
        }
コード例 #3
0
ファイル: MeasuresHelpers.cs プロジェクト: larsenjo/odata.net
        static MeasuresHelpers()
        {
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ODataSamples.Services.Core.Vocabularies.MeasuresVocabularies.xml"))
            {
                IEnumerable<EdmError> errors;
                CsdlReader.TryParse(new[] { XmlReader.Create(stream) }, out Instance, out errors);
            }

            ISOCurrencyTerm = Instance.FindDeclaredValueTerm(MeasuresISOCurrency);
            ScaleTerm = Instance.FindDeclaredValueTerm(MeasuresScale);
        }
コード例 #4
0
        /// <summary>
        /// Parse Capabilities Vocabulary Model from CapabilitiesVocabularies.xml
        /// </summary>
        static CapabilitiesVocabularyModel()
        {
            Assembly assembly = typeof(CapabilitiesVocabularyModel).GetAssembly();

            using (Stream stream = assembly.GetManifestResourceStream("CapabilitiesVocabularies.xml"))
            {
                IEnumerable<EdmError> errors;
                Debug.Assert(stream != null, "CapabilitiesVocabularies.xml: stream!=null");
                CsdlReader.TryParse(new[] { XmlReader.Create(stream) }, out Instance, out errors);
            }

            ChangeTrackingTerm = Instance.FindDeclaredValueTerm(CapabilitiesVocabularyConstants.ChangeTracking);
        }
コード例 #5
0
        /// <summary>
        /// Parse Alternate Keys Vocabulary Model from AlternateKeysVocabularies.xml
        /// </summary>
        static AlternateKeysVocabularyModel()
        {
            Assembly assembly = typeof(AlternateKeysVocabularyModel).GetAssembly();

            using (Stream stream = assembly.GetManifestResourceStream("AlternateKeysVocabularies.xml"))
            {
                IEnumerable<EdmError> errors;
                Debug.Assert(stream != null, "AlternateKeysVocabularies.xml: stream!=null");
                CsdlReader.TryParse(new[] { XmlReader.Create(stream) }, out Instance, out errors);
            }

            AlternateKeysTerm = Instance.FindDeclaredValueTerm(AlternateKeysVocabularyConstants.AlternateKeys);
            Debug.Assert(AlternateKeysTerm != null, "Expected Alternate Key term");

            AlternateKeyType = Instance.FindDeclaredType(AlternateKeysVocabularyConstants.AlternateKeyType) as IEdmComplexType;
            Debug.Assert(AlternateKeyType != null, "Expected Alternate Key type");

            PropertyRefType = Instance.FindDeclaredType(AlternateKeysVocabularyConstants.PropertyRefType) as IEdmComplexType;
            Debug.Assert(PropertyRefType != null, "Expected Alternate Key property ref type");
        }
コード例 #6
0
        static CapabilitiesHelpers()
        {
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ODataSamples.Services.Core.Vocabularies.CapabilitiesVocabularies.xml"))
            {
                IEnumerable<EdmError> errors;
                CsdlReader.TryParse(new[] { XmlReader.Create(stream) }, out Instance, out errors);
            }

            ConformanceLevelTerm = Instance.FindDeclaredValueTerm(CapabilitiesConformanceLevel);
            SupportedFormatsTerm = Instance.FindDeclaredValueTerm(CapabilitiesSupportedFormats);
            AsynchronousRequestsSupportedTerm = Instance.FindDeclaredValueTerm(CapabilitiesAsynchronousRequestsSupported);
            BatchContinueOnErrorSupportedTerm = Instance.FindDeclaredValueTerm(CapabilitiesBatchContinueOnErrorSupported);
            ChangeTrackingTerm = Instance.FindDeclaredValueTerm(CapabilitiesChangeTracking);
            NavigationRestrictionsTerm = Instance.FindDeclaredValueTerm(CapabilitiesNavigationRestrictions);
            FilterFunctionsTerm = Instance.FindDeclaredValueTerm(CapabilitiesFilterFunctions);
            SearchRestrictionsTerm = Instance.FindDeclaredValueTerm(CapabilitiesSearchRestrictions);
            InsertRestrictionsTerm = Instance.FindDeclaredValueTerm(CapabilitiesInsertRestrictions);
            UpdateRestrictionsTerm = Instance.FindDeclaredValueTerm(CapabilitiesUpdateRestrictions);
            DeleteRestrictionsTerm = Instance.FindDeclaredValueTerm(CapabilitiesDeleteRestrictions);
            ConformanceLevelTypeType = (IEdmEnumType)Instance.FindDeclaredType(CapabilitiesConformanceLevelType);
            NavigationTypeType = (IEdmEnumType)Instance.FindDeclaredType(CapabilitiesNavigationType);
            SearchExpressionsType = (IEdmEnumType)Instance.FindDeclaredType(CapabilitiesSearchExpressions);
        }
コード例 #7
0
		public EdmValueTermReferenceExpression(IEdmExpression baseExpression, IEdmValueTerm term) : this(baseExpression, term, null)
		{
		}
コード例 #8
0
        private static IEdmValueAnnotation FindVocabularyAnnotation(this IEdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term)
        {
            var result = default(IEdmValueAnnotation);

            var annotations = model.FindVocabularyAnnotations(target);
            if (annotations != null)
            {
                var annotation = annotations.FirstOrDefault(a => a.Term.Namespace == term.Namespace && a.Term.Name == term.Name);
                result = (IEdmValueAnnotation)annotation;
            }

            return result;
        }
コード例 #9
0
        private static void GetBooleanAndPathCollection(this IEdmModel model, IEdmEntitySet entitySet, IEdmValueTerm term, string booleanPropertyName, string pathsPropertyName, out bool? boolean, out IEnumerable<string> paths)
        {
            boolean = null;
            paths = new string[0];

            var annotation = model.FindVocabularyAnnotation(entitySet, term);
            if (annotation == null)
            {
                return;
            }

            var recordExpression = (IEdmRecordExpression)annotation.Value;
            var booleanExpression = (IEdmBooleanConstantExpression)recordExpression.Properties.Single(p => p.Name == booleanPropertyName).Value;
            var collectionExpression = (IEdmCollectionExpression)recordExpression.Properties.Single(p => p.Name == pathsPropertyName).Value;
            var pathsTemp = new List<string>();

            foreach (IEdmPathExpression pathExpression in collectionExpression.Elements)
            {
                var pathBuilder = new StringBuilder();
                foreach (var path in pathExpression.Path)
                {
                    pathBuilder.AppendFormat("{0}.", path);
                }

                pathBuilder.Remove(pathBuilder.Length - 1, 1);

                pathsTemp.Add(paths.ToString());
            }

            boolean = booleanExpression.Value;
            paths = pathsTemp;
        }
コード例 #10
0
 private static void SetCapabilitiesAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term, bool value)
 {
     var expression = new EdmBooleanConstant(value);
     var annotation = new EdmAnnotation(target, term, expression);
     annotation.SetSerializationLocation(model, target.ToSerializationLocation());
     model.AddVocabularyAnnotation(annotation);
 }
コード例 #11
0
        private static void SetCapabilitiesAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term, IEnumerable<string> values)
        {
            if (values == null)
            {
                values = new string[0];
            }

            var expression = new EdmCollectionExpression(values.Select(function => new EdmStringConstant(function)));
            var annotation = new EdmAnnotation(target, term, expression);
            annotation.SetSerializationLocation(model, target.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
コード例 #12
0
        private static void SetCapabilitiesAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term, bool value, IEnumerable<IEdmNavigationProperty> navigationProperties, string name1, string name2)
        {
            if (navigationProperties == null)
            {
                navigationProperties = new IEdmNavigationProperty[0];
            }

            var properties = new IEdmPropertyConstructor[]
            {
                new EdmPropertyConstructor(name1, new EdmBooleanConstant(value)),
                new EdmPropertyConstructor(name2, new EdmCollectionExpression(navigationProperties.Select(p => new EdmNavigationPropertyPathExpression(p.Name)))),
            };
            var record = new EdmRecordExpression(properties);

            var annotation = new EdmAnnotation(target, term, record);
            annotation.SetSerializationLocation(model, target.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
コード例 #13
0
        internal static IEdmValueTerm CreateAmbiguousValueTermBinding(IEdmValueTerm first, IEdmValueTerm second)
        {
            var ambiguous = first as AmbiguousValueTermBinding;

            if (ambiguous != null)
            {
                ambiguous.AddBinding(second);
                return(ambiguous);
            }

            return(new AmbiguousValueTermBinding(first, second));
        }
コード例 #14
0
        private void CompareValueTerm(IEdmValueTerm expectedValueTerm, IEdmValueTerm actualValueTerm)
        {
            // TODO: can we push type reference equals into product? 
            this.SatisfiesCondition(
                this.EdmTypeReferenceEquals(expectedValueTerm.Type, actualValueTerm.Type),
                "Type of ValueTerm {0} in {1} not Equal.",
                expectedValueTerm.Name,
                expectedValueTerm.Namespace);

            this.CompareTermAnnotations(expectedValueTerm, actualValueTerm);
        }
コード例 #15
0
 private IEdmVocabularyAnnotation CreateAndAttachValueAnnotation(IEdmVocabularyAnnotatable target, IEdmValueTerm term, IEdmExpression value)
 {
     return this.CreateAndAttachValueAnnotation(target, term, value, null);
 }
コード例 #16
0
ファイル: EdmAnnotation.cs プロジェクト: larsenjo/odata.net
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmAnnotation"/> class.
 /// </summary>
 /// <param name="target">Element the annotation applies to.</param>
 /// <param name="term">Term bound by the annotation.</param>
 /// <param name="qualifier">Qualifier used to discriminate between multiple bindings of the same property or type.</param>
 /// <param name="value">Expression producing the value of the annotation.</param>
 public EdmAnnotation(IEdmVocabularyAnnotatable target, IEdmValueTerm term, string qualifier, IEdmExpression value)
     : base(target, term, qualifier)
 {
     EdmUtil.CheckArgumentNull(value, "value");
     this.value = value;
 }
コード例 #17
0
ファイル: EdmAnnotation.cs プロジェクト: larsenjo/odata.net
 /// <summary>
 /// Initializes a new instance of the <see cref="EdmAnnotation"/> class.
 /// </summary>
 /// <param name="target">Element the annotation applies to.</param>
 /// <param name="term">Term bound by the annotation.</param>
 /// <param name="value">Expression producing the value of the annotation.</param>
 public EdmAnnotation(IEdmVocabularyAnnotatable target, IEdmValueTerm term, IEdmExpression value)
     : this(target, term, null, value)
 {
 }
コード例 #18
0
        /// <summary>
        /// Parse Core Vocabulary Model from CoreVocabularies.xml
        /// </summary>
        static CoreVocabularyModel()
        {
            IsInitializing = true;
            Assembly assembly = typeof(CoreVocabularyModel).GetAssembly();

            using (Stream stream = assembly.GetManifestResourceStream("CoreVocabularies.xml"))
            {
                IEnumerable<EdmError> errors;
                Debug.Assert(stream != null, "CoreVocabularies.xml: stream!=null");
                CsdlReader.TryParse(new[] { XmlReader.Create(stream) }, out Instance, out errors);
                IsInitializing = false;
            }

            AcceptableMediaTypesTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.AcceptableMediaTypes);
            ComputedTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.Computed);
            ConcurrencyControlTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.OptimisticConcurrencyControl);
            ConcurrencyTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.OptimisticConcurrency);
            ConventionalIDsTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.ConventionalIDs);
            DereferenceableIDsTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.DereferenceableIDs);
            DescriptionTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.Description);
            ImmutableTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.Immutable);
            IsLanguageDependentTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.IsLanguageDependent);
            IsMediaTypeTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.IsMediaType);
            IsURLTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.IsURL);
            LongDescriptionTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.LongDescription);
            MediaTypeTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.MediaType);
            RequiresTypeTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.RequiresType);
            ResourcePathTerm = Instance.FindDeclaredValueTerm(CoreVocabularyConstants.ResourcePath);
        }
コード例 #19
0
        private IEdmVocabularyAnnotatable ComputeTarget()
        {
            if (this.targetContext != null)
            {
                return(this.targetContext);
            }
            else
            {
                Debug.Assert(this.annotationsContext != null, "Annotation must either have a target context or annotations context");
                string              target              = this.annotationsContext.Annotations.Target;
                string[]            targetSegments      = target.Split('/');
                int                 targetSegmentsCount = targetSegments.Count();
                IEdmEntityContainer container;

                if (targetSegmentsCount == 1)
                {
                    string         elementName = targetSegments[0];
                    IEdmSchemaType type        = this.schema.FindType(elementName);
                    if (type != null)
                    {
                        return(type);
                    }

                    IEdmValueTerm term = this.schema.FindValueTerm(elementName);
                    if (term != null)
                    {
                        return(term);
                    }

                    IEdmFunction function = this.FindParameterizedFunction(elementName, this.Schema.FindFunctions, this.CreateAmbiguousFunction);
                    if (function != null)
                    {
                        return(function);
                    }

                    container = this.schema.FindEntityContainer(elementName);
                    if (container != null)
                    {
                        return(container);
                    }

                    return(new UnresolvedType(this.Schema.UnresolvedName(targetSegments[0]), this.Location));
                }

                if (targetSegmentsCount == 2)
                {
                    container = this.schema.FindEntityContainer(targetSegments[0]);
                    if (container != null)
                    {
                        IEdmEntityContainerElement containerElement = container.FindEntitySet(targetSegments[1]);
                        if (containerElement != null)
                        {
                            return(containerElement);
                        }

                        IEdmFunctionImport functionImport = this.FindParameterizedFunction(targetSegments[1], container.FindFunctionImports, this.CreateAmbiguousFunctionImport);
                        if (functionImport != null)
                        {
                            return(functionImport);
                        }

                        return(new UnresolvedEntitySet(targetSegments[1], container, this.Location));
                    }

                    IEdmStructuredType type = this.schema.FindType(targetSegments[0]) as IEdmStructuredType;
                    if (type != null)
                    {
                        IEdmProperty property = type.FindProperty(targetSegments[1]);
                        if (property != null)
                        {
                            return(property);
                        }

                        return(new UnresolvedProperty(type, targetSegments[1], this.Location));
                    }

                    IEdmFunction function = this.FindParameterizedFunction(targetSegments[0], this.Schema.FindFunctions, this.CreateAmbiguousFunction);
                    if (function != null)
                    {
                        IEdmFunctionParameter parameter = function.FindParameter(targetSegments[1]);
                        if (parameter != null)
                        {
                            return(parameter);
                        }

                        return(new UnresolvedParameter(function, targetSegments[1], this.Location));
                    }

                    return(new UnresolvedProperty(new UnresolvedEntityType(this.Schema.UnresolvedName(targetSegments[0]), this.Location), targetSegments[1], this.Location));
                }

                if (targetSegmentsCount == 3)
                {
                    // The only valid target with three segments is a function parameter.
                    string containerName = targetSegments[0];
                    string functionName  = targetSegments[1];
                    string parameterName = targetSegments[2];

                    container = this.Model.FindEntityContainer(containerName);
                    if (container != null)
                    {
                        IEdmFunctionImport functionImport = this.FindParameterizedFunction(functionName, container.FindFunctionImports, this.CreateAmbiguousFunctionImport);
                        if (functionImport != null)
                        {
                            IEdmFunctionParameter parameter = functionImport.FindParameter(parameterName);
                            if (parameter != null)
                            {
                                return(parameter);
                            }

                            return(new UnresolvedParameter(functionImport, parameterName, this.Location));
                        }
                    }

                    string             qualifiedFunctionName = containerName + "/" + functionName;
                    UnresolvedFunction unresolvedFunction    = new UnresolvedFunction(qualifiedFunctionName, Edm.Strings.Bad_UnresolvedFunction(qualifiedFunctionName), this.Location);
                    return(new UnresolvedParameter(unresolvedFunction, parameterName, this.Location));
                }

                return(new BadElement(new EdmError[] { new EdmError(this.Location, EdmErrorCode.ImpossibleAnnotationsTarget, Edm.Strings.CsdlSemantics_ImpossibleAnnotationsTarget(target)) }));
            }
        }
コード例 #20
0
        private IEdmVocabularyAnnotation CreateAndAttachValueAnnotation(IEdmVocabularyAnnotatable target, IEdmValueTerm term, IEdmExpression value, string qualifier)
        {
            var annotation = new EdmAnnotation(
                target,
                term,
                qualifier,
                value);

            // ?? Unnatural API
            ((EdmModel)this.baseModel).AddVocabularyAnnotation(annotation);
            return annotation;
        }
コード例 #21
0
ファイル: EdmModelVisitor.cs プロジェクト: zdzislaw/odata.net
 protected virtual void ProcessValueTerm(IEdmValueTerm term)
 {
     this.ProcessSchemaElement(term);
     this.ProcessTerm(term);
     this.VisitTypeReference(term.Type);
 }