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()); } }
public List <Books_DTO> GetAll() { using (var sqlConnection = CoreConnection.GetConnection()) { return(sqlConnection.Query <Books_DTO>("Select * from Books order by name").ToList()); } }
public long Delete(long id) { using (var sqlConnection = CoreConnection.GetConnection()) { return(sqlConnection.Execute("delete from books where id = @id", new { id = id })); } }
/// <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(); }
public void OnCoreConnectionChanged(CoreConnection conn) { var handler = CoreConnectionChanged; if (handler != null) { handler(this, new EventArgs <CoreConnection>(conn)); } }
public static void ExecuteNonQuery(SqlCommand sqlCommand) { using (var connection = CoreConnection.GetConnection()) { connection.Open(); using (var command = sqlCommand) { int rowsAffected = command.ExecuteNonQuery(); } } }
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; } }
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); }
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()); } }
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); } }
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); } }
public void OnCoreConnectionChanged(CoreConnection conn) { var handler = CoreConnectionChanged; if (handler != null) handler(this, new EventArgs<CoreConnection>(conn)); }