当前位置: 首页>>代码示例>>C#>>正文


C# EdmModel.SetDescriptionAnnotation方法代码示例

本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel.SetDescriptionAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.SetDescriptionAnnotation方法的具体用法?C# EdmModel.SetDescriptionAnnotation怎么用?C# EdmModel.SetDescriptionAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.OData.Edm.Library.EdmModel的用法示例。


在下文中一共展示了EdmModel.SetDescriptionAnnotation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateTripPinServiceModel


//.........这里部分代码省略.........

            var me = new EdmSingleton(defaultContainer, "Me", personType);
            defaultContainer.AddElement(me);

            personSet.AddNavigationTarget(friendsnNavigation, personSet);
            me.AddNavigationTarget(friendsnNavigation, personSet);

            personSet.AddNavigationTarget(flightAirlineNavigation, airlineSet);
            me.AddNavigationTarget(flightAirlineNavigation, airlineSet);

            personSet.AddNavigationTarget(flightFromAirportNavigation, airportSet);
            me.AddNavigationTarget(flightFromAirportNavigation, airportSet);

            personSet.AddNavigationTarget(flightToAirportNavigation, airportSet);
            me.AddNavigationTarget(flightToAirportNavigation, airportSet);

            personSet.AddNavigationTarget(personPhotoNavigation, photoSet);
            me.AddNavigationTarget(personPhotoNavigation, photoSet);

            personSet.AddNavigationTarget(tripPhotosNavigation, photoSet);
            me.AddNavigationTarget(tripPhotosNavigation, photoSet);

            var getFavoriteAirlineFunction = new EdmFunction(ns, "GetFavoriteAirline",
                new EdmEntityTypeReference(airlineType, false), true,
                new EdmPathExpression("person/Trips/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight/Airline"), true);
            getFavoriteAirlineFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            model.AddElement(getFavoriteAirlineFunction);

            var getInvolvedPeopleFunction = new EdmFunction(ns, "GetInvolvedPeople",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(personType, false))), true, null, true);
            getInvolvedPeopleFunction.AddParameter("trip", new EdmEntityTypeReference(tripType, false));
            model.AddElement(getInvolvedPeopleFunction);

            var getFriendsTripsFunction = new EdmFunction(ns, "GetFriendsTrips",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(tripType, false))),
                true, new EdmPathExpression("person/Friends/Trips"), true);
            getFriendsTripsFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            getFriendsTripsFunction.AddParameter("userName", EdmCoreModel.Instance.GetString(false));
            model.AddElement(getFriendsTripsFunction);

            var getNearestAirport = new EdmFunction(ns, "GetNearestAirport",
                new EdmEntityTypeReference(airportType, false),
                false, null, true);
            getNearestAirport.AddParameter("lat", EdmCoreModel.Instance.GetDouble(false));
            getNearestAirport.AddParameter("lon", EdmCoreModel.Instance.GetDouble(false));
            model.AddElement(getNearestAirport);
            var getNearestAirportFunctionImport = (IEdmFunctionImport)defaultContainer.AddFunctionImport("GetNearestAirport", getNearestAirport, new EdmEntitySetReferenceExpression(airportSet), true);

            var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
            model.AddElement(resetDataSourceAction);
            defaultContainer.AddActionImport(resetDataSourceAction);

            var shareTripAction = new EdmAction(ns, "ShareTrip", null, true, null);
            shareTripAction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            shareTripAction.AddParameter("userName", EdmCoreModel.Instance.GetString(false));
            shareTripAction.AddParameter("tripId", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(shareTripAction);

            model.SetDescriptionAnnotation(defaultContainer, "TripPin service is a sample service for OData V4.");
            model.SetOptimisticConcurrencyAnnotation(personSet, personType.StructuralProperties().Where(p => p.Name == "Concurrency"));
            // TODO: currently singleton does not support ETag feature
            // model.SetOptimisticConcurrencyAnnotation(me, personType.StructuralProperties().Where(p => p.Name == "Concurrency"));
            model.SetResourcePathCoreAnnotation(personSet, "People");
            model.SetResourcePathCoreAnnotation(me, "Me");
            model.SetResourcePathCoreAnnotation(airlineSet, "Airlines");
            model.SetResourcePathCoreAnnotation(airportSet, "Airports");
            model.SetResourcePathCoreAnnotation(photoSet, "Photos");
            model.SetResourcePathCoreAnnotation(getNearestAirportFunctionImport, "Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport");
            model.SetDereferenceableIDsCoreAnnotation(defaultContainer, true);
            model.SetConventionalIDsCoreAnnotation(defaultContainer, true);
            model.SetPermissionsCoreAnnotation(personType.FindProperty("UserName"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(airlineType.FindProperty("AirlineCode"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(airportType.FindProperty("IcaoCode"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(planItemType.FindProperty("PlanItemId"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(tripType.FindProperty("TripId"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(photoType.FindProperty("Id"), CorePermission.Read);
            model.SetImmutableCoreAnnotation(airportType.FindProperty("IataCode"), true);
            model.SetComputedCoreAnnotation(personType.FindProperty("Concurrency"), true);
            model.SetAcceptableMediaTypesCoreAnnotation(photoType, new[] { "image/jpeg" });
            model.SetConformanceLevelCapabilitiesAnnotation(defaultContainer, CapabilitiesConformanceLevelType.Advanced);
            model.SetSupportedFormatsCapabilitiesAnnotation(defaultContainer, new[] { "application/json;odata.metadata=full;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=minimal;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=none;IEEE754Compatible=false;odata.streaming=true" });
            model.SetAsynchronousRequestsSupportedCapabilitiesAnnotation(defaultContainer, true);
            model.SetBatchContinueOnErrorSupportedCapabilitiesAnnotation(defaultContainer, false);
            model.SetNavigationRestrictionsCapabilitiesAnnotation(personSet, CapabilitiesNavigationType.None, new[] { new Tuple<IEdmNavigationProperty, CapabilitiesNavigationType>(friendsnNavigation, CapabilitiesNavigationType.Recursive) });
            model.SetFilterFunctionsCapabilitiesAnnotation(defaultContainer, new[] { "contains", "endswith", "startswith", "length", "indexof", "substring", "tolower", "toupper", "trim", "concat", "year", "month", "day", "hour", "minute", "second", "round", "floor", "ceiling", "cast", "isof" });
            model.SetSearchRestrictionsCapabilitiesAnnotation(personSet, true, CapabilitiesSearchExpressions.None);
            model.SetSearchRestrictionsCapabilitiesAnnotation(airlineSet, true, CapabilitiesSearchExpressions.None);
            model.SetSearchRestrictionsCapabilitiesAnnotation(airportSet, true, CapabilitiesSearchExpressions.None);
            model.SetSearchRestrictionsCapabilitiesAnnotation(photoSet, true, CapabilitiesSearchExpressions.None);
            model.SetInsertRestrictionsCapabilitiesAnnotation(personSet, true, new[] { personTripNavigation, friendsnNavigation });
            model.SetInsertRestrictionsCapabilitiesAnnotation(airlineSet, true, null);
            model.SetInsertRestrictionsCapabilitiesAnnotation(airportSet, false, null);
            model.SetInsertRestrictionsCapabilitiesAnnotation(photoSet, true, null);
            // TODO: model.SetUpdateRestrictionsCapabilitiesAnnotation();
            model.SetDeleteRestrictionsCapabilitiesAnnotation(airportSet, false, null);
            model.SetISOCurrencyMeasuresAnnotation(tripType.FindProperty("Budget"), "USD");
            model.SetScaleMeasuresAnnotation(tripType.FindProperty("Budget"), 2);

            return model;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:TripPinInMemoryModel.cs

示例2: TestCoreDescriptionAnnotation

        public void TestCoreDescriptionAnnotation()
        {
            EdmModel model = new EdmModel();

            const string personTypeDescription = "this is person type.";
            const string personTypeLongDescription = "this is person type, but with a longer description.";
            const string overwritePersonDescription = "this is overwritten person type.";
            const string propertyIdDescription = "this is property Id.";
            const string structuralPropertyDescription = "this is structural property.";
            const string stringTermDescription = "this is string term.";
            const string entitySetDescription = "this is entitySet.";
            const string singletonDescription = "this is singleton.";

            EdmEntityContainer container = new EdmEntityContainer("Ns", "Container");
            var personType = new EdmEntityType("Ns", "Person");
            var propertyId = personType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            personType.AddKeys(propertyId);
            var structuralProperty = personType.AddStructuralProperty("Concurrency", EdmCoreModel.Instance.GetInt32(true));
            model.AddElement(personType);
            var entitySet = container.AddEntitySet("People", personType);
            var driverSet = container.AddEntitySet("Drivers", personType);

            var stringTerm = new EdmTerm("Ns", "HomeAddress", EdmCoreModel.Instance.GetString(true));
            model.AddElement(stringTerm);

            var singleton = container.AddSingleton("Boss", personType);
            model.AddElement(container);

            model.SetDescriptionAnnotation(personType, personTypeDescription);
            model.SetDescriptionAnnotation(personType, overwritePersonDescription);
            model.SetLongDescriptionAnnotation(personType, personTypeLongDescription);
            model.SetDescriptionAnnotation(structuralProperty, structuralPropertyDescription);
            model.SetDescriptionAnnotation(propertyId, propertyIdDescription);
            model.SetDescriptionAnnotation(stringTerm, stringTermDescription);
            model.SetDescriptionAnnotation(entitySet, entitySetDescription);
            model.SetDescriptionAnnotation(singleton, singletonDescription);

            Assert.AreEqual(overwritePersonDescription, model.GetDescriptionAnnotation(personType));
            Assert.AreEqual(personTypeLongDescription, model.GetLongDescriptionAnnotation(personType));
            Assert.AreEqual(structuralPropertyDescription, model.GetDescriptionAnnotation(structuralProperty));
            Assert.AreEqual(propertyIdDescription, model.GetDescriptionAnnotation(propertyId));
            Assert.AreEqual(stringTermDescription, model.GetDescriptionAnnotation(stringTerm));
            Assert.AreEqual(entitySetDescription, model.GetDescriptionAnnotation(entitySet));
            Assert.AreEqual(singletonDescription, model.GetDescriptionAnnotation(singleton));
            Assert.IsNull(model.GetDescriptionAnnotation(driverSet));

            const string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""Ns"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
  <EntityType Name=""Person"">
    <Key>
      <PropertyRef Name=""Id"" />
    </Key>
    <Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false"">
      <Annotation Term=""Org.OData.Core.V1.Description"" String=""this is property Id."" />
    </Property>
    <Property Name=""Concurrency"" Type=""Edm.Int32"">
      <Annotation Term=""Org.OData.Core.V1.Description"" String=""this is structural property."" />
    </Property>
    <Annotation Term=""Org.OData.Core.V1.Description"" String=""this is overwritten person type."" />
    <Annotation Term=""Org.OData.Core.V1.LongDescription"" String=""this is person type, but with a longer description."" />
  </EntityType>
  <Term Name=""HomeAddress"" Type=""Edm.String"">
    <Annotation Term=""Org.OData.Core.V1.Description"" String=""this is string term."" />
  </Term>
  <EntityContainer Name=""Container"">
    <EntitySet Name=""People"" EntityType=""Ns.Person"">
      <Annotation Term=""Org.OData.Core.V1.Description"" String=""this is entitySet."" />
    </EntitySet>
    <EntitySet Name=""Drivers"" EntityType=""Ns.Person"" />
    <Singleton Name=""Boss"" Type=""Ns.Person"">
      <Annotation Term=""Org.OData.Core.V1.Description"" String=""this is singleton."" />
    </Singleton>
  </EntityContainer>
</Schema>";

            IEnumerable<EdmError> errors;
            StringWriter sw = new StringWriter();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.Encoding = System.Text.Encoding.UTF8;
            XmlWriter xw = XmlWriter.Create(sw, settings);
            model.TryWriteCsdl(xw, out errors);
            xw.Flush();
            xw.Close();
            var actual = sw.ToString();

            Assert.AreEqual(expected, actual);

            IEdmModel parsedModel;
            IEnumerable<EdmError> errs;
            bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(expected)) }, out parsedModel, out errs);
            Assert.IsTrue(parsed, "parsed");
            Assert.IsTrue(!errors.Any(), "No errors");

            Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(personType));
            Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(structuralProperty));
            Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(propertyId));
            Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(stringTerm));
            Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(entitySet));
            Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(singleton));
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:VocabularyParsingTests.cs


注:本文中的Microsoft.OData.Edm.Library.EdmModel.SetDescriptionAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。