Пример #1
0
        public virtual object HandleVlvRequest(DirectoryConnection connection, int maxSize, ILinqToLdapLogger log)
        {
            if (Options.YieldNoResults)
            {
                var enumerator  = Options.GetEnumerator();
                var bindingAttr = new[]
                {
                    0,
                    null,
                    0,
                    enumerator
                };

                return(ObjectActivator.CreateGenericInstance(typeof(VirtualListView <>), Options.GetEnumeratorReturnType(), bindingAttr, null));
            }

            if (GetControl <SortRequestControl>(SearchRequest.Controls) == null)
            {
                throw new InvalidOperationException("Virtual List Views require a sort operation. Please include an OrderBy in your query.");
            }

            var skip = Options.SkipSize.GetValueOrDefault();

            if (GetControl <VlvRequestControl>(SearchRequest.Controls) == null)
            {
                VlvRequestControl vlvRequest =
                    new VlvRequestControl(0, Options.TakeSize.GetValueOrDefault(maxSize) - 1, skip + 1)
                {
                    IsCritical = false
                };

                SearchRequest.Controls.Add(vlvRequest);
            }

            if (log != null && log.TraceEnabled)
            {
                log.Trace(SearchRequest.ToLogString());
            }
            var response = connection.SendRequest(SearchRequest) as SearchResponse;

            response.AssertSuccess();

            AssertSortSuccess(response.Controls);

            var vlvResponse = GetControl <VlvResponseControl>(response.Controls);

            if (vlvResponse == null)
            {
                throw new InvalidOperationException("The server does not support Virtual List Views. Skip cannot be used. Please use standard paging.");
            }
            var parameters = new[]
            {
                vlvResponse.ContentCount,
                vlvResponse.ContextId,
                vlvResponse.TargetPosition,
                Options.GetEnumerator(response.Entries)
            };

            return(ObjectActivator.CreateGenericInstance(typeof(VirtualListView <>), Options.GetEnumeratorReturnType(), parameters, null));
        }
Пример #2
0
        public virtual object HandlePagedRequest(DirectoryConnection connection, PageResultRequestControl pageRequest, ILinqToLdapLogger log)
        {
            object enumerator;

            if (Options.YieldNoResults)
            {
                enumerator = Options.GetEnumerator();
                var bindingAttr = new[]
                {
                    pageRequest.PageSize,
                    null,
                    enumerator,
                    null
                };

                return(ObjectActivator.CreateGenericInstance(typeof(LdapPage <>), Options.GetEnumeratorReturnType(), bindingAttr, null));
            }

            if (pageRequest == null)
            {
                pageRequest = new PageResultRequestControl(Options.PagingOptions.PageSize)
                {
                    Cookie = Options.PagingOptions.NextPage
                };

                SearchRequest.Controls.Add(pageRequest);
            }

            if (log != null && log.TraceEnabled)
            {
                log.Trace(SearchRequest.ToLogString());
            }
            var response = connection.SendRequest(SearchRequest) as SearchResponse;

            response.AssertSuccess();

            AssertSortSuccess(response.Controls);

            enumerator = Options.GetEnumerator(response.Entries);
            var nextPage   = GetControl <PageResultResponseControl>(response.Controls);
            var parameters = new[]
            {
                pageRequest.PageSize,
                nextPage?.Cookie,
                enumerator,
                Options.Filter
            };

            return(ObjectActivator.CreateGenericInstance(typeof(LdapPage <>), Options.GetEnumeratorReturnType(), parameters, null));
        }
Пример #3
0
        public void CreateGenericInstance_performance()
        {
            var watch = Stopwatch.StartNew();

            for (int i = 0; i < Iterations; i++)
            {
                var parameters = new object[]
                {
                    100,
                    new byte[0],
                    new string[0],
                    ""
                };
                var inst = ObjectActivator.CreateGenericInstance(typeof(LdapPage <>), typeof(string), parameters, null);
            }
            watch.Stop();
            Trace.WriteLine(watch.ElapsedMilliseconds);
        }
Пример #4
0
        public IQueryable CreateQuery(Expression expression)
        {
            var elementType = TypeSystem.GetElementType(expression.Type);

            return((IQueryable)ObjectActivator.CreateGenericInstance(typeof(DirectoryQuery <>), elementType, new object[] { this, expression }, null));
        }
Пример #5
0
        public virtual object HandleStandardRequest(DirectoryConnection connection, ILinqToLdapLogger log, int maxSize, bool pagingEnabled)
        {
            if (Options.YieldNoResults)
            {
                return(ObjectActivator.CreateGenericInstance(typeof(List <>), Options.GetEnumeratorReturnType(), null, null));
            }

            int pageSize = 0;
            int index    = 0;

            if (pagingEnabled)
            {
                int maxPageSize = Options.PageSize ?? maxSize;
                pageSize = Options.TakeSize.HasValue ? Math.Min(Options.TakeSize.Value, maxPageSize) : maxPageSize;

                index = SearchRequest.Controls.Add(new PageResultRequestControl(pageSize));
            }

            if (log != null && log.TraceEnabled)
            {
                log.Trace(SearchRequest.ToLogString());
            }
            var response = connection.SendRequest(SearchRequest) as SearchResponse;

            response.AssertSuccess();

            var list = new List <SearchResultEntry>();

            list.AddRange(response.Entries.GetRange());

            if (pagingEnabled)
            {
                if (response.Entries.Count > 0)
                {
                    var  pageResultResponseControl = GetControl <PageResultResponseControl>(response.Controls);
                    bool hasMoreResults            = pageResultResponseControl != null && pageResultResponseControl.Cookie.Length > 0 && (!Options.TakeSize.HasValue || list.Count < Options.TakeSize.Value);
                    while (hasMoreResults)
                    {
                        SearchRequest.Controls[index] = new PageResultRequestControl(pageSize)
                        {
                            Cookie = pageResultResponseControl.Cookie
                        };
                        if (log != null && log.TraceEnabled)
                        {
                            log.Trace(SearchRequest.ToLogString());
                        }
                        response = connection.SendRequest(SearchRequest) as SearchResponse;
                        response.AssertSuccess();
                        pageResultResponseControl = GetControl <PageResultResponseControl>(response.Controls);
                        hasMoreResults            = pageResultResponseControl != null && pageResultResponseControl.Cookie.Length > 0 && (!Options.TakeSize.HasValue || list.Count <= Options.TakeSize.Value);

                        list.AddRange(response.Entries.GetRange());
                    }
                }
            }

            AssertSortSuccess(response.Controls);

            if (Options.TakeSize.HasValue && list.Count > Options.TakeSize.Value)
            {
                var size = Options.TakeSize.Value;
                list.RemoveRange(size, list.Count - size);
            }

            var enumerator = Options.GetEnumerator(list);

            return(ObjectActivator.CreateGenericInstance(typeof(List <>), Options.GetEnumeratorReturnType(), new[] { enumerator }, null));
        }
Пример #6
0
        public virtual async System.Threading.Tasks.Task <object> HandlePagedRequestAsync(LdapConnection connection, PageResultRequestControl pageRequest, ILinqToLdapLogger log)
        {
            if (Options.YieldNoResults)
            {
                var bindingAttr = new[]
                {
                    pageRequest.PageSize,
                    null,
                    Options.GetEnumerator(),
                    null
                };

                return(ObjectActivator.CreateGenericInstance(typeof(LdapPage <>), Options.GetEnumeratorReturnType(), bindingAttr, null));
            }

            if (pageRequest == null)
            {
                pageRequest = new PageResultRequestControl(Options.PagingOptions.PageSize)
                {
                    Cookie = Options.PagingOptions.NextPage
                };

                SearchRequest.Controls.Add(pageRequest);
            }

            if (log != null && log.TraceEnabled)
            {
                log.Trace(SearchRequest.ToLogString());
            }

#if NET45
            return(await System.Threading.Tasks.Task.Factory.FromAsync(
                       (callback, state) =>
            {
                return connection.BeginSendRequest(SearchRequest, Options.AsyncProcessing, callback, state);
            },
                       (asyncresult) =>
            {
                var response = (SearchResponse)connection.EndSendRequest(asyncresult);
                response.AssertSuccess();
                AssertSortSuccess(response.Controls);

                var enumerator = Options.GetEnumerator(response.Entries);
                var nextPage = GetControl <PageResultResponseControl>(response.Controls);
                var parameters = new[]
                {
                    pageRequest.PageSize,
                    nextPage?.Cookie,
                    enumerator,
                    Options.Filter
                };

                return ObjectActivator.CreateGenericInstance(typeof(LdapPage <>), Options.GetEnumeratorReturnType(), parameters, null);
            },
                       null
                       ).ConfigureAwait(false));
#else
            var response = await System.Threading.Tasks.Task.Run(() => connection.SendRequest(SearchRequest) as SearchResponse).ConfigureAwait(false);

            response.AssertSuccess();
            AssertSortSuccess(response.Controls);

            var enumerator = Options.GetEnumerator(response.Entries);
            var nextPage   = GetControl <PageResultResponseControl>(response.Controls);
            var parameters = new[]
            {
                pageRequest.PageSize,
                nextPage?.Cookie,
                enumerator,
                Options.Filter
            };

            return(ObjectActivator.CreateGenericInstance(typeof(LdapPage <>), Options.GetEnumeratorReturnType(), parameters, null));
#endif
        }
Пример #7
0
        private async System.Threading.Tasks.Task <object> HandleVlvRequestAsync(LdapConnection connection, int maxSize, ILinqToLdapLogger log)
        {
            if (Options.YieldNoResults)
            {
                var enumerator  = Options.GetEnumerator();
                var bindingAttr = new[]
                {
                    0,
                    null,
                    0,
                    enumerator
                };

                return(ObjectActivator.CreateGenericInstance(typeof(VirtualListView <>), Options.GetEnumeratorReturnType(), bindingAttr, null));
            }

            if (GetControl <SortRequestControl>(SearchRequest.Controls) == null)
            {
                throw new InvalidOperationException("Virtual List Views require a sort operation. Please include an OrderBy in your query.");
            }

            var skip = Options.SkipSize.GetValueOrDefault();

            if (GetControl <VlvRequestControl>(SearchRequest.Controls) == null)
            {
                VlvRequestControl vlvRequest =
                    new VlvRequestControl(0, Options.TakeSize.GetValueOrDefault(maxSize) - 1, skip + 1)
                {
                    IsCritical = false
                };

                SearchRequest.Controls.Add(vlvRequest);
            }

            if (log != null && log.TraceEnabled)
            {
                log.Trace(SearchRequest.ToLogString());
            }

#if NET45
            return(await System.Threading.Tasks.Task.Factory.FromAsync(
                       (callback, state) =>
            {
                return connection.BeginSendRequest(SearchRequest, Options.AsyncProcessing, callback, state);
            },
                       (asyncresult) =>
            {
                var response = (SearchResponse)connection.EndSendRequest(asyncresult);
                response.AssertSuccess();
                AssertSortSuccess(response.Controls);

                var vlvResponse = GetControl <VlvResponseControl>(response.Controls);

                if (vlvResponse == null)
                {
                    throw new InvalidOperationException("The server does not support Virtual List Views. Skip cannot be used. Please use standard paging.");
                }
                var parameters = new[]
                {
                    vlvResponse.ContentCount,
                    vlvResponse.ContextId,
                    vlvResponse.TargetPosition,
                    Options.GetEnumerator(response.Entries)
                };

                return ObjectActivator.CreateGenericInstance(typeof(VirtualListView <>), Options.GetEnumeratorReturnType(), parameters, null);
            },
                       null
                       ).ConfigureAwait(false));
#else
            var response = await System.Threading.Tasks.Task.Run(() => connection.SendRequest(SearchRequest) as SearchResponse).ConfigureAwait(false);

            response.AssertSuccess();
            AssertSortSuccess(response.Controls);

            var vlvResponse = GetControl <VlvResponseControl>(response.Controls);

            if (vlvResponse == null)
            {
                throw new InvalidOperationException("The server does not support Virtual List Views. Skip cannot be used. Please use standard paging.");
            }
            var parameters = new[]
            {
                vlvResponse.ContentCount,
                vlvResponse.ContextId,
                vlvResponse.TargetPosition,
                Options.GetEnumerator(response.Entries)
            };

            return(ObjectActivator.CreateGenericInstance(typeof(VirtualListView <>), Options.GetEnumeratorReturnType(), parameters, null));
#endif
        }
Пример #8
0
        private async System.Threading.Tasks.Task <object> HandleStandardRequestAsync(LdapConnection connection, ILinqToLdapLogger log, int maxSize, bool pagingEnabled)
        {
            if (Options.YieldNoResults)
            {
                return(ObjectActivator.CreateGenericInstance(typeof(List <>), Options.GetEnumeratorReturnType(), null, null));
            }

            int pageSize = 0;
            int index    = 0;

            if (pagingEnabled)
            {
                int maxPageSize = Options.PageSize ?? maxSize;
                pageSize = Options.TakeSize.HasValue ? Math.Min(Options.TakeSize.Value, maxPageSize) : maxPageSize;

                index = SearchRequest.Controls.Add(new PageResultRequestControl(pageSize));
            }

            if (log != null && log.TraceEnabled)
            {
                log.Trace(SearchRequest.ToLogString());
            }

            var            list     = new List <SearchResultEntry>();
            SearchResponse response = null;

#if NET45
            await System.Threading.Tasks.Task.Factory.FromAsync(
                (callback, state) =>
            {
                return(connection.BeginSendRequest(SearchRequest, Options.AsyncProcessing, callback, state));
            },
                (asyncresult) =>
            {
                response = (SearchResponse)connection.EndSendRequest(asyncresult);
                response.AssertSuccess();

                list.AddRange(response.Entries.GetRange());
            },
                null
                ).ConfigureAwait(false);
#else
            response = await System.Threading.Tasks.Task.Run(() => connection.SendRequest(SearchRequest) as SearchResponse).ConfigureAwait(false);

            response.AssertSuccess();
            list.AddRange(response.Entries.GetRange());
#endif

            if (pagingEnabled)
            {
                if (response.Entries.Count > 0)
                {
                    var  pageResultResponseControl = GetControl <PageResultResponseControl>(response.Controls);
                    bool hasMoreResults            = pageResultResponseControl != null && pageResultResponseControl.Cookie.Length > 0 && (!Options.TakeSize.HasValue || list.Count < Options.TakeSize.Value);
                    while (hasMoreResults)
                    {
                        SearchRequest.Controls[index] = new PageResultRequestControl(pageSize)
                        {
                            Cookie = pageResultResponseControl.Cookie
                        };
                        if (log != null && log.TraceEnabled)
                        {
                            log.Trace(SearchRequest.ToLogString());
                        }

#if NET45
                        await System.Threading.Tasks.Task.Factory.FromAsync(
                            (callback, state) =>
                        {
                            return(connection.BeginSendRequest(SearchRequest, Options.AsyncProcessing, callback, state));
                        },
                            (asyncresult) =>
                        {
                            response = (SearchResponse)connection.EndSendRequest(asyncresult);
                            response.AssertSuccess();

                            pageResultResponseControl = GetControl <PageResultResponseControl>(response.Controls);
                            hasMoreResults            = pageResultResponseControl != null && pageResultResponseControl.Cookie.Length > 0 && (!Options.TakeSize.HasValue || list.Count <= Options.TakeSize.Value);

                            list.AddRange(response.Entries.GetRange());
                        },
                            null
                            ).ConfigureAwait(false);
#else
                        response = await System.Threading.Tasks.Task.Run(() => connection.SendRequest(SearchRequest) as SearchResponse).ConfigureAwait(false);

                        response.AssertSuccess();

                        pageResultResponseControl = GetControl <PageResultResponseControl>(response.Controls);
                        hasMoreResults            = pageResultResponseControl != null && pageResultResponseControl.Cookie.Length > 0 && (!Options.TakeSize.HasValue || list.Count <= Options.TakeSize.Value);

                        list.AddRange(response.Entries.GetRange());
#endif
                    }
                }
            }

            AssertSortSuccess(response.Controls);

            if (Options.TakeSize.HasValue && list.Count > Options.TakeSize.Value)
            {
                var size = Options.TakeSize.Value;
                list.RemoveRange(size, list.Count - size);
            }

            var enumerator = Options.GetEnumerator(list);

            return(ObjectActivator.CreateGenericInstance(typeof(List <>), Options.GetEnumeratorReturnType(), new[] { enumerator }, null));
        }
Пример #9
0
 public object GetEnumerator(List <SearchResultEntry> results)
 {
     return(ObjectActivator.CreateGenericInstance(typeof(SearchResponseEnumerable <>), GetEnumeratorReturnType(),
                                                  new object[] { GetTransformer(), results }, "2"));
 }
Пример #10
0
 public object GetEnumerator()
 {
     return(ObjectActivator.CreateGenericInstance(typeof(SearchResponseEnumerable <>), GetEnumeratorReturnType(),
                                                  new object[] { null, GetTransformer() }, "1"));
 }