Example #1
0
 public Books_DTO Get(long id)
 {
     using (var sqlConnection = CoreConnection.GetConnection())
     {
         return(sqlConnection.Query <Books_DTO>("Select * from books where id = @id", new { id = id }).SingleOrDefault());
     }
 }
Example #2
0
 public List <Books_DTO> GetAll()
 {
     using (var sqlConnection = CoreConnection.GetConnection())
     {
         return(sqlConnection.Query <Books_DTO>("Select *  from Books order by name").ToList());
     }
 }
Example #3
0
 public long Delete(long id)
 {
     using (var sqlConnection = CoreConnection.GetConnection())
     {
         return(sqlConnection.Execute("delete from books where id = @id", new { id = id }));
     }
 }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        /// <remarks>
        /// params:
        /// 1)Current Service Name
        /// 2)Reciever Service name
        ///
        ///
        /// </remarks>
        public void Run(string[] args)
        {
            Name = args?[0];
            if (string.IsNullOrEmpty(Name))
            {
                throw new ArgumentNullException(NoNameMsg);
            }
            RecName = args?[1];
            if (string.IsNullOrEmpty(RecName))
            {
                throw new ArgumentNullException(NoRecNameMsg);
            }

            RecID = args?[2];
            if (string.IsNullOrEmpty(RecID))
            {
                throw new ArgumentNullException(NoRecIdNameMsg);
            }

            SayMessage = args.Length == 4 ? args[3].ToString() : null;
            CoreConnection.Connected += CoreConnection_Connected;

            CoreConnection.Start();
            lockEvent.WaitOne();
            CoreConnection.Dispose();
        }
Example #5
0
        public void OnCoreConnectionChanged(CoreConnection conn)
        {
            var handler = CoreConnectionChanged;

            if (handler != null)
            {
                handler(this, new EventArgs <CoreConnection>(conn));
            }
        }
Example #6
0
        public static void ExecuteNonQuery(SqlCommand sqlCommand)
        {
            using (var connection = CoreConnection.GetConnection())
            {
                connection.Open();

                using (var command = sqlCommand)
                {
                    int rowsAffected = command.ExecuteNonQuery();
                }
            }
        }
Example #7
0
        private void CoreConnection_Connected(string appId)
        {
            try
            {
                var exchangeName = Name + ".direct";
                var consumer     = new ConsumerParam()
                {
                    ExchangeParam = new ChannelExchangeParam()
                    {
                        Name = exchangeName,
                        Type = ExchangeTypes.EXCHANGETYPE_DIRECT,
                    },
                    QueueParam = new ChannelQueueParam()
                    {
                        Name       = exchangeName + "." + appId,
                        AutoDelete = true
                    }
                };

                CoreConnection.Listen(consumer, (msg) =>
                {
                    var str = Encoding.UTF8.GetString(msg.Content);
                    msg.Ack();
                    Trace.TraceInformation($"Listen ({Name}): {str}");
                    if (str == "Exit")
                    {
                        lockEvent.Set();
                    }
                    if (QuestionAnswerDictionary.ContainsKey(str))
                    {
                        Say(QuestionAnswerDictionary[str]);
                        if (QuestionAnswerDictionary[str] == "Exit")
                        {
                            lockEvent.Set();
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("Неизвестное сообщение");
                    }
                });

                if (!string.IsNullOrEmpty(SayMessage) && QuestionAnswerDictionary.ContainsKey(SayMessage))
                {
                    Say(SayMessage);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                throw;
            }
        }
Example #8
0
        private void Say(string msg)
        {
            var prod = new ProducerParam();

            //be ignored
            prod.RoutingKey = AppId.CurrentUID;
            var rec_exchangeName = RecName + ".fanout";

            prod.ExchangeParam = new ChannelExchangeParam()
            {
                Name = rec_exchangeName,
                Type = ExchangeTypes.EXCHANGETYPE_FANOUT,
            };
            Trace.TraceInformation($"Say {Name}: {msg}");
            CoreConnection.Publish(prod, Encoding.UTF8.GetBytes(msg), null);
        }
Example #9
0
 private void Say(string msg)
 {
     try
     {
         var prod = new ProducerParam();
         //be ignored
         prod.RoutingKey = RecID;
         var rec_exchangeName = RecName + ".direct";
         prod.ExchangeParam = new ChannelExchangeParam()
         {
             Name = rec_exchangeName,
             Type = ExchangeTypes.EXCHANGETYPE_DIRECT,
         };
         Trace.TraceInformation($"Say {Name}: {msg}");
         CoreConnection.Publish(prod, Encoding.UTF8.GetBytes(msg), null);
     }
     catch (Exception ex)
     {
         Trace.TraceError(ex.ToString());
     }
 }
Example #10
0
        public long Update(Books_DTO obj)
        {
            long toReturn = 0;

            using (var sqlConnection = CoreConnection.GetConnection())
            {
                try
                {
                    toReturn = sqlConnection.Execute("update books set name = @name, pages = @pages, quantity = @quantity, update_date = (select getdate()) where id = @id", obj);
                }
                catch (Exception ex)
                {
                    message = CoreException.GetMessage(ex.Message);
                }


                if (toReturn > 0)
                {
                    message = "Cadastro realizado com sucesso";
                }

                return(toReturn);
            }
        }
Example #11
0
        public long Create(Books_DTO obj)
        {
            using (var sqlConnection = CoreConnection.GetConnection())
            {
                long toReturn = 0;

                try
                {
                    toReturn = sqlConnection.Execute("Insert into books (name, pages, create_date, update_date,author, quantity) values (@name, @pages, (select getdate()),(select getdate()),@author,@quantity  )", obj);
                }
                catch (Exception ex)
                {
                    message = CoreException.GetMessage(ex.Message);
                }


                if (toReturn > 0)
                {
                    message = "Cadastro realizado com sucesso";
                }

                return(toReturn);
            }
        }
Example #12
0
 public void OnCoreConnectionChanged(CoreConnection conn) {
   var handler = CoreConnectionChanged;
   if (handler != null) handler(this, new EventArgs<CoreConnection>(conn));
 }