Ejemplo n.º 1
0
        /// <summary>
        /// Does the ops command.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="query">The query.</param>
        /// <returns>A <see cref="CommerceCommandSingle"/></returns>
        public static CommerceCommandSingle DoOpsCommand(this Container container, DataServiceActionQuerySingle <CommerceCommandSingle> query)
        {
            var response        = query.GetValueAsync().Result;
            var commandResponse = response;

            return(commandResponse);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Does the ops command.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="query">The query.</param>
        /// <returns>A <see cref="CommerceCommandSingle"/></returns>
        public static CommerceCommandSingle DoOpsCommand(this Container container, DataServiceActionQuerySingle <CommerceCommandSingle> query)
        {
            Console.WriteLine("     ================ OPS COMMAND =================");
            Console.WriteLine("     {query.RequestUri}");

            try
            {
                var response        = query.GetValueAsync().Result;
                var commandResponse = response;
                return(commandResponse);
            }
            catch (DataServiceQueryException ex)
            {
                Proxy.WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}");
                throw;
            }
            catch (AggregateException ex)
            {
                Proxy.WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}");
                throw;
            }
            catch (Exception ex)
            {
                Proxy.WriteColoredLine(ConsoleColor.Red, $"Unknown Exception {ex.Message}  GetValue:{query.RequestUri}");
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends a query expecting a CommandResponse back.
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <param name="query">The query.</param>
        /// <returns>A value</returns>
        public static CommerceCommand DoCommand <T>(DataServiceActionQuerySingle <T> query)
        {
            try
            {
                var response        = query.GetValueAsync().Result;
                var commandResponse = response as CommerceCommand;
                if (commandResponse == null)
                {
                    return(null);
                }

                LogInfo($"     <.><.> DoCommand<T>: {query.RequestUri}");
                WritePerf(commandResponse.Models.ToList());

                if (commandResponse.ResponseCode.Equals("Ok", StringComparison.OrdinalIgnoreCase))
                {
                    return(commandResponse);
                }

                foreach (var message in commandResponse.Messages.Where(m => !m.Code.Equals("Information", StringComparison.OrdinalIgnoreCase)))
                {
                    LogError($"DoCommand Failed:{message.Text}", typeof(Proxy));
                }

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

                throw;
            }
            catch (Exception ex)
            {
                LogError($"Exception {ex.GetType()}: {ex.Message} on DoCommand:{query.RequestUri}", typeof(Proxy));
                throw;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <param name="query">The query.</param>
        /// <returns>A value</returns>
        public static T GetValue <T>(DataServiceActionQuerySingle <T> query)
        {
            var watch = new Stopwatch();

            watch.Start();

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

                return(result);
            }
            catch (DataServiceQueryException ex)
            {
                LogError($"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}", typeof(Proxy));
                throw;
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    if (e is DataServiceClientException dataserviceClientException)
                    {
                        LogError($"Client Exception {dataserviceClientException.StatusCode} - {dataserviceClientException.Message} on GetValue:{query.RequestUri}", typeof(Proxy));
                    }
                    else
                    {
                        LogError($"Exception {e.GetType()}: {e.Message} on GetValue:{query.RequestUri}", typeof(Proxy));
                    }
                }

                throw;
            }
            catch (Exception ex)
            {
                LogError($"Exception {ex.GetType()}: {ex.Message} GetValue:{query.RequestUri}", typeof(Proxy));
                throw;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <param name="query">The query.</param>
        /// <returns>A value</returns>
        public static T GetValue <T>(DataServiceActionQuerySingle <T> query)
        {
            var watch = new Stopwatch();

            watch.Start();

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

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

                return(result);
            }
            catch (DataServiceQueryException ex)
            {
                WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}");
                throw;
            }
            catch (AggregateException ex)
            {
                if (ex.InnerException is DataServiceQueryException)
                {
                    var queryException = ex.InnerException as DataServiceQueryException;
                    var realException  = queryException.InnerException as DataServiceClientException;
                    WriteColoredLine(ConsoleColor.Red, $"Client Exception {realException.StatusCode} - {realException.Message} on GetValue:{query.RequestUri}");
                    throw realException;
                }

                WriteColoredLine(ConsoleColor.Red, $"Aggregate Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}");
                throw;
            }
            catch (Exception ex)
            {
                WriteColoredLine(ConsoleColor.Red, $"Unknown Exception {ex.Message} GetValue:{query.RequestUri}");
                throw;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sends a query expecting a CommandResponse back.
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <param name="query">The query.</param>
        /// <returns>A value</returns>
        public static CommerceOps.Sitecore.Commerce.Core.Commands.CommerceCommand DoOpsCommand <T>(DataServiceActionQuerySingle <T> query)
        {
            Console.WriteLine($"     ================ COMMAND =================");
            Console.WriteLine($"     {query.RequestUri}");

            try
            {
                var response        = query.GetValueAsync().Result;
                var commandResponse = response as CommerceOps.Sitecore.Commerce.Core.Commands.CommerceCommand;
                if (commandResponse != null)
                {
                    //WritePerf(commandResponse.Models.ToList());

                    if (commandResponse.ResponseCode != "Ok")
                    {
                        WriteColoredLine(ConsoleColor.Red, $"DoCommand Failed:{commandResponse.Messages.FirstOrDefault(m => m.Code.Equals("Error") || m.Code.Equals("Warning"))?.Text}");
                    }
                }

                return(commandResponse);
            }
            catch (DataServiceQueryException ex)
            {
                WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}");
                throw;
            }
            catch (AggregateException ex)
            {
                WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}");
                throw;
            }
            catch (Exception ex)
            {
                WriteColoredLine(ConsoleColor.Red, $"Unknown Exception {ex.Message}  GetValue:{query.RequestUri}");
                throw;
            }
        }