static void Main(string[] args) { List <KirimModel> list = new List <KirimModel>() { new KirimModel("John Hadikusumo", "0431343034", "*****@*****.**", "Registration", "Your registration is complete"), new KirimModel("Masdi Chandra", "042724022", "*****@*****.**", "Forget Password", "Your password has been resetted"), new KirimModel("Diana Mangunsong", "047032995", "*****@*****.**", "Registration", "Your registration is complete"), new KirimModel("Robert Raharjo", "048820104", "*****@*****.**", "Registration", "Your registration is complete"), new KirimModel("Kathy Sondak", "049211525", "*****@*****.**", "Registration", "Your registration is complete"), new KirimModel("Lilian Wu", "046455532", "*****@*****.**", "Registration", "Your registration is complete"), new KirimModel("Freddy Mc Mahon", "04230078", "*****@*****.**", "Registration", "Your registration is complete"), new KirimModel("Ram Ram Don", "0431343034", "*****@*****.**", "Registration", "Your registration is complete"), new KirimModel("Suratj Pakir", "044673079", "*****@*****.**", "Forget Password", "Your password has been resetted"), new KirimModel("Simon Ryu", "04620039", "*****@*****.**", "Registration", "Your registration is complete"), new KirimModel("Rhea Tobari", "048832044", "*****@*****.**", "Registration", "Your registration is complete") }; for (int i = 0; i < list.Count; i++) { MSMQModel <KirimModel> model = new MSMQModel <KirimModel>(); model.QueueName = ConfigurationManager.AppSettings["Queue_Name"].ToString(); model.QueueMessage = list[i]; MSMQ <KirimModel> msmq = new MSMQ <KirimModel>(); string id = msmq.WriteQueueMessage(model); Console.WriteLine("Id => " + id); } Console.ReadLine(); }
/// <summary> /// Handles the ReceiveCompleted event of the Queue control. /// sends email when message received from queue /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void MSMQReceiver(object sender, ReceiveCompletedEventArgs e) { try { MessageQueue queue = (MessageQueue)sender; Message msg = queue.EndReceive(e.AsyncResult); switch (msg.Label) { case "order email": CustomerOrder order = JsonConvert.DeserializeObject <CustomerOrder>(msg.Body.ToString()); email.SendOrderEmail(order); break; case "password reset": MSMQModel model = JsonConvert.DeserializeObject <MSMQModel>(msg.Body.ToString()); email.EmailService(model); break; } queue.BeginReceive(TimeSpan.FromSeconds(5)); } catch (Exception ex) { } }
public void ReadQueueMessage(MSMQModel <TObject> model) { log.Info("ReadQueueMessage starts here"); try { MessageQueue messageQueue; string queueName = model.QueueName; string queueId = string.Empty; if (!MessageQueue.Exists(queueName)) { messageQueue = MessageQueue.Create(queueName, true); } else { messageQueue = new MessageQueue(queueName); } messageQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) }); messageQueue.ReceiveCompleted += MessageQueue_ReceiveCompleted; messageQueue.BeginReceive(); } catch (Exception ex) { log.Error(ex.Message); } log.Info("ReadQueueMessage stops here"); }
public ActionResult ForgetPassword(ForgetPasswordModel forgetPasswordModel) { try { if (ModelState.IsValid) { MSMQModel result = bookBL.ForgetPassword(forgetPasswordModel); //getting the data from BusinessLayer var msmq = new MSMQ(Configuration); msmq.MSMQSender(result); if (result != null) { return(this.Ok(new { Success = true, Message = "Your password has been forget sucessfully now you can reset your password" })); //(smd format) //this.Ok returns the data in json format } else { return(this.Ok(new { Success = true, Message = "Other User is trying to login from your account" })); //(smd format) //this.Ok returns the data in json format } } else { return(null); } } catch (Exception ex) { return(BadRequest(new { Success = false, ex.Message })); } }
public bool Stop() { log.Info("Stops starts here"); model = new MSMQModel <KirimModel>(); timer.Stop(); log.Info("Stops stops here"); return(true); }
public MSMQModel ForgetPassword(ForgetPasswordModel forgetPasswordModel) { try { CustomerUser customerUser = new CustomerUser(); LoginAdmin forget1 = new LoginAdmin(); JwtModel forget2 = new JwtModel(); using (SqlConnection connection = new SqlConnection(connectionString)) { using (connection) { connection.Open(); //define the SqlCommand Object SqlCommand cmd = new SqlCommand("spForgetPassword", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Email", forgetPasswordModel.Email); SqlDataReader sqlDataReader = cmd.ExecuteReader(); if (sqlDataReader.HasRows) { if (sqlDataReader.Read()) { customerUser.Email = sqlDataReader.GetString(0); } var jwt = CreateToken(customerUser); forget2.JwtToken = jwt; var model1 = new ForgetPasswordModel { Email = forgetPasswordModel.Email }; var model2 = new JwtModel { JwtToken = forget2.JwtToken }; var model = new MSMQModel { Email = model1.Email, JwtToken = model2.JwtToken }; return(model); } else { return(null); } //Close Data Reader sqlDataReader.Close(); connection.Close(); } } } catch (Exception e) { throw e; } }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { log.Info("Timer_Elapsed starts here"); model = new MSMQModel <KirimModel>(); model.QueueName = ConfigurationManager.AppSettings["Queue_Name"].ToString(); messaging = new MSMQ <KirimModel>(); messaging.ReadEventHandler += Messaging_ReadEventHandler; messaging.ReadQueueMessage(model); log.Info("Timer_Elapsed stops here"); }
/// <summary> /// Sends the password reset link to MSMQ /// </summary> /// <param name="link"></param> public void MSMQSender(MSMQModel link) { try { Message msg = new Message { Label = "password reset link", Body = JsonConvert.SerializeObject(link), }; queue.Send(msg); queue.ReceiveCompleted += MSMQReceiver; queue.BeginReceive(TimeSpan.FromSeconds(5)); queue.Close(); } catch (Exception ex) { throw ex; } }
public async Task <bool> Kirim(KirimModel model) { bool result = await Task.Run <bool>(() => { MSMQModel <KirimModel> newmodel = new MSMQModel <KirimModel>(); newmodel.QueueMessage = model; newmodel.QueueName = ConfigurationManager.AppSettings["Queue_Name"].ToString(); MSMQ <KirimModel> msmq = new MSMQ <KirimModel>(); msmq.WriteQueueMessage(newmodel); SMSMessage message = new SMSMessage(); message.Message = message.Message.Replace("{PENGIRIM}", model.Name).Replace("{NEWLINE}", Environment.NewLine + Environment.NewLine); SMS sms = new SMS(); sms.Message = message; sms.Send(); return(true); }); return(result); }
public string WriteQueueMessage(MSMQModel <KirimModel> model) { MessageQueue messageQueue; string queueId = string.Empty; string queueName = model.QueueName; /* Example @".\Private\satuindonesia" */ string queueMessage = JsonConvert.SerializeObject(model.QueueMessage); if (!MessageQueue.Exists(queueName)) { messageQueue = MessageQueue.Create(queueName, true); } else { messageQueue = new MessageQueue(queueName); } Message message = new Message(queueMessage); messageQueue.Send(message, MessageQueueTransactionType.Single); queueId = message.Id; messageQueue.Close(); return(queueId); }