private static object ExecuteAllDimensions(MethodCallExpression methodExpression, Type returnType, DatastoreService dsService) { if (methodExpression.Arguments.Count < 1) { throw new InvalidOperationException("Missing arguments for the AllDimensions expression."); } // This comes from IDatastoreQueryable<TSourceType, TResultType> var sourceType = GetGenericArgument(returnType, 0); var parser = new DatastoreExpressionParser(); parser.Visit(methodExpression.Arguments[0]); var dataQuery = BuildDataQueryFromParser(parser); dataQuery.IncludeDimensions = true; dataQuery.IncludeAllDimensions = false; dataQuery.IncludeRecords = false; dataQuery.ExcludeCount = true; var results = dsService.Query(dataQuery); var allDimensions = new List <DimensionItem>(); foreach (var d in results.DimensionList) { allDimensions.Add((DimensionItem)((ICloneable)d).Clone()); } var dimensionStore = Activator.CreateInstance( typeof(DimensionStore <>).MakeGenericType(sourceType), new object[] { allDimensions, results.Query.NonParsedFieldList }); return(dimensionStore); }
private static ActionDiagnostics ExecuteDelete(MethodCallExpression methodExpression, Type returnType, DatastoreService dsService) { if (methodExpression.Arguments.Count < 1) { throw new InvalidOperationException("Invalid argument count for the Delete expression."); } var parser = new DatastoreExpressionParser(); parser.Visit(methodExpression.Arguments[0]); var dataQuery = BuildDataQueryFromParser(parser); return(dsService.DeleteData(dataQuery)); }
private static object ExecuteToSlice(MethodCallExpression methodExpression, Type returnType, DatastoreService dsService) { if (methodExpression.Arguments.Count < 1) { throw new InvalidOperationException("Missing arguments for the Results expression."); } var parser = new DatastoreExpressionParser(); parser.Visit(methodExpression.Arguments[0]); var dataQuery = BuildDataSliceQueryFromParser(parser); return(dsService.CalculateSlice(dataQuery)); }
private static DataQuery GetAggregateParser(MethodCallExpression methodExpression) { var parser = new DatastoreExpressionParser(); parser.Visit(methodExpression.Arguments[0]); var dataQuery = BuildDataQueryFromParser(parser); dataQuery.IncludeDimensions = false; dataQuery.IncludeAllDimensions = false; dataQuery.IncludeRecords = false; dataQuery.ExcludeCount = true; dataQuery.FieldSelects = null; return(dataQuery); }
private static object ExecuteResultsAsync(MethodCallExpression methodExpression, Type returnType, DatastoreService dsService) { if (methodExpression.Arguments.Count < 1) { throw new InvalidOperationException("Missing arguments for the Results expression."); } var parser = new DatastoreExpressionParser(); parser.Visit(methodExpression.Arguments[0]); var dataQuery = BuildDataQueryFromParser(parser); var flags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance; var retval = Activator.CreateInstance(type: returnType, bindingAttr: flags, binder: null, args: new object[] { dsService, dataQuery }, culture: CultureInfo.CurrentCulture); return(retval); //return new DatastoreResultsAsync<object>(dsService, dataQuery); }
private static SummarySlice BuildDataSliceQueryFromParser(DatastoreExpressionParser parser) { var dataQuery = new SummarySlice(); if (parser.Query.FieldFilters != null) { dataQuery.Query.FieldFilters = parser.Query.FieldFilters; } if (parser.Query.FieldSorts != null) { dataQuery.Query.FieldSorts = parser.Query.FieldSorts; } dataQuery.Query.PageOffset = parser.Query.PageOffset; dataQuery.Query.RecordsPerPage = parser.Query.RecordsPerPage; if (parser.Query.Keyword != null) { dataQuery.Query.Keyword = parser.Query.Keyword; } if (parser.Users != null) { dataQuery.Query.UserList = parser.Users; } if (parser.Query.DimensionValueList != null) { dataQuery.Query.DimensionValueList = parser.Query.DimensionValueList; } if (parser.Query.SkipDimensions != null) { dataQuery.Query.SkipDimensions = parser.Query.SkipDimensions; } dataQuery.GroupFields = parser.SliceQuery.GroupFields; dataQuery.SpliceDName = parser.SliceQuery.SpliceDName; return(dataQuery); }
private static object ExecuteCount(MethodCallExpression methodExpression, Type returnType, DatastoreService dsService) { if (methodExpression.Arguments.Count < 1) { throw new InvalidOperationException("Missing arguments for the Count expression."); } var parser = new DatastoreExpressionParser(); parser.Visit(methodExpression.Arguments[0]); var dataQuery = BuildDataQueryFromParser(parser); dataQuery.IncludeDimensions = false; dataQuery.IncludeAllDimensions = false; dataQuery.IncludeRecords = false; dataQuery.ExcludeCount = false; var result = dsService.Query(dataQuery); return(result.TotalRecordCount); }
private static ActionDiagnostics ExecuteUpdate(MethodCallExpression methodExpression, Type returnType, DatastoreService dsService) { if (methodExpression.Arguments.Count < 1) { throw new InvalidOperationException("Invalid argument count for the Update expression."); } var parser = new DatastoreExpressionParser(); parser.Visit(methodExpression.Arguments[0]); var dataQuery = BuildDataQueryFromParser(parser); if (parser.FieldUpdates == null || parser.FieldUpdates.Count == 0) { return new ActionDiagnostics { IsSuccess = false } } ; //throw new InvalidOperationException("No field updates specified"); return(dsService.UpdateDataWhere(dataQuery, parser.FieldUpdates)); }
private static object ExecuteItems2(MethodCallExpression methodExpression, Type returnType, DatastoreService dsService) { if (methodExpression.Arguments.Count < 1) { throw new InvalidOperationException("Missing arguments for the Items expression."); } var parser = new DatastoreExpressionParser(); parser.Visit(methodExpression.Arguments[0]); var dataQuery = BuildDataQueryFromParser(parser); dataQuery.IncludeDimensions = false; dataQuery.IncludeAllDimensions = false; dataQuery.IncludeRecords = true; var itemType = GetGenericArgument(returnType, 0); var dsItems = Activator.CreateInstance(typeof(DatastoreItems <>).MakeGenericType(itemType)); var results = dsService.Query(dataQuery); SetResultItems(dsItems, itemType, dataQuery, results, parser.SelectExpression); return(dsItems); }
private static object ExecuteResults(MethodCallExpression methodExpression, Type returnType, DatastoreService dsService) { if (methodExpression.Arguments.Count < 1) { throw new InvalidOperationException("Missing arguments for the Results expression."); } var parser = new DatastoreExpressionParser(); parser.Visit(methodExpression.Arguments[0]); var dataQuery = BuildDataQueryFromParser(parser); var results = dsService.Query(dataQuery); var sourceType = GetGenericArgument(returnType, 0); #region Create the dimensions var dimensions = new List <DimensionItem>(); foreach (var d in results.DimensionList) { dimensions.Add((DimensionItem)((ICloneable)d).Clone()); } var dimensionStore = Activator.CreateInstance( typeof(DimensionStore <>).MakeGenericType(sourceType), new object[] { dimensions, results.Query.NonParsedFieldList }); #endregion #region Create the ALL dimensions var allDimensions = new List <DimensionItem>(); foreach (var d in results.AllDimensionList) { allDimensions.Add((DimensionItem)((ICloneable)d).Clone()); } var allDimensionStore = Activator.CreateInstance( typeof(DimensionStore <>).MakeGenericType(sourceType), new object[] { allDimensions, results.Query.NonParsedFieldList }); #endregion #region Create the APPLIED dimensions var appliedDimensions = new List <DimensionItem>(); foreach (var d in results.AppliedDimensionList) { appliedDimensions.Add((DimensionItem)((ICloneable)d).Clone()); } var appliedDimensionstore = Activator.CreateInstance( typeof(DimensionStore <>).MakeGenericType(sourceType), new object[] { appliedDimensions, results.Query.NonParsedFieldList }); #endregion var dsResults = Activator.CreateInstance(typeof(DatastoreResults <>).MakeGenericType(sourceType)); SetProperty(dsResults, "DimensionStore", dimensionStore); SetProperty(dsResults, "AppliedDimensionList", appliedDimensionstore); SetProperty(dsResults, "AppliedFieldFilterList", results.Query.FieldFilters ?? new List <IFieldFilter>()); SetProperty(dsResults, "AllDimensions", allDimensionStore); SetProperty(dsResults, "DerivedFieldList", results.DerivedFieldList?.ToList()); SetResultItems(dsResults, sourceType, dataQuery, results, parser.SelectExpression); var diag = new ResultDiagnostics { CacheHit = results.CacheHit, ComputeTime = results.ComputeTime, LockTime = results.LockTime, DataVersion = results.DataVersion, VersionHash = results.VersionHash, RepositoryId = dsService.RepositoryId, }; SetProperty(dsResults, "Diagnostics", diag); SetProperty(dsResults, "Query", ((ICloneable)results.Query).Clone()); return(dsResults); }
private static DataQuery BuildDataQueryFromParser(DatastoreExpressionParser parser) { var dataQuery = new DataQuery(string.IsNullOrEmpty(parser.Url) ? "?" : parser.Url); if (parser.Query.FieldFilters != null) { dataQuery.FieldFilters = parser.Query.FieldFilters; } if (parser.Query.FieldSorts != null) { dataQuery.FieldSorts = parser.Query.FieldSorts; } dataQuery.PageOffset = parser.Query.PageOffset; dataQuery.RecordsPerPage = parser.Query.RecordsPerPage; dataQuery.NonParsedFieldList = parser.Query.NonParsedFieldList; dataQuery.IncludeDimensions = parser.Query.IncludeDimensions; dataQuery.IncludeAllDimensions = parser.Query.IncludeAllDimensions; dataQuery.IncludeRecords = parser.Query.IncludeRecords; dataQuery.ExcludeCount = parser.Query.ExcludeCount; dataQuery.IncludeEmptyDimensions = parser.Query.IncludeEmptyDimensions; dataQuery.ExcludeDimensionCount = parser.Query.ExcludeDimensionCount; dataQuery.IPMask = parser.Query.IPMask; dataQuery.DerivedFieldList = parser.Query.DerivedFieldList; if (parser.Query.Keyword != null) { dataQuery.Keyword = parser.Query.Keyword; } if (parser.Users != null) { dataQuery.UserList = parser.Users; } if (parser.Query.DimensionValueList != null) { dataQuery.DimensionValueList = parser.Query.DimensionValueList; } if (parser.Query.SkipDimensions != null) { dataQuery.SkipDimensions = parser.Query.SkipDimensions; } if (parser.SelectList != null) { dataQuery.FieldSelects = new List <string>(); dataQuery.FieldSelects.AddRange(parser.SelectList); } //else //{ // if (parser.DerivedFieldList != null) // { // dataQuery.DerivedFieldList = parser.DerivedFieldList; // } //} if (parser.Query.GroupFields != null) { dataQuery.GroupFields = new List <string>(); dataQuery.GroupFields.AddRange(parser.Query.GroupFields); } dataQuery.IncludeEmptyDimensions = parser.Query.IncludeEmptyDimensions; dataQuery.ExcludeDimensionCount = parser.Query.ExcludeDimensionCount; return(dataQuery); }