public GetDataResult ServiceGetData(GetDataInfo getInfo) { GetDataResult res = null; this._currentOperation = ServiceOperationType.GetData; try { res = this.GetData(getInfo); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } res = new GetDataResult() { pageIndex = getInfo.pageIndex, pageCount = getInfo.pageCount, rows = new Row[0], dbSetName = getInfo.dbSetName, totalCount = null, error = new ErrorInfo(ex.Message, ex.GetType().Name) }; this.OnError(ex); } finally { this._currentOperation = ServiceOperationType.None; } return(res); }
/// <summary> /// Utility method to obtain data from service query method /// mainly used to embed data on page load, and fill classifiers for lookup data /// </summary> /// <param name="dbSetName"></param> /// <param name="queryName"></param> /// <returns></returns> public GetDataResult GetQueryData(string dbSetName, string queryName) { GetDataInfo getInfo = new GetDataInfo { dbSetName = dbSetName, queryName = queryName }; return(ServiceGetData(getInfo)); }
protected GetDataResult GetData(GetDataInfo getInfo) { var metadata = this.EnsureMetadataInitialized(); List <MethodDescription> methodList = metadata.methodDescriptions; MethodDescription method = methodList.Where((m) => m.methodName == getInfo.queryName && m.isQuery == true).FirstOrDefault(); if (method == null) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_QUERY_NAME_INVALID, getInfo.queryName)); } this.Authorizer.CheckUserRightsToExecute(method.methodInfo); getInfo.dbSetInfo = metadata.dbSets[getInfo.dbSetName]; bool isMultyPageRequest = getInfo.dbSetInfo.enablePaging && getInfo.pageCount > 1; QueryResult queryResult = null; int? totalCount = null; List <object> methParams = new List <object>(); methParams.Add(getInfo); for (var i = 0; i < method.parameters.Count; ++i) { methParams.Add(getInfo.paramInfo.GetValue(method.parameters[i].name, method, this.DataHelper)); } queryResult = (QueryResult)method.methodInfo.Invoke(this, methParams.ToArray()); IEnumerable entities = (IEnumerable)queryResult.Result; totalCount = queryResult.TotalCount; int rowCnt = 0; LinkedList <object> entityList = new LinkedList <object>(); foreach (object entity in entities) { entityList.AddLast(entity); ++rowCnt; } var rows = this.CreateRows(getInfo.dbSetInfo, entityList, rowCnt); IEnumerable <IncludedResult> subResults = this.CreateIncludedResults(getInfo.dbSetInfo, entityList, queryResult.includeNavigations); GetDataResult res = new GetDataResult() { pageIndex = getInfo.pageIndex, pageCount = getInfo.pageCount, dbSetName = getInfo.dbSetName, names = getInfo.dbSetInfo.fieldInfos.Where(f => f.isIncludeInResult()).OrderBy(f => f._ordinal).Select(fi => fi.fieldName), totalCount = totalCount, extraInfo = queryResult.extraInfo, rows = rows, rowCount = rowCnt, fetchSize = getInfo.dbSetInfo.FetchSize, included = subResults, error = null }; return((GetDataResult)res); }
public QueryResult<FolderModel> ReadChildren(GetDataInfo getInfo, string parentKey, int level, string path, bool includeFiles) { string fullpath = Path.GetFullPath(Path.Combine(ROOT,path)); DirectoryInfo dinfo = new DirectoryInfo(fullpath); if (!includeFiles) { var dirs = dinfo.EnumerateDirectories(); var res = dirs.Select(d => new FolderModel { Key = Guid.NewGuid().ToString(), ParentKey = parentKey, HasSubDirs = d.EnumerateDirectories().Any(), Level = level, Name = d.Name, IsFolder = true }).OrderBy(d=>d.Name); return new QueryResult<FolderModel>(res); } else { var fileSyst = dinfo.EnumerateFileSystemInfos(); var res2 = fileSyst.Select(d => new FolderModel { Key = Guid.NewGuid().ToString(), ParentKey = parentKey, HasSubDirs = (d is DirectoryInfo) ? ((DirectoryInfo)d).EnumerateFileSystemInfos().Any() : false, Level = level, Name = d.Name, IsFolder = (d is DirectoryInfo) }).OrderByDescending(d=>d.IsFolder).ThenBy(d=>d.Name); return new QueryResult<FolderModel>(res2); } }
public QueryResult<FolderModel> ReadRoot(GetDataInfo getInfo, bool includeFiles) { return ReadChildren(getInfo, null, 0, "", includeFiles); }