コード例 #1
0
 public override void ScalarExecuted(DbCommand command, DbCommandInterceptionContext <object> interceptionContext)
 {
     _stopwatch.Stop();
     if (interceptionContext.Exception != null)
     {
         _logger.Error(interceptionContext.Exception, "错误命令:{0}", command.CommandText);
     }
     else
     {
         _logger.TraceApi("SQL Database", "SchoolInterceptor.ScalarExcuted", _stopwatch.Elapsed, "命令:{0}", command.CommandText);
     }
     base.ScalarExecuted(command, interceptionContext);
 }
コード例 #2
0
        private static void Add(string parameters)
        {
            string isbn;
            string author;
            string name;
            string publisher;
            int    year;
            int    pages;
            float  price;

            while (true)
            {
                Console.Write("ISBN: ");
                isbn = Console.ReadLine();
                break;
            }

            while (true)
            {
                Console.Write("Author: ");
                author = Console.ReadLine();
                break;
            }

            while (true)
            {
                Console.Write("Name: ");
                name = Console.ReadLine();
                break;
            }

            while (true)
            {
                Console.Write("Publisher: ");
                publisher = Console.ReadLine();
                break;
            }

            while (true)
            {
                Console.Write("Year: ");
                if (int.TryParse(Console.ReadLine(), out year))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter a valid year");
                }
            }

            while (true)
            {
                Console.Write("Pages: ");
                if (int.TryParse(Console.ReadLine(), out pages))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter a valid pages amount");
                }
            }

            while (true)
            {
                Console.Write("Price: ");
                if (float.TryParse(Console.ReadLine(), out price))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter a valid Price");
                }
            }

            try
            {
                booklistService.AddBook(new Book(isbn, author, name, publisher, year, pages, price));
                Console.WriteLine("Book added successfully");
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                Logger.Error(ex, "Unable to create Book object - ivalid arguments");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Logger.Error(ex, $"Unable to add book to store - such book already exists. ISBN - {isbn}");
            }
        }