示例#1
0
        private static bool TryCastDateConstantAsType(IEdmDateConstantExpression expression, IEdmTypeReference type, out IEnumerable <EdmError> discoveredErrors)
        {
            if (!type.IsDate())
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType) };
                return(false);
            }

            discoveredErrors = Enumerable.Empty <EdmError>();
            return(true);
        }
示例#2
0
 protected override void ProcessDateConstantExpression(IEdmDateConstantExpression expression)
 {
     this.schemaWriter.WriteDateConstantExpressionElement(expression);
 }
 internal void WriteDateConstantExpressionElement(IEdmDateConstantExpression expression)
 {
     this.xmlWriter.WriteStartElement(CsdlConstants.Element_Date);
     this.xmlWriter.WriteString(EdmValueWriter.DateAsXml(expression.Value));
     this.WriteEndElement();
 }
        private static bool TryCastDateConstantAsType(IEdmDateConstantExpression expression, IEdmTypeReference type, out IEnumerable<EdmError> discoveredErrors)
        {
            if (!type.IsDate())
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindNotValidForAssertedType) };
                return false;
            }

            discoveredErrors = Enumerable.Empty<EdmError>();
            return true;
        }
示例#5
0
 protected virtual void ProcessDateConstantExpression(IEdmDateConstantExpression expression)
 {
     this.ProcessExpression(expression);
 }
 internal abstract void WriteDateConstantExpressionElement(IEdmDateConstantExpression expression);
示例#7
0
        /// <summary>
        /// Given a model element, see if it is marked as deprecated.
        /// </summary>
        /// <param name="model">The model containing the element</param>
        /// <param name="element">The IEdmElement to be validated to see if it's marked as deprecated.</param>
        /// <param name="message">The returned deprecation message if the element is deprecated.</param>
        /// <param name="version">The returned version if the element is deprecated, if specified.</param>
        /// <param name="date">The returned date if the element is deprecated, if specified.</param>
        /// <param name="removalDate">The returned removal date if the element is deprecated, if specified.</param>
        /// <returns>True if the element is marked as deprecated, otherwise false.</returns>
        private static bool IsDeprecated(IEdmModel model, IEdmElement element, out string message, out string version, out Date?date, out Date?removalDate)
        {
            if (!(element is IEdmPrimitiveType))
            {
                IEdmVocabularyAnnotatable annotatedElement = element as IEdmVocabularyAnnotatable;
                if (annotatedElement != null)
                {
                    foreach (IEdmVocabularyAnnotation annotation in GetRevisionAnnotations(model, annotatedElement))
                    {
                        IEdmCollectionExpression collectionExpression = annotation.Value as IEdmCollectionExpression;
                        if (collectionExpression != null)
                        {
                            foreach (IEdmExpression versionRecord in collectionExpression.Elements)
                            {
                                bool isDeprecated = false;
                                message     = string.Empty;
                                version     = string.Empty;
                                date        = null;
                                removalDate = null;
                                IEdmRecordExpression record = versionRecord as IEdmRecordExpression;
                                if (record != null)
                                {
                                    foreach (IEdmPropertyConstructor property in record.Properties)
                                    {
                                        switch (property.Name)
                                        {
                                        case RevisionKindProperty:
                                            IEdmEnumMemberExpression enumValue = property.Value as IEdmEnumMemberExpression;
                                            if (enumValue != null)
                                            {
                                                if (string.Equals(enumValue.EnumMembers.FirstOrDefault().Name, RevisionKindDeprecated, StringComparison.OrdinalIgnoreCase))
                                                {
                                                    isDeprecated = true;
                                                }
                                                else
                                                {
                                                    continue;
                                                }
                                            }

                                            break;

                                        case RevisionVersionProperty:
                                            IEdmStringConstantExpression versionValue = property.Value as IEdmStringConstantExpression;
                                            if (versionValue != null)
                                            {
                                                version = versionValue.Value;
                                            }

                                            break;

                                        case RevisionDescriptionProperty:
                                            IEdmStringConstantExpression descriptionValue = property.Value as IEdmStringConstantExpression;
                                            if (descriptionValue != null)
                                            {
                                                message = descriptionValue.Value;
                                            }

                                            break;

                                        case RevisionDateProperty:
                                            IEdmDateConstantExpression dateValue = property.Value as IEdmDateConstantExpression;
                                            if (dateValue != null)
                                            {
                                                date = dateValue.Value;
                                            }

                                            break;

                                        case RevisionRemovalDateProperty:
                                            IEdmDateConstantExpression removalDateValue = property.Value as IEdmDateConstantExpression;
                                            if (removalDateValue != null)
                                            {
                                                removalDate = removalDateValue.Value;
                                            }

                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                }

                                if (isDeprecated)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            message = version = string.Empty;
            date    = removalDate = null;
            return(false);
        }
示例#8
0
        /// <summary>
        /// Convert an <see cref="IEdmExpression"/> to a <see cref="ODataValue"/>
        /// </summary>
        /// <param name="expression">The <see cref="IEdmExpression"/>.</param>
        /// <returns>The null or <see cref="ODataValue"/>.</returns>
        public static ODataValue Convert(this IEdmExpression expression)
        {
            if (expression == null)
            {
                return(null);
            }

            switch (expression.ExpressionKind)
            {
            case EdmExpressionKind.BinaryConstant:
                IEdmBinaryConstantExpression binaryConstant = (IEdmBinaryConstantExpression)expression;
                return(new ODataPrimitiveValue(binaryConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetBinary(false)
                });

            case EdmExpressionKind.BooleanConstant:
                IEdmBooleanConstantExpression booleanConstant = (IEdmBooleanConstantExpression)expression;
                return(new ODataPrimitiveValue(booleanConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetBoolean(false)
                });

            case EdmExpressionKind.DateTimeOffsetConstant:
                IEdmDateTimeOffsetConstantExpression dateTimeOffsetConstant = (IEdmDateTimeOffsetConstantExpression)expression;
                return(new ODataPrimitiveValue(dateTimeOffsetConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetDateTimeOffset(false)
                });

            case EdmExpressionKind.DecimalConstant:
                IEdmDecimalConstantExpression decimalConstant = (IEdmDecimalConstantExpression)expression;
                return(new ODataPrimitiveValue(decimalConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetDecimal(false)
                });

            case EdmExpressionKind.FloatingConstant:
                IEdmFloatingConstantExpression floatConstant = (IEdmFloatingConstantExpression)expression;
                return(new ODataPrimitiveValue(floatConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetDouble(false)
                });

            case EdmExpressionKind.GuidConstant:
                IEdmGuidConstantExpression guidConstant = (IEdmGuidConstantExpression)expression;
                return(new ODataPrimitiveValue(guidConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetGuid(false)
                });

            case EdmExpressionKind.IntegerConstant:
                IEdmIntegerConstantExpression integerConstant = (IEdmIntegerConstantExpression)expression;
                return(new ODataPrimitiveValue(integerConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetInt64(false)
                });

            case EdmExpressionKind.StringConstant:
                IEdmStringConstantExpression stringConstant = (IEdmStringConstantExpression)expression;
                return(new ODataPrimitiveValue(stringConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetString(false)
                });

            case EdmExpressionKind.DurationConstant:
                IEdmDurationConstantExpression durationConstant = (IEdmDurationConstantExpression)expression;
                return(new ODataPrimitiveValue(durationConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetDuration(false)
                });

            case EdmExpressionKind.TimeOfDayConstant:
                IEdmTimeOfDayConstantExpression timeOfDayConstant = (IEdmTimeOfDayConstantExpression)expression;
                return(new ODataPrimitiveValue(timeOfDayConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetTimeOfDay(false)
                });

            case EdmExpressionKind.DateConstant:
                IEdmDateConstantExpression dateConstant = (IEdmDateConstantExpression)expression;
                return(new ODataPrimitiveValue(dateConstant.Value)
                {
                    TypeReference = EdmCoreModel.Instance.GetDate(false)
                });

            case EdmExpressionKind.Record:
                IEdmRecordExpression recordExpression = (IEdmRecordExpression)expression;
                return(new ODataResourceValue
                {
                    TypeReference = recordExpression.DeclaredType,
                    Properties = recordExpression.Properties.ToDictionary(p => p.Name, p => p.Value.Convert())
                });

            case EdmExpressionKind.Collection:
                IEdmCollectionExpression collectionExpression = (IEdmCollectionExpression)expression;
                ODataCollectValue        collectionValue      = new ODataCollectValue
                {
                    TypeReference = collectionExpression.DeclaredType
                };

                collectionValue.Elements = collectionExpression.Elements.Select(e => e.Convert()).ToList();
                return(collectionValue);

            case EdmExpressionKind.Path:
            case EdmExpressionKind.PropertyPath:
            case EdmExpressionKind.NavigationPropertyPath:
            case EdmExpressionKind.EnumMember:
            default:
                throw new NotSupportedException(String.Format(SRResource.NotSupportedEdmExpressionKind, expression.ExpressionKind));
            }
        }