private static ODataResourceCollectionInfo GetODataResourceCollectionInfo(string url, string name)
        {
            ODataResourceCollectionInfo info = new ODataResourceCollectionInfo
            {
                Url = new Uri(url, UriKind.Relative)
            };

            info.SetAnnotation<AtomResourceCollectionMetadata>(new AtomResourceCollectionMetadata { Title = name });

            return info;
        }
Пример #2
0
 internal void WriteServiceDocument(DataServiceProviderWrapper provider)
 {
     ODataWorkspace defaultWorkspace = new ODataWorkspace {
         Collections = provider.GetResourceSets().Select<ResourceSetWrapper, ODataResourceCollectionInfo>(delegate (ResourceSetWrapper rs) {
             ODataResourceCollectionInfo info = new ODataResourceCollectionInfo {
                 Url = new Uri(rs.Name, UriKind.RelativeOrAbsolute)
             };
             AtomResourceCollectionMetadata annotation = new AtomResourceCollectionMetadata();
             AtomTextConstruct construct = new AtomTextConstruct {
                 Text = rs.Name
             };
             annotation.Title = construct;
             info.SetAnnotation<AtomResourceCollectionMetadata>(annotation);
             return info;
         })
     };
     this.writer.WriteServiceDocument(defaultWorkspace);
 }
Пример #3
0
 public void WriteServiceDocument()
 {
     var msgWriter = new ODataMessageWriter(_response, _writerSettings, _map.Model);
     var collections = new List<ODataResourceCollectionInfo>();
     foreach (
         var entityContainer in
             _map.Model.EntityContainers().Where(ec => _map.Model.IsDefaultEntityContainer(ec)))
     {
         foreach (var es in entityContainer.EntitySets())
         {
             var collectionInfo = new ODataResourceCollectionInfo {Url = new Uri(es.Name, UriKind.Relative)};
             var metadata = new AtomResourceCollectionMetadata {Title = es.Name};
             collectionInfo.SetAnnotation(metadata);
             collections.Add(collectionInfo);
         }
     }
     var workspace = new ODataWorkspace {Collections = collections};
     msgWriter.WriteServiceDocument(workspace);
 }
        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();
                }
            }
        }
        private ODataResourceCollectionInfo ReadCollectionElement()
        {
            ODataResourceCollectionInfo info = new ODataResourceCollectionInfo();
            string attribute = base.XmlReader.GetAttribute(this.AtomHRefAttributeName, this.EmptyNamespace);
            ValidationUtils.ValidateResourceCollectionInfoUrl(attribute);
            info.Url = base.ProcessUriFromPayload(attribute, base.XmlReader.XmlBaseUri);
            bool enableAtomMetadataReading = base.MessageReaderSettings.EnableAtomMetadataReading;
            AtomResourceCollectionMetadata collectionMetadata = null;
            if (enableAtomMetadataReading)
            {
                collectionMetadata = new AtomResourceCollectionMetadata();
            }
            if (!base.XmlReader.IsEmptyElement)
            {
                base.XmlReader.ReadStartElement();
                do
                {
                    switch (base.XmlReader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (base.XmlReader.NamespaceEquals(this.AtomPublishingNamespace))
                            {
                                if (base.XmlReader.LocalNameEquals(this.AtomPublishingCategoriesElementName))
                                {
                                    if (enableAtomMetadataReading)
                                    {
                                        this.ServiceDocumentMetadataDeserializer.ReadCategoriesElementInCollection(collectionMetadata);
                                    }
                                    else
                                    {
                                        base.XmlReader.Skip();
                                    }
                                }
                                else
                                {
                                    if (!base.XmlReader.LocalNameEquals(this.AtomPublishingAcceptElementName))
                                    {
                                        throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInResourceCollection(base.XmlReader.LocalName));
                                    }
                                    if (enableAtomMetadataReading)
                                    {
                                        this.ServiceDocumentMetadataDeserializer.ReadAcceptElementInCollection(collectionMetadata);
                                    }
                                    else
                                    {
                                        base.XmlReader.Skip();
                                    }
                                }
                            }
                            else if (base.XmlReader.NamespaceEquals(this.AtomNamespace))
                            {
                                if (enableAtomMetadataReading && base.XmlReader.LocalNameEquals(this.AtomTitleElementName))
                                {
                                    this.ServiceDocumentMetadataDeserializer.ReadTitleElementInCollection(collectionMetadata);
                                }
                                else
                                {
                                    base.XmlReader.Skip();
                                }
                            }
                            else
                            {
                                base.XmlReader.Skip();
                            }
                            break;

                        case XmlNodeType.EndElement:
                            break;

                        default:
                            base.XmlReader.Skip();
                            break;
                    }
                }
                while (base.XmlReader.NodeType != XmlNodeType.EndElement);
            }
            base.XmlReader.Read();
            if (enableAtomMetadataReading)
            {
                info.SetAnnotation<AtomResourceCollectionMetadata>(collectionMetadata);
            }
            return info;
        }