コード例 #1
0
ファイル: Proxy.cs プロジェクト: robearlam/Rob.Commerce
        /// <summary>
        /// Executes the specified query.
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <param name="query">The query.</param>
        /// <returns>A collection</returns>
        public static IEnumerable <T> Execute <T>(DataServiceQuery <T> query)
        {
            var watch = new Stopwatch();

            watch.Start();

            try
            {
                var result = query.ExecuteAsync().Result;

                watch.Stop();
                Console.WriteLine($"     <.><.> Execute<T>: {query.RequestUri}: {watch.ElapsedMilliseconds}ms");

                return(result);
            }
            catch (DataServiceQueryException ex)
            {
                WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on Execute:{query.RequestUri}");
                throw;
            }
            catch (AggregateException ex)
            {
                WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on Execute:{query.RequestUri}");
                throw;
            }
            catch (Exception ex)
            {
                WriteColoredLine(ConsoleColor.Red, $"Unknown Exception {ex.Message} Execute:{query.RequestUri}");
                throw;
            }
        }
コード例 #2
0
        /// <summary>
        /// Executes the specified query.
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <param name="query">The query.</param>
        /// <returns>A collection</returns>
        public static IEnumerable <T> Execute <T>(DataServiceQuery <T> query)
        {
            var watch = new Stopwatch();

            watch.Start();

            try
            {
                var result = query.ExecuteAsync().Result;
                watch.Stop();
                LogInfo($"     <.><.> Execute<T>: {query.RequestUri}: {watch.ElapsedMilliseconds}ms");

                return(result);
            }
            catch (DataServiceQueryException ex)
            {
                LogError($"Exception {ex.InnerException.Message} on Execute:{query.RequestUri}", typeof(Proxy));
                throw;
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    LogError($"Exception {e.GetType()}: {e.Message} on Execute:{query.RequestUri}", typeof(Proxy));
                }

                throw;
            }
            catch (Exception ex)
            {
                LogError($"Exception {ex.GetType()}: {ex.Message} Execute:{query.RequestUri}", typeof(Proxy));
                throw;
            }
        }
コード例 #3
0
        public static async Task <int> EntitiesCount <TEntity>(this DataServiceQuery <TEntity> query)
        {
            var entities = await query.ExecuteAsync();

            int entitiesCount = entities.Count();

            return(entitiesCount);
        }
コード例 #4
0
        // get all the entities from an entity set
        private async Task <T[]> ReadAllEntitiesAsync <T>(string entitySetName)
        {
            var client = ReaderClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4);

            DataServiceQuery <T> query   = client.CreateQuery <T>(entitySetName);
            IEnumerable <T>      results = await query.ExecuteAsync();

            return(results.ToArray());
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: KenitoInc/BookLibClient
        private static async Task GetAllUsers(Container dsc)
        {
            DataServiceQuery <User> query = dsc.CreateQuery <User>("Users");

            query = query.IncludeTotalCount();
            //var response1 = await query.ExecuteAsync();
            QueryOperationResponse <User> response = await query.ExecuteAsync() as QueryOperationResponse <User>;

            Console.WriteLine($"There are a total of {response.TotalCount} Users.");
            foreach (var res in response)
            {
                Console.WriteLine(res.Name);
            }
        }
コード例 #6
0
            public IEnumerator <Task <IEnumerable <T> > > GetEnumerator()
            {
                var result = _query.ExecuteAsync();

                yield return(result);

                var response = (QueryOperationResponse <T>)result.Result;

                for (var continuation = response.GetContinuation(); continuation != null; continuation = response.GetContinuation())
                {
                    result = _ctx.ExecuteAsync(continuation);
                    yield return(result);

                    response = (QueryOperationResponse <T>)result.Result;
                }
            }
コード例 #7
0
        private async Task PrintQuery(DataServiceQuery query)
        {
            Console.WriteLine(Entity);
            var list = await query.ExecuteAsync();

            var elementType = query.GetType().GenericTypeArguments[0];

            var props = Columns.Select(k => Info.GetProperty(elementType, k))
                        .Where(k => k != null);

            var table = new ConsoleTable(props.Select(k => k.Name).ToArray());

            foreach (var wk in list)
            {
                var line = props.Select(k => k.GetValue(wk));
                table.AddRow(line.ToArray());
            }

            table.Write();
        }