public void Listen() { var listener = new System.Net.HttpListener(); listener.Prefixes.Add("http://+:81/"); listener.Start(); do { var context = listener.GetContext(); var request = context.Request; var response = context.Response; if (request.Url.PathAndQuery == "/~close") { response.Close(); break; } var searchInfo = new SearchInfo(); if (request.HttpMethod == "POST" && request.InputStream != null) { searchInfo = _parser.ParseBody(request.InputStream); } else { var dataFromQuery = request.Url.ParseQueryString(); searchInfo = _parser.ParseQuery(dataFromQuery); } var predicate = _filter.BuildExpression(searchInfo); var data = GetData(searchInfo, predicate); var accept = GetAcceptType(request.AcceptTypes); SendResponse(accept, data, response); } while (true); listener.Close(); }
public ResultHandler <IEnumerable <Expression <Func <EventModel, bool> > > > BuildExpressions(IEnumerable <FilterStatement <EventModel> > filterStatements) { try { List <Expression <Func <EventModel, bool> > > result = new List <Expression <Func <EventModel, bool> > >(); foreach (var filterStatement in filterStatements) { IFilter <EventModel> filter = this._eventFilterResolver(filterStatement.FilterType); ResultHandler <Expression <Func <EventModel, bool> > > expressionResult = filter.BuildExpression(filterStatement); if (!expressionResult.Success) { this._logger.LogError(expressionResult.ErrorMessage); return(ResultHandler.Fail <IEnumerable <Expression <Func <EventModel, bool> > > >(expressionResult.ErrorCode)); } result.Add(expressionResult.Value); } return(ResultHandler.Ok <IEnumerable <Expression <Func <EventModel, bool> > > >(result)); } catch (Exception ex) { return(ResultHandler.Fail <IEnumerable <Expression <Func <EventModel, bool> > > >(ex)); } }