示例#1
0
 internal static void ValidateResourceCollectionInfo(ODataResourceCollectionInfo collectionInfo)
 {
     if (collectionInfo == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_WorkspaceCollectionsMustNotContainNullItem);
     }
     if (collectionInfo.Url == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_ResourceCollectionMustSpecifyUrl);
     }
 }
        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;
        }
示例#3
0
        /// <summary>
        /// Validates a resource collection.
        /// </summary>
        /// <param name="collectionInfo">The resource collection to validate.</param>
        internal static void ValidateResourceCollectionInfo(ODataResourceCollectionInfo collectionInfo)
        {
            DebugUtils.CheckNoExternalCallers();

            if (collectionInfo == null)
            {
                throw new ODataException(Strings.ValidationUtils_WorkspaceCollectionsMustNotContainNullItem);
            }

            // The resource collection URL must not be null;
            if (collectionInfo.Url == null)
            {
                throw new ODataException(Strings.ValidationUtils_ResourceCollectionMustSpecifyUrl);
            }
        }
 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 ODataWorkspace ReadServiceDocument()
 {
     List<ODataResourceCollectionInfo> sourceList = null;
     base.ReadPayloadStart(false);
     base.JsonReader.ReadStartObject();
     while (base.JsonReader.NodeType == JsonNodeType.Property)
     {
         string strB = base.JsonReader.ReadPropertyName();
         if (string.CompareOrdinal("EntitySets", strB) == 0)
         {
             if (sourceList != null)
             {
                 throw new ODataException(Strings.ODataJsonServiceDocumentDeserializer_MultipleEntitySetsPropertiesForServiceDocument);
             }
             sourceList = new List<ODataResourceCollectionInfo>();
             base.JsonReader.ReadStartArray();
             while (base.JsonReader.NodeType != JsonNodeType.EndArray)
             {
                 string collectionInfoUrl = base.JsonReader.ReadStringValue();
                 ValidationUtils.ValidateResourceCollectionInfoUrl(collectionInfoUrl);
                 ODataResourceCollectionInfo item = new ODataResourceCollectionInfo {
                     Url = base.ProcessUriFromPayload(collectionInfoUrl, false)
                 };
                 sourceList.Add(item);
             }
             base.JsonReader.ReadEndArray();
         }
         else
         {
             base.JsonReader.SkipValue();
         }
     }
     if (sourceList == null)
     {
         throw new ODataException(Strings.ODataJsonServiceDocumentDeserializer_NoEntitySetsPropertyForServiceDocument);
     }
     base.JsonReader.ReadEndObject();
     base.ReadPayloadEnd(false);
     return new ODataWorkspace { Collections = new ReadOnlyEnumerable<ODataResourceCollectionInfo>(sourceList) };
 }
 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);
 }
示例#7
0
 internal static void ValidateResourceCollectionInfo(ODataResourceCollectionInfo collectionInfo)
 {
     if (collectionInfo == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_WorkspaceCollectionsMustNotContainNullItem);
     }
     if (collectionInfo.Url == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_ResourceCollectionMustSpecifyUrl);
     }
 }
        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();
                }
            }
        }
示例#9
0
        /// <summary>
        /// Validates a resource collection.
        /// </summary>
        /// <param name="collectionInfo">The resource collection to validate.</param>
        internal static void ValidateResourceCollectionInfo(ODataResourceCollectionInfo collectionInfo)
        {
            DebugUtils.CheckNoExternalCallers();

            if (collectionInfo == null)
            {
                throw new ODataException(Strings.ValidationUtils_WorkspaceCollectionsMustNotContainNullItem);
            }

            // The resource collection URL must not be null; 
            if (collectionInfo.Url == null)
            {
                throw new ODataException(Strings.ValidationUtils_ResourceCollectionMustSpecifyUrl);
            }
        }
        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;
        }
 internal void WriteResourceCollectionMetadata(ODataResourceCollectionInfo collection)
 {
     AtomResourceCollectionMetadata annotation = collection.GetAnnotation<AtomResourceCollectionMetadata>();
     AtomTextConstruct textConstruct = null;
     if (annotation != null)
     {
         textConstruct = annotation.Title;
     }
     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);
     }
     if (annotation != null)
     {
         string accept = annotation.Accept;
         if (accept != null)
         {
             base.WriteElementWithTextContent(string.Empty, "accept", "http://www.w3.org/2007/app", accept);
         }
         AtomCategoriesMetadata categories = annotation.Categories;
         if (categories != null)
         {
             base.XmlWriter.WriteStartElement(string.Empty, "categories", "http://www.w3.org/2007/app");
             Uri href = categories.Href;
             bool? @fixed = categories.Fixed;
             string scheme = categories.Scheme;
             IEnumerable<AtomCategoryMetadata> source = categories.Categories;
             if (href != null)
             {
                 if ((@fixed.HasValue || (scheme != null)) || ((source != null) && source.Any<AtomCategoryMetadata>()))
                 {
                     throw new ODataException(Microsoft.Data.OData.Strings.ODataAtomWriterMetadataUtils_CategoriesHrefWithOtherValues);
                 }
                 base.XmlWriter.WriteAttributeString("href", base.UriToUrlAttributeValue(href));
             }
             else
             {
                 if (@fixed.HasValue)
                 {
                     base.XmlWriter.WriteAttributeString("fixed", @fixed.Value ? "yes" : "no");
                 }
                 if (scheme != null)
                 {
                     base.XmlWriter.WriteAttributeString("scheme", scheme);
                 }
                 if (source != null)
                 {
                     foreach (AtomCategoryMetadata metadata3 in source)
                     {
                         base.WriteCategory("atom", metadata3.Term, metadata3.Scheme, metadata3.Label);
                     }
                 }
             }
             base.XmlWriter.WriteEndElement();
         }
     }
 }