internal void WriteServiceDocument(ODataWorkspace defaultWorkspace)
 {
     IEnumerable<ODataResourceCollectionInfo> collections = defaultWorkspace.Collections;
     base.WritePayloadStart();
     base.XmlWriter.WriteStartElement(string.Empty, "service", "http://www.w3.org/2007/app");
     if (base.MessageWriterSettings.BaseUri != null)
     {
         base.XmlWriter.WriteAttributeString("base", "http://www.w3.org/XML/1998/namespace", base.MessageWriterSettings.BaseUri.AbsoluteUri);
     }
     base.XmlWriter.WriteAttributeString("xmlns", "http://www.w3.org/2000/xmlns/", "http://www.w3.org/2007/app");
     base.XmlWriter.WriteAttributeString("atom", "http://www.w3.org/2000/xmlns/", "http://www.w3.org/2005/Atom");
     base.XmlWriter.WriteStartElement(string.Empty, "workspace", "http://www.w3.org/2007/app");
     this.atomServiceDocumentMetadataSerializer.WriteWorkspaceMetadata(defaultWorkspace);
     if (collections != null)
     {
         foreach (ODataResourceCollectionInfo info in collections)
         {
             ValidationUtils.ValidateResourceCollectionInfo(info);
             base.XmlWriter.WriteStartElement(string.Empty, "collection", "http://www.w3.org/2007/app");
             base.XmlWriter.WriteAttributeString("href", base.UriToUrlAttributeValue(info.Url));
             this.atomServiceDocumentMetadataSerializer.WriteResourceCollectionMetadata(info);
             base.XmlWriter.WriteEndElement();
         }
     }
     base.XmlWriter.WriteEndElement();
     base.XmlWriter.WriteEndElement();
     base.WritePayloadEnd();
 }
Example #2
0
 private void VerifyCanWriteServiceDocument(ODataWorkspace defaultWorkspace)
 {
     ExceptionUtils.CheckArgumentNotNull <ODataWorkspace>(defaultWorkspace, "defaultWorkspace");
     if (!this.writingResponse)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ODataMessageWriter_ServiceDocumentInRequest);
     }
     this.VerifyWriterNotDisposedAndNotUsed();
 }
        public ODataWorkspace GetServiceDocument()
        {
            IEdmModel model = GetModel();
            ODataWorkspace workspace = new ODataWorkspace();
            IEdmEntityContainer container = model.EntityContainers().Single();
            IEnumerable<IEdmEntitySet> entitysets = container.EntitySets();

            IEnumerable<ODataResourceCollectionInfo> collections = entitysets.Select(
                e => GetODataResourceCollectionInfo(model.GetEntitySetUrl(e).ToString(), e.Name));
            workspace.Collections = collections;

            return workspace;
        }
        public HttpResponseMessage GetServiceDocument()
        {
            IEdmModel model;
            MediaTypeFormatter odataFormatter = GetFormatter(typeof(ODataWorkspace), out model);

            ODataWorkspace workspace = new ODataWorkspace();
            IEdmEntityContainer container = model.EntityContainers().Single();
            IEnumerable<IEdmEntitySet> entitysets = container.EntitySets();

            IEnumerable<ODataResourceCollectionInfo> collections = entitysets.Select(e => GetODataResourceCollectionInfo(model.GetEntitySetUrl(e).ToString(), e.Name));
            workspace.Collections = collections;

            // This controller requires and supports only the OData formatter.
            return Request.CreateResponse(HttpStatusCode.OK, workspace, odataFormatter);
        }
 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);
 }
 internal void WriteServiceDocument(ODataWorkspace defaultWorkspace)
 {
     IEnumerable<ODataResourceCollectionInfo> collections = defaultWorkspace.Collections;
     base.WriteTopLevelPayload(delegate {
         this.JsonWriter.StartObjectScope();
         this.JsonWriter.WriteName("EntitySets");
         this.JsonWriter.StartArrayScope();
         if (collections != null)
         {
             foreach (ODataResourceCollectionInfo info in collections)
             {
                 ValidationUtils.ValidateResourceCollectionInfo(info);
                 this.JsonWriter.WriteValue(UriUtilsCommon.UriToString(info.Url));
             }
         }
         this.JsonWriter.EndArrayScope();
         this.JsonWriter.EndObjectScope();
     });
 }
 internal void WriteWorkspaceMetadata(ODataWorkspace workspace)
 {
     AtomWorkspaceMetadata annotation = workspace.GetAnnotation<AtomWorkspaceMetadata>();
     AtomTextConstruct textConstruct = null;
     if (annotation != null)
     {
         textConstruct = annotation.Title;
     }
     if (textConstruct == null)
     {
         textConstruct = new AtomTextConstruct {
             Text = "Default"
         };
     }
     if (base.UseServerFormatBehavior && (textConstruct.Kind == AtomTextConstructKind.Text))
     {
         base.WriteElementWithTextContent("atom", "title", "http://www.w3.org/2005/Atom", textConstruct.Text);
     }
     else
     {
         base.WriteTextConstruct("atom", "title", "http://www.w3.org/2005/Atom", textConstruct);
     }
 }
Example #8
0
 internal virtual Task WriteServiceDocumentAsync(ODataWorkspace defaultWorkspace)
 {
     throw this.CreatePayloadKindNotSupportedException(ODataPayloadKind.ServiceDocument);
 }
Example #9
0
 internal virtual Task WriteServiceDocumentAsync(ODataWorkspace defaultWorkspace)
 {
     throw this.CreatePayloadKindNotSupportedException(ODataPayloadKind.ServiceDocument);
 }
 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);
 }
Example #11
0
 /// <summary>
 /// Asynchronously writes a service document with the specified <paramref name="defaultWorkspace"/>
 /// as message payload.
 /// </summary>
 /// <param name="defaultWorkspace">The default workspace to write in the service document.</param>
 /// <returns>A task representing the asynchronous operation of writing the service document.</returns>
 /// <remarks>It is the responsibility of this method to flush the output before the task finishes.</remarks>
 internal virtual Task WriteServiceDocumentAsync(ODataWorkspace defaultWorkspace)
 {
     DebugUtils.CheckNoExternalCallers();
     throw this.CreatePayloadKindNotSupportedException(ODataPayloadKind.ServiceDocument);
 }
        private ODataWorkspace ReadWorkspace()
        {
            bool enableAtomMetadataReading = base.AtomInputContext.MessageReaderSettings.EnableAtomMetadataReading;
            this.SkipToElementInAtomPublishingNamespace();
            if (base.XmlReader.NodeType == XmlNodeType.EndElement)
            {
                return null;
            }
            if (!base.XmlReader.LocalNameEquals(this.AtomPublishingWorkspaceElementName))
            {
                throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInServiceDocument(base.XmlReader.LocalName));
            }
            List<ODataResourceCollectionInfo> sourceList = new List<ODataResourceCollectionInfo>();
            AtomWorkspaceMetadata workspaceMetadata = null;
            if (enableAtomMetadataReading)
            {
                workspaceMetadata = new AtomWorkspaceMetadata();
            }
            if (!base.XmlReader.IsEmptyElement)
            {
                base.XmlReader.ReadStartElement();
                do
                {
                    base.XmlReader.SkipInsignificantNodes();
                    switch (base.XmlReader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (base.XmlReader.NamespaceEquals(this.AtomPublishingNamespace))
                            {
                                if (!base.XmlReader.LocalNameEquals(this.AtomPublishingCollectionElementName))
                                {
                                    throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInWorkspace(base.XmlReader.LocalName));
                                }
                                ODataResourceCollectionInfo item = this.ReadCollectionElement();
                                sourceList.Add(item);
                            }
                            else if (enableAtomMetadataReading && base.XmlReader.NamespaceEquals(this.AtomNamespace))
                            {
                                if (base.XmlReader.LocalNameEquals(this.AtomTitleElementName))
                                {
                                    this.ServiceDocumentMetadataDeserializer.ReadTitleElementInWorkspace(workspaceMetadata);
                                }
                                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();
            ODataWorkspace workspace = new ODataWorkspace {
                Collections = new ReadOnlyEnumerable<ODataResourceCollectionInfo>(sourceList)
            };
            if (enableAtomMetadataReading)
            {
                workspace.SetAnnotation<AtomWorkspaceMetadata>(workspaceMetadata);
            }
            return workspace;
        }
Example #13
0
 private void WriteServiceDocumentImplementation(ODataWorkspace defaultWorkspace)
 {
     new ODataJsonServiceDocumentSerializer(this).WriteServiceDocument(defaultWorkspace);
 }
Example #14
0
 internal override Task WriteServiceDocumentAsync(ODataWorkspace defaultWorkspace)
 {
     return TaskUtils.GetTaskForSynchronousOperationReturningTask(delegate {
         this.WriteServiceDocumentImplementation(defaultWorkspace);
         return this.FlushAsync();
     });
 }
 /// <summary>
 /// Asynchronously writes a service document with the specified <paramref name="defaultWorkspace"/> 
 /// as message payload.
 /// </summary>
 /// <param name="defaultWorkspace">The default workspace to write in the service document.</param>
 /// <returns>A task representing the asynchronous operation of writing the service document.</returns>
 /// <remarks>It is the responsibility of this method to flush the output before the task finishes.</remarks>
 internal virtual Task WriteServiceDocumentAsync(ODataWorkspace defaultWorkspace)
 {
     DebugUtils.CheckNoExternalCallers();
     throw this.CreatePayloadKindNotSupportedException(ODataPayloadKind.ServiceDocument);
 }
Example #16
0
 public void WriteServiceDocument(ODataWorkspace defaultWorkspace)
 {
     //this.VerifyCanWriteServiceDocument(defaultWorkspace);
     this.WriteToOutput(ODataPayloadKind.ServiceDocument, null, context => context.WriteServiceDocument(defaultWorkspace));
 }
        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();
                }
            }
        }
Example #18
0
 public Task WriteServiceDocumentAsync(ODataWorkspace defaultWorkspace)
 {
     this.VerifyCanWriteServiceDocument(defaultWorkspace);
     return(this.WriteToOutputAsync(ODataPayloadKind.ServiceDocument, null, context => context.WriteServiceDocumentAsync(defaultWorkspace)));
 }
Example #19
0
 internal override void WriteServiceDocument(ODataWorkspace defaultWorkspace)
 {
     this.WriteServiceDocumentImplementation(defaultWorkspace);
     this.Flush();
 }