Created
May 31, 2018 13:28
-
-
Save kivancbakdi/3c2af5f2b1f008c6e048474c0027f915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using PeakUp.Employee.Manager.Extensions; | |
using PeakUp.Employee.Manager.Models; | |
using System; | |
using System.Messaging; | |
using System.Threading; | |
namespace PeakUp.Employee.Manager | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//Kullanıcıdan Personel Bilgilerinin Alınması | |
Console.WriteLine("Personelin Adı"); | |
var employeeName = Console.ReadLine(); | |
Console.WriteLine("Personelin E-Posta Adresi"); | |
var employeeMailAdress = Console.ReadLine(); | |
//Alınan Bilgiler ile Employee objesinin oluşturulması | |
var employee = new EmployeeModel(employeeName, employeeMailAdress); | |
//Hoşgeldin Maili için Personelin Kuyruğa Eklenmesi | |
AddEmployeeToQueue(employee); | |
//Personelin Oluşturulduğuna Dair Mesaj | |
Console.WriteLine("Personel oluşturuldu, teşekkürler."); | |
//Mesajın Ekranda 1 saniye kalması için Thread'i uyutuyoruz | |
Thread.Sleep(1000); | |
} | |
static void AddEmployeeToQueue(EmployeeModel employee) | |
{ | |
// Email Queue zaten bilgisayarda/sunucuda mevcut ise getirilmesi, değilse oluşturulup getirilmesi (Detaylar için Extensions altında bulunan CreateIfNotExists metodunun incelenmesi gerekiyor. | |
var emailQueue = new MessageQueue().CreateIfNotExists("mail"); | |
//string veri alışverişi yaptığımızdan dolayı emailQueue için string tipinde bir formatter tanımlıyoruz | |
Type formatterType = typeof(string); | |
emailQueue.Formatter = new XmlMessageFormatter(new Type[] { formatterType }); | |
//Mail objesinin oluşturulması | |
var mail = new Mail(employee.MailAddress, $"Aramıza hoşgeldin {employee.Name}"); | |
//Gönderilen mesajların daha kolay yazılıp, daha kolay okunabilmesi için JSON'a çevrilmesi (Opsiyonel) | |
var mailJson = JsonConvert.SerializeObject(mail); | |
//Mesajın queue'ya gönderilmesi | |
emailQueue.Send(mailJson); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment