Ejemplo n.º 1
0
        public SubsetList CreateSubsets(IEnumerable <SubResult> subResults)
        {
            SubsetList result = new SubsetList();

            if (subResults == null)
            {
                return(result);
            }

            foreach (SubResult subResult in subResults)
            {
                DbSetInfo dbSetInfo = _metadata.DbSets[subResult.dbSetName];

                if (result.Any(r => r.dbSetName == subResult.dbSetName))
                {
                    throw new DomainServiceException(string.Format("The included sub results already have DbSet {0} entities", dbSetInfo.dbSetName));
                }

                RowGenerator rowGenerator = new RowGenerator(dbSetInfo, subResult.Result, _dataHelper);

                Subset current = new Subset
                {
                    dbSetName = dbSetInfo.dbSetName,
                    rows      = rowGenerator.CreateDistinctRows(),
                    names     = dbSetInfo.GetNames()
                };

                result.Add(current);
            }

            return(result);
        }
Ejemplo n.º 2
0
        private void CreateSubset(DbSetInfo dbSetInfo, IEnumerable <object> inputEntities, string propertyName,
                                  string[] nextParts, Dictionary <string, Subset> visited)
        {
            var       metadata        = MetadataHelper.GetInitializedMetadata(_domainService);
            var       isChildProperty = false;
            DbSetInfo nextDbSetInfo   = null;
            var       assoc           = metadata.associations.Values.Where(
                a => a.parentDbSetName == dbSetInfo.dbSetName && a.parentToChildrenName == propertyName)
                                        .FirstOrDefault();

            if (assoc != null)
            {
                isChildProperty = true;
                nextDbSetInfo   = metadata.dbSets[assoc.childDbSetName];
            }
            else
            {
                assoc = metadata.associations.Values.Where(
                    a => a.childDbSetName == dbSetInfo.dbSetName && a.childToParentName == propertyName)
                        .FirstOrDefault();
                if (assoc == null)
                {
                    throw new DomainServiceException(string.Format(ErrorStrings.ERR_INCL_NAVIG_INVALID,
                                                                   propertyName + (nextParts.Length > 0 ? "." + string.Join(".", nextParts) : "")));
                }

                nextDbSetInfo = metadata.dbSets[assoc.parentDbSetName];
            }

            if (visited.ContainsKey(nextDbSetInfo.dbSetName + "." + propertyName))
            {
                return;
            }

            var resultEntities = this.GetResultEntities(inputEntities, propertyName, isChildProperty);

            //create temporary result without rows
            //fills rows at the end of the method
            var current = new Subset
            {
                dbSetName = nextDbSetInfo.dbSetName,
                rows      = new Row[0],
                names     = nextDbSetInfo.GetNames()
            };

            visited.Add(nextDbSetInfo.dbSetName + "." + propertyName, current);
            if (nextParts.Length > 0)
            {
                CreateSubset(nextDbSetInfo, resultEntities, nextParts[0], nextParts.Skip(1).ToArray(), visited);
            }

            var rowGenerator = new RowGenerator(nextDbSetInfo, resultEntities, _dataHelper);

            current.rows = rowGenerator.CreateDistinctRows();
        }
Ejemplo n.º 3
0
        public async Task Invoke(QueryContext <TService> ctx)
        {
            DbSetInfo dbSetInfo = ctx.Request.GetDbSetInfo() ?? throw new InvalidOperationException($"Could not get the DbSet for {ctx.Request.dbSetName}");
            IDataHelper <TService> dataHelper = ctx.ServiceContainer.GetDataHelper();
            IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper();
            RunTimeMetadata metadata = ctx.Service.GetMetadata();

            MethodDescription method = metadata.GetQueryMethod(ctx.Request.dbSetName, ctx.Request.queryName);

            LinkedList <object> methParams = new LinkedList <object>();

            for (int i = 0; i < method.parameters.Count; ++i)
            {
                methParams.AddLast(ctx.Request.paramInfo.GetValue(method.parameters[i].name, method, dataHelper));
            }

            RequestContext req = QueryContext <TService> .CreateRequestContext(ctx.Service, ctx.Request);

            using (RequestCallContext callContext = new RequestCallContext(req))
            {
                MethodInfoData methodData  = method.GetMethodData();
                object         instance    = serviceHelper.GetMethodOwner(methodData);
                object         invokeRes   = methodData.MethodInfo.Invoke(instance, methParams.ToArray());
                QueryResult    queryResult = (QueryResult)await serviceHelper.GetMethodResult(invokeRes);

                IEnumerable <object> entities  = queryResult.Result;
                int?              totalCount   = queryResult.TotalCount;
                RowGenerator      rowGenerator = new RowGenerator(dbSetInfo, entities, dataHelper);
                IEnumerable <Row> rows         = rowGenerator.CreateRows();

                SubsetsGenerator subsetsGenerator = new SubsetsGenerator(metadata, dataHelper);
                SubsetList       subResults       = subsetsGenerator.CreateSubsets(queryResult.subResults);

                ctx.Response.names      = dbSetInfo.GetNames();
                ctx.Response.totalCount = totalCount;
                ctx.Response.rows       = rows;
                ctx.Response.subsets    = subResults;
                ctx.Response.extraInfo  = queryResult.extraInfo;
            }

            await _next(ctx);
        }
Ejemplo n.º 4
0
        protected virtual void TrackChangesToEntity(RowInfo rowInfo)
        {
            DbSetInfo dbSetInfo = rowInfo.GetDbSetInfo();

            if (!dbSetInfo.GetIsTrackChanges())
            {
                return;
            }

            try
            {
                string[] changed = new string[0];
                switch (rowInfo.changeType)
                {
                case ChangeType.Updated:
                {
                    changed = rowInfo.GetChangeState().ChangedFieldNames;
                }
                break;

                default:
                {
                    changed = dbSetInfo.GetNames().Select(f => f.n).ToArray();
                }
                break;
                }

                string[] pknames  = dbSetInfo.GetPKFields().Select(f => f.fieldName).ToArray();
                string   diffgram = DiffGram.GetDiffGram(rowInfo.GetChangeState().OriginalEntity,
                                                         rowInfo.changeType == ChangeType.Deleted ? null : rowInfo.GetChangeState().Entity,
                                                         dbSetInfo.GetEntityType(), changed, pknames, rowInfo.changeType, dbSetInfo.dbSetName);

                OnTrackChange(dbSetInfo.dbSetName, rowInfo.changeType, diffgram);
            }
            catch (Exception ex)
            {
                _OnError(ex);
            }
        }