示例#1
0
文件: source.cs 项目: winxxp/samples
        static void StructuralTypeVisitRecord(IExtendedDataRecord record)
        {
            int fieldCount = record.DataRecordInfo.FieldMetadata.Count;

            for (int fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++)
            {
                Console.Write(record.GetName(fieldIndex) + ": ");

                // If the field is flagged as DbNull, the shape of the value is undetermined.
                // An attempt to get such a value may trigger an exception.
                if (record.IsDBNull(fieldIndex) == false)
                {
                    BuiltInTypeKind fieldTypeKind = record.DataRecordInfo.FieldMetadata[fieldIndex].
                                                    FieldType.TypeUsage.EdmType.BuiltInTypeKind;
                    // The EntityType, ComplexType and RowType are structural types
                    // that have members.
                    // Read only the PrimitiveType members of this structural type.
                    if (fieldTypeKind == BuiltInTypeKind.PrimitiveType)
                    {
                        // Primitive types are surfaced as plain objects.
                        Console.WriteLine(record.GetValue(fieldIndex).ToString());
                    }
                }
            }
        }
示例#2
0
        private static XmlElement GetElementForKind(XmlDocument document, BuiltInTypeKind kind)
        {
            Debug.Assert(document != null, "document != null");
            string xpath;

            switch (kind)
            {
            case BuiltInTypeKind.EdmProperty:
                xpath = "/csdl1:Schema/csdl1:EntityType[@Name='Customers']/csdl1:Property[@Name='CompanyName']";
                break;

            case BuiltInTypeKind.EntityContainer:
                xpath = "/csdl1:Schema/csdl1:EntityContainer";
                break;

            case BuiltInTypeKind.EntityType:
                xpath = "/csdl1:Schema/csdl1:EntityType[@Name='Customers']";
                break;

            case BuiltInTypeKind.EdmFunction:
            default:
                throw new NotSupportedException("Built in type kind not supported: " + kind);
            }
            return((XmlElement)document.SelectSingleNode(xpath, TestUtil.TestNamespaceManager));
        }
示例#3
0
        public static ArmType?AsArmType(this BuiltInTypeKind builtinType)
        {
            switch (builtinType)
            {
            case BuiltInTypeKind.Any:
                return(null);

            case BuiltInTypeKind.Array:
                return(ArmType.Array);

            case BuiltInTypeKind.Bool:
                return(ArmType.Bool);

            case BuiltInTypeKind.Int:
                return(ArmType.Int);

            case BuiltInTypeKind.Null:
                return(ArmType.Null);

            case BuiltInTypeKind.Object:
                return(ArmType.Object);

            case BuiltInTypeKind.ResourceRef:
                return(null);

            case BuiltInTypeKind.String:
                return(ArmType.String);

            default:
                throw new ArgumentException($"Unknown ARM builtin type: '{builtinType}'");
            }
        }
示例#4
0
        public static string AsPowerShellTypeString(this BuiltInTypeKind builtinType)
        {
            switch (builtinType)
            {
            case BuiltInTypeKind.Object:
            case BuiltInTypeKind.Null:
            case BuiltInTypeKind.Any:
            case BuiltInTypeKind.ResourceRef:
                return("object");

            case BuiltInTypeKind.Array:
                return("array");

            case BuiltInTypeKind.Bool:
                return("bool");

            case BuiltInTypeKind.Int:
                return("int");

            case BuiltInTypeKind.String:
                return("string");

            default:
                throw new ArgumentException($"Unknown ARM builtin type: '{builtinType}'");
            }
        }
示例#5
0
文件: source.cs 项目: winxxp/samples
        static void RefTypeVisitRecord(IExtendedDataRecord record)
        {
            // For RefType the record contains exactly one field.
            int fieldIndex = 0;

            // If the field is flagged as DbNull, the shape of the value is undetermined.
            // An attempt to get such a value may trigger an exception.
            if (record.IsDBNull(fieldIndex) == false)
            {
                BuiltInTypeKind fieldTypeKind = record.DataRecordInfo.FieldMetadata[fieldIndex].
                                                FieldType.TypeUsage.EdmType.BuiltInTypeKind;
                //read only fields that contain PrimitiveType
                if (fieldTypeKind == BuiltInTypeKind.RefType)
                {
                    // Ref types are surfaced as EntityKey instances.
                    // The containing record sees them as atomic.
                    EntityKey key = record.GetValue(fieldIndex) as EntityKey;
                    // Get the EntitySet name.
                    Console.WriteLine("EntitySetName " + key.EntitySetName);
                    // Get the Name and the Value information of the EntityKey.
                    foreach (EntityKeyMember keyMember in key.EntityKeyValues)
                    {
                        Console.WriteLine("   Key Name: " + keyMember.Key);
                        Console.WriteLine("   Key Value: " + keyMember.Value);
                    }
                }
            }
        }
示例#6
0
        private bool TryGetTypeNameForBuiltin(BuiltInTypeKind kind, out string typeName)
        {
            switch (kind)
            {
            case BuiltInTypeKind.Array:
                typeName = "array";
                return(true);

            case BuiltInTypeKind.Bool:
                typeName = "bool";
                return(true);

            case BuiltInTypeKind.Int:
                typeName = "int";
                return(true);

            case BuiltInTypeKind.String:
                typeName = "string";
                return(true);

            default:
                typeName = null;
                return(false);
            }
        }
示例#7
0
        public IEnumerable <GlobalItem> GetSourceTypes()
        {
            foreach (EntityContainer container in _edmItemCollection.GetItems <EntityContainer>())
            {
                BuiltInTypeKind kind = container.BuiltInTypeKind;
                yield return(container);
            }

            foreach (EdmType item in _edmItemCollection.GetItems <EdmType>())
            {
                switch (item.BuiltInTypeKind)
                {
                case BuiltInTypeKind.AssociationType:
                case BuiltInTypeKind.ComplexType:
                case BuiltInTypeKind.EntityType:
                    yield return(item);

                    break;

                case BuiltInTypeKind.EdmFunction:
                case BuiltInTypeKind.PrimitiveType:
                    break;

                default:
                    Debug.Assert(false, item.BuiltInTypeKind.ToString());
                    break;
                }
            }
        }
示例#8
0
        private void GenerateFieldInfos(DbSetInfo dbSetInfo, string[] keys, EdmProperty[] edmProps)
        {
            short pkNum = 0;

            Array.ForEach(edmProps, (edmProp) =>
            {
                Field fieldInfo = new Field()
                {
                    fieldName = edmProp.Name
                };
                if (keys.Contains(fieldInfo.fieldName))
                {
                    ++pkNum;
                    fieldInfo.isPrimaryKey = pkNum;
                    fieldInfo.isReadOnly   = true;
                }
                bool isComputed           = this.isComputed(edmProp);
                fieldInfo.isAutoGenerated = isAutoGenerated(edmProp);
                fieldInfo.isNullable      = edmProp.Nullable;
                fieldInfo.isReadOnly      = fieldInfo.isAutoGenerated;
                bool isArray    = false;
                string propType = edmProp.TypeUsage.EdmType.Name;
                try
                {
                    fieldInfo.dataType = DataTypeFromType(propType, out isArray);
                    ReadOnlyMetadataCollection <Facet> facets = edmProp.TypeUsage.Facets;
                    Facet maxLenFacet = facets.Where(f => f.Name == "MaxLength").FirstOrDefault();
                    if (maxLenFacet != null)
                    {
                        try
                        {
                            fieldInfo.maxLength = (short)Convert.ChangeType(maxLenFacet.Value, typeof(short));
                        }
                        catch
                        {
                        }
                    }
                    //gess that the property is rowversion
                    fieldInfo.fieldType = (isComputed && fieldInfo.dataType == DataType.Binary) ? FieldType.RowTimeStamp : FieldType.None;
                }
                catch (UnSupportedTypeException)
                {
                    BuiltInTypeKind typeKind = edmProp.TypeUsage.EdmType.BuiltInTypeKind;
                    if (typeKind == BuiltInTypeKind.ComplexType)
                    {
                        fieldInfo.dataType  = DataType.None;
                        fieldInfo.fieldType = FieldType.Object;
                    }
                    else
                    {
                        throw;
                    }
                }

                dbSetInfo.fieldInfos.Add(fieldInfo);
            });
        }
        // <summary>
        // Add properties for all the build in complex type
        // </summary>
        // <param name="builtInTypeKind"> The type of the built In type whose properties are being added </param>
        // <param name="properties"> properties of the built in type </param>
        private static void AddBuiltInTypeProperties(BuiltInTypeKind builtInTypeKind, EdmProperty[] properties)
        {
            var complexType = (ComplexType)GetBuiltInType(builtInTypeKind);

            if (properties != null)
            {
                for (var i = 0; i < properties.Length; i++)
                {
                    complexType.AddMember(properties[i]);
                }
            }
        }
        private static void InitializeEnumType(
            BuiltInTypeKind builtInTypeKind,
            string name,
            string[] enumMemberNames)
        {
            EnumType builtInType = (EnumType)MetadataItem.GetBuiltInType(builtInTypeKind);

            EdmType.Initialize((EdmType)builtInType, name, "Edm", DataSpace.CSpace, false, (EdmType)null);
            for (int index = 0; index < enumMemberNames.Length; ++index)
            {
                builtInType.AddMember(new EnumMember(enumMemberNames[index], (object)index));
            }
        }
        private static void AddBuiltInTypeProperties(
            BuiltInTypeKind builtInTypeKind,
            EdmProperty[] properties)
        {
            ComplexType builtInType = (ComplexType)MetadataItem.GetBuiltInType(builtInTypeKind);

            if (properties == null)
            {
                return;
            }
            for (int index = 0; index < properties.Length; ++index)
            {
                builtInType.AddMember((EdmMember)properties[index]);
            }
        }
示例#12
0
        /// <summary>
        /// Initializes the enum type
        /// </summary>
        /// <param name="builtInTypeKind">The built-in type kind enum value of this enum type</param>
        /// <param name="name">The name of this enum type</param>
        /// <param name="enumMemberNames">The member names of this enum type</param>
        private static void InitializeEnumType(BuiltInTypeKind builtInTypeKind,
                                               string name,
                                               string[] enumMemberNames)
        {
            EnumType enumType = (EnumType)GetBuiltInType(builtInTypeKind);

            // Initialize item attributes for all ancestor types
            EdmType.Initialize(enumType,
                               name,
                               EdmConstants.EdmNamespace,
                               DataSpace.CSpace,
                               false,
                               null);

            for (int i = 0; i < enumMemberNames.Length; i++)
            {
                enumType.AddMember(new EnumMember(enumMemberNames[i], i));
            }
        }
示例#13
0
 /// <summary>
 /// Add properties for all the build in complex type
 /// </summary>
 /// <param name="builtInTypeKind">The type of the built In type whose properties are being added</param>
 /// <param name="properties">properties of the built in type</param>
 private static void AddBuiltInTypeProperties(BuiltInTypeKind builtInTypeKind, EdmProperty[] properties)
 {
     ComplexType complexType = (ComplexType)GetBuiltInType(builtInTypeKind);
     if (properties != null)
     {
         for (int i = 0; i < properties.Length; i++)
         {
             complexType.AddMember(properties[i]);
         }
     }
 }
示例#14
0
 /// <summary>
 /// Returns the list of EDM builtin types
 /// </summary>
 public static EdmType GetBuiltInType(BuiltInTypeKind builtInTypeKind)
 {
     return _builtInTypes[(int)builtInTypeKind];
 }
 private void VerifyMember(IProviderMember actualMember, bool expectedIsKey, string expectedEdmTypeName, BuiltInTypeKind expectedEdmTypeKind, string expectedMimeType, EntityType expectedCollectionType)
 {
     string memberName = actualMember.Name;
     Assert.AreEqual(expectedEdmTypeKind, actualMember.EdmTypeKind, "IProviderMember.EdmTypeKind is not the expected value for the member {0}.", memberName);
     Assert.AreEqual(expectedIsKey, actualMember.IsKey, "IProviderMember.IsKey is not the expected value for the member {0}.", memberName);
     Assert.AreEqual(expectedEdmTypeName, actualMember.EdmTypeName, "IProviderMember.EdmTypeName is not the expected value for the member {0}.", memberName);
     Assert.AreEqual(expectedMimeType, actualMember.MimeType, "IProviderMember.MimeType is not the expected value for the member {0}.", memberName);
     Assert.AreEqual(expectedCollectionType, actualMember.CollectionItemType, "IProviderMember.ExpectedCollectionType is not the expected value for the member {0}.", memberName);
 }
示例#16
0
        public void WebDataServiceCsdlMimeTypes()
        {
            object[] targets = new object[]
            {
                // BuiltInTypeKind.EdmFunction,
                // BuiltInTypeKind.ComplexType,
                // BuiltInTypeKind.EntityContainer,
                // BuiltInTypeKind.EntityType,
                BuiltInTypeKind.EdmProperty,
            };

            // Ensure the NorthwindModel service is ready to be used.
            Trace.WriteLine("NorthwindModel IsValid: " + ServiceModelData.Northwind.IsValid);

            CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                new Dimension("Target", targets),
                new Dimension("MimeType", new object[] { "", "text/html" }));
            int schemaCounter = 0;

            TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
            {
                BuiltInTypeKind target = (BuiltInTypeKind)values["Target"];
                string mimeType        = (string)values["MimeType"];

                // Create a copy of Northwind model files.
                schemaCounter++;
                const bool overwriteTrue = true;
                string sourceFileName    = Path.Combine(TestUtil.NorthwindMetadataDirectory, "Northwind.csdl");
                string destFileName      = sourceFileName + schemaCounter + ".csdl";
                File.Copy(sourceFileName, destFileName, overwriteTrue);
                File.SetAttributes(destFileName, FileAttributes.Normal);

                // Add an attribute at specific values.
                string csdlFileName  = destFileName;
                XmlDocument document = new XmlDocument();
                document.Load(csdlFileName);
                XmlElement element = GetElementForKind(document, target);
                element.SetAttribute("MimeType", "http://docs.oasis-open.org/odata/ns/metadata", mimeType);
                document.Save(csdlFileName);

                using (TestWebRequest request = TestWebRequest.CreateForInProcess())
                {
                    // Get the generated CSDL.
                    string connectionString = NorthwindModel.NorthwindContext.ContextConnectionString;
                    try
                    {
                        string northwindConnectionString = connectionString;
                        northwindConnectionString        = northwindConnectionString
                                                           .Replace("Northwind.csdl", "Northwind.csdl" + schemaCounter + ".csdl");
                        NorthwindModel.NorthwindContext.ContextConnectionString = northwindConnectionString;

                        request.DataServiceType  = typeof(NorthwindModel.NorthwindContext);
                        request.RequestUriString = "/$metadata";
                        Exception exception      = TestUtil.RunCatching(request.SendRequest);
                        TestUtil.AssertExceptionExpected(exception,
                                                         target != BuiltInTypeKind.EdmProperty,
                                                         mimeType == "");

                        if (exception != null)
                        {
                            return;
                        }

                        XmlDocument metadataResult = new XmlDocument(TestUtil.TestNameTable);
                        metadataResult.Load(request.GetResponseStream());
                        Trace.WriteLine(metadataResult.OuterXml);

                        // Get a value using a primitive serializer.
                        request.RequestUriString = "/Customers?$format=atom&$top=1";
                        request.SendRequest();
                        XmlDocument customerDocument = SerializationFormatData.Atom.LoadXmlDocumentFromStream(request.GetResponseStream());
                        XmlElement customerId        = TestUtil.AssertSelectSingleElement(customerDocument, "/atom:feed/atom:entry/atom:id");
                        request.FullRequestUriString = customerId.InnerText + "/CompanyName/$value";
                        request.SendRequest();
                        Assert.AreEqual(mimeType, TestUtil.GetMediaType(request.ResponseContentType));
                    }
                    finally
                    {
                        NorthwindModel.NorthwindContext.ContextConnectionString = connectionString;
                    }
                }
            });
        }
        private void VerifyMember(IProviderMember actualMember, bool expectedIsKey, string expectedEdmTypeName, BuiltInTypeKind expectedEdmTypeKind, string expectedMimeType, EntityType expectedCollectionType)
        {
            string memberName = actualMember.Name;

            Assert.AreEqual(expectedEdmTypeKind, actualMember.EdmTypeKind, "IProviderMember.EdmTypeKind is not the expected value for the member {0}.", memberName);
            Assert.AreEqual(expectedIsKey, actualMember.IsKey, "IProviderMember.IsKey is not the expected value for the member {0}.", memberName);
            Assert.AreEqual(expectedEdmTypeName, actualMember.EdmTypeName, "IProviderMember.EdmTypeName is not the expected value for the member {0}.", memberName);
            Assert.AreEqual(expectedMimeType, actualMember.MimeType, "IProviderMember.MimeType is not the expected value for the member {0}.", memberName);
            Assert.AreEqual(expectedCollectionType, actualMember.CollectionItemType, "IProviderMember.ExpectedCollectionType is not the expected value for the member {0}.", memberName);
        }
示例#18
0
 static internal InvalidOperationException NonSerializableType(BuiltInTypeKind kind)
 {
     return(InvalidOperation(Strings.Serialization_UnknownGlobalItem(kind)));
 }
 /// <summary>
 /// Returns a conceptual model built-in type that matches one of the
 /// <see
 ///     cref="T:System.Data.Entity.Core.Metadata.Edm.BuiltInTypeKind" />
 /// values.
 /// </summary>
 /// <returns>
 /// An <see cref="T:System.Data.Entity.Core.Metadata.Edm.EdmType" /> object that represents the built-in type in the EDM.
 /// </returns>
 /// <param name="builtInTypeKind">
 /// One of the <see cref="T:System.Data.Entity.Core.Metadata.Edm.BuiltInTypeKind" /> values.
 /// </param>
 public static EdmType GetBuiltInType(BuiltInTypeKind builtInTypeKind)
 {
     return(_builtInTypes[(int)builtInTypeKind]);
 }
示例#20
0
 public BuiltInType(BuiltInTypeKind kind)
 {
     Kind = kind;
 }
示例#21
0
        /// <summary>
        /// Initializes the enum type
        /// </summary>
        /// <param name="builtInTypeKind">The built-in type kind enum value of this enum type</param>
        /// <param name="name">The name of this enum type</param>
        /// <param name="enumMemberNames">The member names of this enum type</param>
        private static void InitializeEnumType(BuiltInTypeKind builtInTypeKind,
                                                string name,
                                                string[] enumMemberNames)
        {
            EnumType enumType = (EnumType)GetBuiltInType(builtInTypeKind);

            // Initialize item attributes for all ancestor types
            EdmType.Initialize(enumType,
                               name,
                               EdmConstants.EdmNamespace,
                               DataSpace.CSpace,
                               false,
                               null);

            for (int i = 0; i < enumMemberNames.Length; i++)
            {
                enumType.AddMember(new EnumMember(enumMemberNames[i], i));
            }
        }
 /// <summary>
 /// Initializes a new attribute with built in type kind
 /// </summary>
 /// <param name="builtInTypeKind">Built in type setting Type property</param>
 /// <param name="isCollectionType">Sets IsCollectionType property</param>
 internal MetadataPropertyAttribute(BuiltInTypeKind builtInTypeKind, bool isCollectionType)
     : this(MetadataItem.GetBuiltInType(builtInTypeKind), isCollectionType)
 {
 }
 // <summary>
 // Initializes a new attribute with built in type kind
 // </summary>
 // <param name="builtInTypeKind"> Built in type setting Type property </param>
 // <param name="isCollectionType"> Sets IsCollectionType property </param>
 internal MetadataPropertyAttribute(BuiltInTypeKind builtInTypeKind, bool isCollectionType)
     : this(MetadataItem.GetBuiltInType(builtInTypeKind), isCollectionType)
 {
 }
示例#24
0
 static internal InvalidOperationException MissingGenerationPatternForType(BuiltInTypeKind kind)
 {
     return(InvalidOperation(Strings.ModelGeneration_UnGeneratableType(kind)));
 }
 /// <summary>
 /// Returns a conceptual model built-in type that matches one of the
 /// <see cref="T:System.Data.Entity.Core.Metadata.Edm.BuiltInTypeKind" />
 /// values.
 /// </summary>
 /// <returns>
 /// An <see cref="T:System.Data.Entity.Core.Metadata.Edm.EdmType" /> object that represents the built-in type in the EDM.
 /// </returns>
 /// <param name="builtInTypeKind">
 /// One of the <see cref="T:System.Data.Entity.Core.Metadata.Edm.BuiltInTypeKind" /> values.
 /// </param>
 public static EdmType GetBuiltInType(BuiltInTypeKind builtInTypeKind)
 {
     return(MetadataItem._builtInTypes[(int)builtInTypeKind]);
 }