Esempio n. 1
0
        public void DispatchForEntity(GOGroupRoleDataObject entity, List <string> includes, IObjectsDataSet context, Dictionary <string, object> parameters, bool skipSecurity = false)
        {
            // Remember includes we've already dispatched so as to avoid multiple data fetches
            var dispatched = new HashSet <string>();

            // get (custom) prefetch list so we can skip the dispatch for stuff we already fetched
            var prefetches = PrefetchAssociations.Get("GOGroupRole", parameters);

            foreach (var include in includes)
            {
                string relation    = include.Split('.').First().ToLower();
                var    subincludes = DispatchPath.GetSubIncludes(relation, includes);

                if (relation.Contains(":"))
                {
                    relation = relation.Substring(relation.IndexOf(':') + 1);
                }

                if (dispatched.Contains(relation))
                {
                    continue;
                }

                dispatched.Add(relation);

                switch (relation)
                {
                case "group":
                {
                    // custom code can implement IPrefetch<ORMGOGroupRole> and add prefetch info through PrefetchAssociations helper => if set, we skip the dispatch-fetch
                    if (prefetches.Contains("Group"))
                    {
                        break;
                    }

                    try
                    {
                        var objectToFetch = GOGroupDataProvider.Get(new GOGroupDataObject(entity.GOGroupName), null, subincludes, context, parameters, skipSecurity);
                        if (objectToFetch != null)
                        {
                            entity.ObjectsDataSet.Merge(objectToFetch.ObjectsDataSet);
                        }
                    }
                    catch (GOServerException e)
                    {
                        if (e.Reason != "accessDenied")
                        {
                            throw;
                        }
                    }
                    break;
                }

                case "role":
                {
                    // custom code can implement IPrefetch<ORMGOGroupRole> and add prefetch info through PrefetchAssociations helper => if set, we skip the dispatch-fetch
                    if (prefetches.Contains("Role"))
                    {
                        break;
                    }

                    try
                    {
                        var objectToFetch = GORoleDataProvider.Get(new GORoleDataObject(entity.GORoleName), null, subincludes, context, parameters, skipSecurity);
                        if (objectToFetch != null)
                        {
                            entity.ObjectsDataSet.Merge(objectToFetch.ObjectsDataSet);
                        }
                    }
                    catch (GOServerException e)
                    {
                        if (e.Reason != "accessDenied")
                        {
                            throw;
                        }
                    }
                    break;
                }

                default:
                    throw new ApplicationException("GOGroupRole Entity has no relation named " + relation);
                }
            }
        }
        public void DispatchForEntityCollection(IEnumerable <GOUserGroupDataObject> entities, List <string> includes, IObjectsDataSet context, Dictionary <string, object> parameters, bool skipSecurity = false)
        {
            // Remember includes we've already dispatched so as to avoid multiple data fetches
            var dispatched = new HashSet <string>();

            // get (custom) prefetch list so we can skip the dispatch for stuff we already fetched
            var prefetches = PrefetchAssociations.Get("GOUserGroup", parameters);

            foreach (var include in includes)
            {
                string relation    = include.Split('.').First().ToLower();
                var    subincludes = DispatchPath.GetSubIncludes(relation, includes);

                if (relation.Contains(":"))
                {
                    relation = relation.Substring(relation.IndexOf(':') + 1);
                }

                if (dispatched.Contains(relation))
                {
                    continue;
                }

                dispatched.Add(relation);

                switch (relation)
                {
                case "group":
                {
                    // custom code can implement IPrefetch<ORMGOUserGroup> and add prefetch info through PrefetchAssociations helper => if set, we skip the dispatch-fetch
                    if (prefetches.Contains("Group"))
                    {
                        break;
                    }

                    var filterparameters = new object[] { entities.Select(e => e.GOGroupName).Distinct().ToArray() };
                    try
                    {
                        entities.First().ObjectsDataSet.Merge(GOGroupDataProvider.GetCollection(null, "(@0.Contains(outerIt.Name))", filterparameters, null, 0, 0, subincludes, context, parameters, skipSecurity).ObjectsDataSet);
                    }
                    catch (GOServerException e)
                    {
                        if (e.Reason != "accessDenied")
                        {
                            throw;
                        }
                    }
                    break;
                }

                case "user":
                {
                    // custom code can implement IPrefetch<ORMGOUserGroup> and add prefetch info through PrefetchAssociations helper => if set, we skip the dispatch-fetch
                    if (prefetches.Contains("User"))
                    {
                        break;
                    }

                    var filterparameters = new object[] { entities.Select(e => e.GOUserId).Distinct().ToArray() };
                    try
                    {
                        entities.First().ObjectsDataSet.Merge(GOUserDataProvider.GetCollection(null, "(@0.Contains(outerIt.Id))", filterparameters, null, 0, 0, subincludes, context, parameters, skipSecurity).ObjectsDataSet);
                    }
                    catch (GOServerException e)
                    {
                        if (e.Reason != "accessDenied")
                        {
                            throw;
                        }
                    }
                    break;
                }

                default:
                    throw new ApplicationException("GOUserGroup Entity has no relation named " + relation);
                }
            }
        }