public ODataServiceResponse(ODataUri uri, IEdmModel model) : base(uri) { _model = model; }
public void Process() { var lastType = TokenType.Scheme; var queryNode = default(ODataNode); foreach (var token in _tokens) { _original.Append(token.Text); var node = FromToken(token, queryNode); if (token.Type == TokenType.OpenParen && lastType == TokenType.Identifier) { var ident = _output.Pop(); switch (ident.Text) { case "all": node = new AllNode(token); break; case "any": node = new AnyNode(token); break; default: node = new CallNode(token); break; } node.Children.Add(ident); } else if (token.Type == TokenType.QueryName) { queryNode = node; } if (GetPrecedence(node) > 0) { while (_operators.Count > 0 && GetPrecedence(node) < GetPrecedence(_operators.Peek())) { PopOperator(); } _operators.Push(node); } else { switch (node.Type) { case TokenType.Call: case TokenType.OpenParen: _operators.Push(node); break; case TokenType.CloseParen: while (_operators.Count > 0 && _operators.Peek().Type != TokenType.OpenParen && _operators.Peek().Type != TokenType.Call) { PopOperator(); } if (_operators.Count > 0 && (_operators.Peek().Type == TokenType.OpenParen || _operators.Peek().Type == TokenType.Call)) { var op = _operators.Pop(); if (op is CallNode || op is AnyNode || op is AllNode) { if (lastType != TokenType.OpenParen) { var child = _output.Pop(); if (child.Type == TokenType.Comma || child.Type == TokenType.Colon) { foreach (var c in child.Children) { op.Children.Add(c); } } else { op.Children.Add(child); } } _output.Push(op); } } break; case TokenType.Whitespace: // Skip break; default: _output.Push(node); break; } } lastType = token.Type; } while (_operators.Count > 0) { PopOperator(); } _uri = new ODataUri(_original.ToString()); Flatten(); _uri.Initialize(); }
public ODataResponseBase(ODataUri uri) : base(uri) { }
internal IEdmNavigationSource GetEdmSource(ODataUri uri) { return(_path ?? uri.FindEntitySet(_model)); }
public ODataEnumerable(IEnumerable <T> enumerable, ODataUri uri) { _uri = uri; _enum = enumerable; }
public ODataEdmxResponse(ODataUri uri, IEdmModel model) : base(uri) { _model = model; Format = ResponseFormat.Xml; }
internal ODataQueryable(IQueryable child, ODataUri uri) { _child = child; _uri = uri; }
public ODataErrorResponse(ODataUri uri, Exception ex, bool renderDetails, string language = "en-US") : base(uri) { _ex = ex; _renderDetails = renderDetails; _language = language; }
public static JObject GetSwaggerDoc(ODataUri uri, IEdmModel model, Version version) { JObject swaggerDoc = new JObject() { { "swagger", "2.0" }, { "info", new JObject() { { "title", "OData Service" }, { "description", "The OData Service at " + uri.UriBuilder().Segment("$metadata").ToString() }, { "version", version.ToString() }, { "x-odata-version", "4.0" } } }, { "host", uri.Host }, { "schemes", new JArray("http") }, { "basePath", uri.UriBuilder(true).ToString() }, { "consumes", new JArray("application/json") }, { "produces", new JArray("application/json") }, }; JObject swaggerPaths = new JObject(); swaggerDoc.Add("paths", swaggerPaths); JObject swaggeDefinitions = new JObject(); swaggerDoc.Add("definitions", swaggeDefinitions); foreach (var entitySet in model.EntityContainer.EntitySets()) { swaggerPaths.Add("/" + entitySet.Name, CreateSwaggerPathForEntitySet(entitySet)); swaggerPaths.Add(GetPathForEntity(entitySet), CreateSwaggerPathForEntity(entitySet)); } foreach (var operationImport in model.EntityContainer.OperationImports()) { swaggerPaths.Add(GetPathForOperationImport(operationImport), CreateSwaggerPathForOperationImport(operationImport)); } foreach (var type in model.SchemaElements.OfType <IEdmStructuredType>()) { swaggeDefinitions.Add(type.FullTypeName(), CreateSwaggerDefinitionForStructureType(type)); } foreach (var operation in model.SchemaElements.OfType <IEdmOperation>()) { // skip unbound operation if (!operation.IsBound) { continue; } var boundParameter = operation.Parameters.First(); var boundType = boundParameter.Type.Definition; // skip operation bound to non entity (or entity collection) if (boundType.TypeKind == EdmTypeKind.Entity) { IEdmEntityType entityType = boundType as IEdmEntityType; foreach ( var entitySet in model.EntityContainer.EntitySets().Where(es => es.EntityType().Equals(entityType))) { swaggerPaths.Add(GetPathForOperationOfEntity(operation, entitySet), CreateSwaggerPathForOperationOfEntity(operation, entitySet)); } } else if (boundType.TypeKind == EdmTypeKind.Collection && (boundType as IEdmCollectionType).ElementType.Definition.TypeKind == EdmTypeKind.Entity) { IEdmEntityType entityType = boundType as IEdmEntityType; foreach ( var entitySet in model.EntityContainer.EntitySets().Where(es => es.EntityType().Equals(entityType))) { swaggerPaths.Add(GetPathForOperationOfEntitySet(operation, entitySet), CreateSwaggerPathForOperationOfEntitySet(operation, entitySet)); } } } swaggeDefinitions.Add("_Error", new JObject() { { "properties", new JObject() { { "error", new JObject() { { "$ref", "#/definitions/_InError" } } } } } }); swaggeDefinitions.Add("_InError", new JObject() { { "properties", new JObject() { { "code", new JObject() { { "type", "string" } } }, { "message", new JObject() { { "type", "string" } } } } } }); return(swaggerDoc); }
public SwaggerResponse(ODataUri uri, IEdmModel model, Version version) : base(uri) { _model = model; _version = version; }
/// <summary> /// Create an OData response for an exception /// </summary> public static ODataResponse FromException(ODataUri uri, Exception ex, bool renderDetails, string language = "en-US") { return(new ODataErrorResponse(uri, ex, renderDetails, language)); }