本文整理汇总了C#中ODataMessageWriter.WriteServiceDocumentAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ODataMessageWriter.WriteServiceDocumentAsync方法的具体用法?C# ODataMessageWriter.WriteServiceDocumentAsync怎么用?C# ODataMessageWriter.WriteServiceDocumentAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODataMessageWriter
的用法示例。
在下文中一共展示了ODataMessageWriter.WriteServiceDocumentAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public void ProcessRequest(HttpContext context)
{
if (!HttpContext.Current.Request.IsAuthenticated)
{
HttpContext.Current.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = HttpContext.Current.Request.FilePath }, "OAuth2Bearer");
return;
}
MSRAHttpResponseMessage message = new MSRAHttpResponseMessage(this.ContextBase.Response);
message.StatusCode = 200;
message.SetHeader(ODataConstants.ContentTypeHeader, "application/json");
// create the writer, indent for readability
ODataMessageWriterSettings messageWriterSettings = new ODataMessageWriterSettings()
{
Indent = true,
CheckCharacters = false,
BaseUri = context.Request.Url
};
messageWriterSettings.SetContentType(ODataFormat.Json);
messageWriterSettings.SetMetadataDocumentUri(new Uri("http://localhost:31435/odata/MSRAQuery/$metadata"));
if (string.IsNullOrEmpty(QueryId))
{
AzureTestDBEntities db = new AzureTestDBEntities();
var queries = db.MsrRecurringQueries.ToList().Take(1);
ODataWorkspace workSpace = new ODataWorkspace();
var collections = new List<ODataResourceCollectionInfo>();
foreach (MsrRecurringQuery recurringQuery in queries)
{
ODataResourceCollectionInfo collectionInfo = new ODataResourceCollectionInfo()
{
Name = "MsrRecurringQueries",
Url = new Uri(context.Request.Url+"data/" + recurringQuery.RecurringQueryID.ToString(), UriKind.Absolute)
};
collectionInfo.SetAnnotation<AtomResourceCollectionMetadata>(new AtomResourceCollectionMetadata()
{
Title = new AtomTextConstruct()
{
Text = "MsrRecurringQueries"//recurringQuery.RecurringQueryName
},
});
collections.Add(collectionInfo);
}
workSpace.Collections = collections.AsEnumerable<ODataResourceCollectionInfo>();
using (ODataMessageWriter messageWriter = new ODataMessageWriter(message, messageWriterSettings))
{
messageWriter.WriteServiceDocumentAsync(workSpace);
}
}
else
{
EdmModel mainModel =(EdmModel) QueryMetadataHttpHandler.BuildODataModel();
using (ODataMessageWriter messageWriter = new ODataMessageWriter(message, messageWriterSettings, mainModel))
{
var msrRecurringQueryResultType = new EdmEntityType("mainNS", "MsrRecurringQuery", null);
IEdmPrimitiveType edmPrimitiveType1 = new MSRAEdmPrimitiveType("Int32", "Edm", EdmPrimitiveTypeKind.Int32, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive);
IEdmPrimitiveType edmPrimitiveType2 = new MSRAEdmPrimitiveType("String", "Edm", EdmPrimitiveTypeKind.String, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive);
IEdmPrimitiveType edmPrimitiveType3 = new MSRAEdmPrimitiveType("String", "Edm", EdmPrimitiveTypeKind.String, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive);
IEdmPrimitiveType edmPrimitiveType4 = new MSRAEdmPrimitiveType("String", "Edm", EdmPrimitiveTypeKind.String, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive);
IEdmPrimitiveType edmPrimitiveType5 = new MSRAEdmPrimitiveType("String", "Edm", EdmPrimitiveTypeKind.String, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive);
IEdmPrimitiveType edmPrimitiveType6 = new MSRAEdmPrimitiveType("Decimal", "Edm", EdmPrimitiveTypeKind.Decimal, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive);
msrRecurringQueryResultType.AddKeys(new EdmStructuralProperty(msrRecurringQueryResultType, "RowId", new EdmPrimitiveTypeReference(edmPrimitiveType1, false)));
msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "RowId", new EdmPrimitiveTypeReference(edmPrimitiveType1, false)));
msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "Pricing_Level", new EdmPrimitiveTypeReference(edmPrimitiveType2, false)));
msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "Business_Summary", new EdmPrimitiveTypeReference(edmPrimitiveType3, false)));
msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "Future_Flag", new EdmPrimitiveTypeReference(edmPrimitiveType4, false)));
msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "Fiscal_Month", new EdmPrimitiveTypeReference(edmPrimitiveType5, false)));
msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "MS_Sales_Amount_Const", new EdmPrimitiveTypeReference(edmPrimitiveType6, false)));
ODataWriter feedWriter = messageWriter.CreateODataFeedWriter(
mainModel.EntityContainers().Select(c => c.EntitySets().First()).First(), msrRecurringQueryResultType);
ODataFeed feed = new ODataFeed()
{
Id = "MsrRecurringQueries",
};
feedWriter.WriteStart(feed);
AzureTestDBEntities db = new AzureTestDBEntities();
var queries = db.T_annooli_231161891 ;
foreach (var recurringQuery in queries)
{
ODataEntry entry = this.GetODataEntry(recurringQuery);
feedWriter.WriteStart(entry);
feedWriter.WriteEnd();
}
feedWriter.WriteEnd();
}
}
}