void ActivateMetricsExecute() { itemsWithCommand.Clear(); switch (SelectedMetricsLevel) { case MetricsLevel.Assembly: query = new QueryAssembly(MainModule); break; case MetricsLevel.Namespace: query = new QueryNameSpace(MainModule); break; case MetricsLevel.Type: query = new QueryType(MainModule); break; case MetricsLevel.Method: query = new QueryMethod(MainModule); break; default: throw new Exception("Invalid value for MetricsLevel"); } ItemsWithCommand = query.GetQueryList(); }
/// <summary> /// Updates the specified entity. /// </summary> /// <param name="entity"></param> public void Update <T>(T entity, Expression <Func <T, bool> > expression = null) where T : new() { string query = ""; try { if (entity == null) { throw new ArgumentNullException("entity"); } string condition = expression == null ? "" : QueryUtil.Translate(expression); query = BaseQuery.UPDATE_WHERE <T>(entity.ToUpdateQuery(condition)); SqlUtil.ExecuteDynamicQuery(query); } catch (Exception ex) { string message = ex.Message; while (ex.InnerException != null) { ex = ex.InnerException; message += ex.Message; } throw new Exception(message); } }
public async Task <IPaginationData <TItem> > GetPaginationResponseAsync(Expression <Func <TEntity, TItem> > selector, int start, int pageSize, string orderField = null, string orderDirection = null, Expression <Func <TEntity, bool> > inputFilterIdsExpression = null, Expression <Func <TEntity, bool> > skipIdsExpression = null, Expression <Func <TEntity, bool> > searchTermExpression = null) { if (inputFilterIdsExpression != null) { BaseQuery = BaseQuery.Where(inputFilterIdsExpression); } if (skipIdsExpression != null) { BaseQuery = BaseQuery.Where(skipIdsExpression); } var query = BaseQuery; if (searchTermExpression != null) { query = query.Where(searchTermExpression); } try { var totalCount = await BaseQuery.CountAsync(); var response = await GetPaginationResponseAsync(start, pageSize, totalCount, orderField, orderDirection, query, selector); return(response); } catch (Exception ex) { _logger?.LogError(ex.GetBaseException()?.Message ?? ex.Message); throw; } }
public void SetPredicateExp() { if (PredicateExp != null) { BaseQuery = BaseQuery.Where(PredicateExp); } }
public IQueryable <TEntity> GetEntityPaginated(BaseQuery baseDto, IQueryable <TEntity> entities) { int pageSize = baseDto.PageSize > 0 ? baseDto.PageSize : 50; //by default the size is 50 int skip = baseDto.Page > 0 ? baseDto.Page : 0; return(entities.Skip(pageSize * skip).Take(pageSize > 0 ? pageSize : 50)); }
public ListEntity <ListAttendanceLogEntity> GetList(string userId, string year, string month, int pageIndex, int pageSize) { var list = this.context.AttendanceLog.Where(c => true); if (!string.IsNullOrWhiteSpace(userId)) { list = list.Where(c => c.UserId == userId); } if (!string.IsNullOrWhiteSpace(year)) { list = list.Where(c => c.AttendanceYear == year); } if (!string.IsNullOrWhiteSpace(month)) { list = list.Where(c => c.AttendanceMonth == month); } List <ListAttendanceLogEntity> tempList = new List <ListAttendanceLogEntity>(); int total = list.Count(); if (total <= 0) { return(new ListEntity <ListAttendanceLogEntity>(tempList, total, pageIndex, pageSize)); } List <string> ids = list.OrderByDescending(c => c.AttendanceTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).Select(c => c.Id).ToList(); BaseQuery query = new BaseQuery("SELECT Id,AttendanceIp,AttendanceTime,AttendanceType,AttendanceYear,LogoutTime,LogoutType,AttendanceMonth, (select name from UserInfo where Id=UserId) as UserName FROM AttendanceLog where id in @ids", new { ids = ids }); tempList = DapperContext.BaseGetListByParam <ListAttendanceLogEntity>(query); return(new ListEntity <ListAttendanceLogEntity>(tempList, total, pageIndex, pageSize)); }
public Zwroty this[Guid[] guids] { get { return(new Zwroty(this.GetQuery(BaseQuery.Where(z => z.Kontrahent != null && z.Kontrahent.Guid != null && guids.Contains(z.Kontrahent.Guid.Value))))); } }
private void OnQuery(object sender, BaseQuery query) { if (query is GetAgeQuery && query.Target == this) { query.Result = _age; } }
public void BranchLambdaTestConditional() { BaseQuery query = null; if (1 == 1) { query |= Query <ElasticSearchProject> .Term(f => f.Name, "foo2"); } if (1 == 1) { query |= Query <ElasticSearchProject> .Term(f => f.Name, "bar2"); } if (1 == 1) { query |= Query <ElasticSearchProject> .Term(f => f.Name, "blah2"); } if (query == null) { query = Query <ElasticSearchProject> .MatchAll(); } var s = new SearchDescriptor <ElasticSearchProject>() .From(0) .Size(20) .Query(query); this.JsonEquals(s, System.Reflection.MethodInfo.GetCurrentMethod()); }
/// <summary> /// Deletes the specified entity based off Primary Key attribute. /// </summary> /// <param name="entity"></param> public void Delete <T>(T entity) where T : new() { string query = ""; try { if (entity == null) { throw new ArgumentNullException("entity"); } query = BaseQuery.DELETE_WHERE <T>(entity.ToDeleteQuery()); SqlUtil.ExecuteDynamicQuery(query); } catch (Exception ex) { var message = ex.Message; while (ex.InnerException != null) { ex = ex.InnerException; message += "\n" + ex.Message; } throw new Exception(message); } }
//TODO: Figure out QueryUtil.Translate() /// <summary> /// Returns a list of sorted entities associated with Class T. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sortDirection"></param> /// <param name="sortValue"></param> /// <param name="expression"></param> /// <returns></returns> public List <T> SortedTable <T>(string sortDirection, string sortValue, int?recordsToSkip = null, int?recordsToTake = null, Expression <Func <T, bool> > expression = null) where T : new() { try { string query = expression == null ? BaseQuery.SELECT_FROM_ORDER_BY <T>(sortDirection, sortValue) : BaseQuery.SELECT_FROM_WHERE_ORDER_BY <T>(sortDirection, sortValue, QueryUtil.Translate(expression)); if (recordsToSkip.HasValue) { query = BaseQuery.APPEND_SKIP(query, recordsToSkip.Value); if (recordsToTake.HasValue) { query = BaseQuery.APPEND_FETCH(query, recordsToTake.Value); } } return(SqlUtil.GetMultipleInfo <T>(query, null, true)); } catch (Exception ex) { throw new Exception(CustomErrorResponse(ex)); } }
//TODO: Figure out QueryUtil.Translate() /// <summary> /// Returns a list of sorted entities associated with Class T. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sortDirection"></param> /// <param name="sortValue"></param> /// <param name="expression"></param> /// <returns></returns> public List <T> SortedTable <T>(string sortDirection, string sortValue, int?recordsToSkip = null, int?recordsToTake = null, Expression <Func <T, bool> > expression = null) where T : new() { try { string query = expression == null ? BaseQuery.SELECT_FROM_ORDER_BY <T>(sortDirection, sortValue) : BaseQuery.SELECT_FROM_WHERE_ORDER_BY <T>(sortDirection, sortValue, QueryUtil.Translate(expression)); if (recordsToSkip.HasValue) { query = BaseQuery.APPEND_SKIP(query, recordsToSkip.Value); if (recordsToTake.HasValue) { query = BaseQuery.APPEND_FETCH(query, recordsToTake.Value); } } return(SqlUtil.GetMultipleInfo <T>(query, null, true)); } catch (Exception ex) { string message = ex.Message; while (ex.InnerException != null) { ex = ex.InnerException; message += ex.Message; } throw new Exception(message); // Default to query all records, then apply predicate -- Need to figure out the try section // return SqlUtil.GetMultipleInfo<T>(BaseQuery.SELECT_FROM_ORDER_BY<T>(sortDirection, sortValue), null, true).Where(expression.Compile()).ToList(); } }
public override async Task <IPagedList <TOutput> > FilterAsync <TOutput>(StudentCurriculumFilterDto filter, CancellationToken cancellationToken = default) { var query = BaseQuery.AsNoTracking().Where(x => x.Student.UserId == filter.UserId); if (!string.IsNullOrEmpty(filter.Q)) { query = query.Where(x => EF.Functions.ILike(x.Curriculum.Course.Title, $"%{filter.Q}%") || EF.Functions.ILike(x.Curriculum.Teacher.FullName, $"%{filter.Q}%") || EF.Functions.ILike(x.Curriculum.Field.Title, $"%{filter.Q}%")); } if (filter.Status.HasValue) { query = query.Where(x => x.Status == (StudentCurriculumStatus)filter.Status.Value); } if (filter.SemesterId.HasValue) { query = query.Where(x => x.Curriculum.Semester.Id == filter.SemesterId.Value); } return(await query.MapTo <TOutput>().SortBy(filter) .ToPagedListAsync(filter.Count, filter.Page, cancellationToken)); }
/// <summary> /// Deletes the specified entity or entities based off provided expression. /// </summary> /// <param name="entity"></param> public void Delete <T>(Expression <Func <T, bool> > expression, bool deleteAll = false) { string query = ""; try { string table = typeof(T).Name; string condition = QueryUtil.Translate(expression); query = deleteAll ? BaseQuery.DELETE_WHERE <T>(new string[] { table, condition }) : BaseQuery.DELETE_FIRST_WHERE <T>(new string[] { table, condition }); SqlUtil.ExecuteDynamicQuery(query); } catch (Exception ex) { var message = ex.Message; while (ex.InnerException != null) { ex = ex.InnerException; message += "\n" + ex.Message; } throw new Exception(message); } }
public static async Task <Stream> Get(Uri uri, BaseQuery param) { uri = new UriBuilder(uri) { Query = param.ToString() }.Uri; using (var token = new CancellationTokenSource()) { var get = await http.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, token.Token); if (Option.no_mime_type_check == false) { var ctype = get.Content.Headers.ContentType; var jsontype = new MediaTypeHeaderValue("application/json"); if (param.json && !ctype.Equals(jsontype)) { token.Cancel(); throw new HttpRequestException($"HTTP returned unexpected ContentType {ctype}, expecting {jsontype}."); } } return(await get.Content.ReadAsStreamAsync()); } }
public override async Task <IPagedList <TOutput> > FilterAsync <TOutput>(FilterBase filter, CancellationToken cancellationToken = default) { var query = BaseQuery.AsNoTracking(); return(await query.MapTo <TOutput>().SortBy(filter) .ToPagedListAsync(filter.Count, filter.Page, cancellationToken)); }
private static string SerializeBatchQueryItem(BaseQuery query) { var rawData = JsonConvert.SerializeObject(query); var typeName = query.GetType().FullName; var data = rawData.Insert(1, $"\"__type\":\"{typeName}\","); return(data); }
public ElasticSearchQuery(BaseQuery query, BaseQuery filterQuery, IEnumerable <QueryMethod> methods, IEnumerable <IFieldQueryTranslator> virtualFieldProcessors, IEnumerable <FacetQuery> facetQueries) { Query = query; Filter = filterQuery; Methods = methods.ToList(); VirtualFieldProcessors = virtualFieldProcessors.ToList(); FacetQueries = (facetQueries != null) ? facetQueries.ToList() : new List <FacetQuery>(); }
public IEnumerable <object> GetData(IQueryCollection queryCollection) { var dictionary = queryCollection.ToDictionary(k => k.Key, v => v.Value); dictionary["pagination[perpage]"] = $"{int.MaxValue}"; return(BaseQuery.QueryPaged(new QueryCollection(dictionary), Transform).Data .Select(i => ExportTransform(i))); }
/// <inheritdoc /> /// <summary> /// 数量 /// </summary> /// <param name="query"></param> /// <returns></returns> public int Count <TEntity>(BaseQuery <TEntity> query) { ISession session = Session; var count = Select(query, session).Where(Where(query)).Count(); session.Close(); return(count); }
public static IQueryable <T> ApplyPaging <T>(this IQueryable <T> queryable, BaseQuery paging) { if (paging.PageSizeValue > 0) { queryable = queryable.Skip(paging.SkipCount).Take(paging.PageSizeValue); } return(queryable); }
public frmFilmBoxOffice(string Name) { InitializeComponent(); baseQuery = new BaseQuery(); dgvList.CellFormatting += new DataGridViewCellFormattingEventHandler(dgvList_CellFormatting); this.name = Name; }
public DaneKontrahenta this[IDaneKontrahentaHost host, int typ] { get { var tableName = host.Table.TableName; var id = host.ID; return(BaseQuery.Where(r => r.HostType == tableName && r.Host == id && r.Typ == typ).FirstOrDefault()); } }
public virtual async Task <T> GetAsync(long id) { var result = await BaseQuery.FirstOrDefaultAsync(x => x.Id == id); if (result == null) { throw new NotFoundException(typeof(Food), id); } return(result); }
public (List <SysOrganize>, int) GetOrganizePage(BaseQuery baseQuery) { var query = ExpressionBuilder.True <SysOrganize>(); query = query.And(m => m.IsDrop == false); int Total = _organizeRepositoty.Count(query); var list = this._organizeRepositoty.PageBy(baseQuery.PageIndex, baseQuery.PageSize, query).ToList(); return(list, Total); }
/// <summary> /// Describe the query to perform using the static Query class /// </summary> public virtual RescoreQueryDescriptor <T> Query(BaseQuery query) { query.ThrowIfNull("query"); if (query.IsConditionless) { return(this); } this._Query = query; return(this); }
public async Task <PageResult <DataDictionaryOutDto> > GetResultAsync(BaseQuery query) { var param = new PageParameters(query.PageIndex, query.PageRow); param.OrderConditions = new OrderCondition[] { new OrderCondition(query.SortName, query.SortDirection) }; return(await _dataDictionary.NoTrackEntities.ToPageAsync <DataDictionaryEntity, DataDictionaryOutDto>(x => x.IsDeleted == false, param)); }
public DokHandlowe this[string symbol] { get { return(new DokHandlowe() { BaseQuery = GetQuery(BaseQuery.Where(dh => dh.NumerSymbol == symbol)) }); } }
public IEnumerable <ISearchHit> Search() { _client.Search <object>(x => x .Index(_indexName) .AllTypes() .Query(q => { BaseQuery query = null; query &= q.Term("Foo", "poo"); return(query); }) ); //QueryDescriptor s = new QueryDescriptor(); //s. //var query = CreateQuery(); //IndexSearcher searcher; //try { // searcher = new IndexSearcher(_directory, true); //} //catch { // // index might not exist if it has been rebuilt // Logger.Information("Attempt to read a none existing index"); // return Enumerable.Empty<ISearchHit>(); //} //using (searcher) { // var sort = String.IsNullOrEmpty(_sort) // ? Sort.RELEVANCE // : new Sort(new SortField(_sort, _comparer, _sortDescending)); // var collector = TopFieldCollector.Create( // sort, // _count + _skip, // false, // true, // false, // true); // Logger.Debug("Searching: {0}", query.ToString()); // searcher.Search(query, collector); // var results = collector.TopDocs().ScoreDocs // .Skip(_skip) // .Select(scoreDoc => new LuceneSearchHit(searcher.Doc(scoreDoc.Doc), scoreDoc.Score)) // .ToList(); // Logger.Debug("Search results: {0}", results.Count); // return results; //} }
public override async Task <IPagedList <TOutput> > FilterAsync <TOutput>(FilterBase filter, CancellationToken cancellationToken = default) { var query = BaseQuery.AsNoTracking(); if (!string.IsNullOrEmpty(filter.Q)) { query = query.Where(x => x.Title.Contains(filter.Q)); } return(await query.MapTo <TOutput>().SortBy(filter).ToPagedListAsync(filter.Count, filter.Page, cancellationToken)); }
private void DoValidSemiStrictBoolQueryStatic(BaseQuery query) { Assert.DoesNotThrow(() => { var s = new SearchDescriptor<ElasticsearchProject>() .From(0) .Take(10) .Query(query); this.JsonNotEquals(s, System.Reflection.MethodInfo.GetCurrentMethod(), "MatchAll"); }); }