Example #1
0
        /// <summary>
        /// Generate a default ODataServiceDocument instance from model.
        /// </summary>
        /// <param name="model">The Edm Model frm which to generate the service document.</param>
        /// <returns>The generated service document.</returns>
        public static ODataServiceDocument GenerateServiceDocument(this IEdmModel model)
        {
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            if (model.EntityContainer == null)
            {
                throw new ODataException(Strings.ODataUtils_ModelDoesNotHaveContainer);
            }

            ODataServiceDocument serviceDocument = new ODataServiceDocument();

            serviceDocument.EntitySets = model.EntityContainer.EntitySets()
                                         .Select(entitySet => new ODataEntitySetInfo()
            {
                Name = entitySet.Name, Title = entitySet.Name, Url = new Uri(entitySet.Name, UriKind.RelativeOrAbsolute)
            }).ToList();
            serviceDocument.Singletons = model.EntityContainer.Singletons()
                                         .Select(singleton => new ODataSingletonInfo()
            {
                Name = singleton.Name, Title = singleton.Name, Url = new Uri(singleton.Name, UriKind.RelativeOrAbsolute)
            }).ToList();
            serviceDocument.FunctionImports = model.EntityContainer.OperationImports().OfType <IEdmFunctionImport>().Where(functionImport => functionImport.IncludeInServiceDocument && !functionImport.Function.Parameters.Any())
                                              .Select(functionImport => new ODataFunctionImportInfo()
            {
                Name = functionImport.Name, Title = functionImport.Name, Url = new Uri(functionImport.Name, UriKind.RelativeOrAbsolute)
            }).ToList();

            return(serviceDocument);
        }
Example #2
0
        /// <summary>
        /// Generate a default ODataServiceDocument instance from model.
        /// </summary>
        /// <param name="model">The Edm Model frm which to generate the service document.</param>
        /// <returns>The generated service document.</returns>
        public static ODataServiceDocument GenerateServiceDocument(this IEdmModel model)
        {
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            if (model.EntityContainer == null)
            {
                throw new ODataException(Strings.ODataUtils_ModelDoesNotHaveContainer);
            }

            IList <ODataEntitySetInfo>      lstEntitySets   = new List <ODataEntitySetInfo>();
            IList <ODataSingletonInfo>      lstSingletons   = new List <ODataSingletonInfo>();
            IList <ODataFunctionImportInfo> functionImports = new List <ODataFunctionImportInfo>();

            foreach (var element in model.EntityContainer.AllElements())
            {
                IEdmEntitySet entitySet = element as IEdmEntitySet;

                if (entitySet != null)
                {
                    lstEntitySets.Add(new ODataEntitySetInfo()
                    {
                        Name = entitySet.Name, Title = entitySet.Name, Url = new Uri(entitySet.Name, UriKind.RelativeOrAbsolute)
                    });
                }
                else
                {
                    IEdmSingleton singleton = element as IEdmSingleton;

                    if (singleton != null)
                    {
                        lstSingletons.Add(new ODataSingletonInfo()
                        {
                            Name = singleton.Name, Title = singleton.Name, Url = new Uri(singleton.Name, UriKind.RelativeOrAbsolute)
                        });
                    }
                    else
                    {
                        IEdmFunctionImport functionImport = element as IEdmFunctionImport;
                        var a = model.EntityContainer.OperationImports().OfType <IEdmFunctionImport>();

                        if (functionImport != null && functionImport.IncludeInServiceDocument && !functionImport.Function.Parameters.Any())
                        {
                            functionImports.Add(new ODataFunctionImportInfo()
                            {
                                Name = functionImport.Name, Title = functionImport.Name, Url = new Uri(functionImport.Name, UriKind.RelativeOrAbsolute)
                            });
                        }
                    }
                }
            }

            ODataServiceDocument serviceDocument = new ODataServiceDocument();

            serviceDocument.EntitySets      = lstEntitySets;
            serviceDocument.Singletons      = lstSingletons;
            serviceDocument.FunctionImports = functionImports;

            return(serviceDocument);
        }
Example #3
0
 /// <summary>
 /// Asynchronously writes a service document with the specified <paramref name="serviceDocument"/>
 /// as message payload.
 /// </summary>
 /// <param name="serviceDocument">The service document 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(ODataServiceDocument serviceDocument)
 {
     throw this.CreatePayloadKindNotSupportedException(ODataPayloadKind.ServiceDocument);
 }