public IActionResult WordToPdfPage(WordToPdf wordToPdf) { var factory = new ConnectionFactory(); //factory.Uri = new Uri(_configuration["ConnectionString:RabbitMQCloudString"]); factory.HostName = "localhost"; using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.ExchangeDeclare("convert-exchange", ExchangeType.Direct, true, false, null); channel.QueueDeclare(queue: "File", true, false, autoDelete: false, arguments: null); channel.QueueBind("File", "convert-exchange", "WordToPdf"); MessageWordToPdf messageWordToPdf = new MessageWordToPdf(); using (MemoryStream memoryStream = new MemoryStream()) { wordToPdf.WordFile.CopyTo(memoryStream); messageWordToPdf.WordToByte = memoryStream.ToArray(); } messageWordToPdf.Email = wordToPdf.Email; messageWordToPdf.FileName = Path.GetFileNameWithoutExtension(wordToPdf.WordFile.FileName); string serializeMessage = JsonConvert.SerializeObject(messageWordToPdf); byte[] byteMessage = Encoding.UTF8.GetBytes(serializeMessage); var properties = channel.CreateBasicProperties(); properties.Persistent = true; channel.BasicPublish("convert-exchange", routingKey: "WordToPdf", basicProperties: properties, body: byteMessage); ViewBag.result = "Word Pdf e Dönüştürülüp email atılacak"; return(View()); } } }
private string ConvertToPdf(string sourceFile) { var fileInfo = new FileInfo(sourceFile); var extension = fileInfo.Extension; var tempPath = Path.GetTempPath(); var pdfPath = Path.Combine(tempPath, new Guid().ToString() + ".pdf"); if (_wordConverter == null) { _wordConverter = new WordToPdf(); } if (_publisherConverter == null) { _publisherConverter = new PublisherToPdf(); } if (extension == ".doc" || extension == ".docx") { _wordConverter.Convert(sourceFile, pdfPath); } else if (extension == ".pub" || extension == ".pubx") { _publisherConverter.Convert(sourceFile, pdfPath); } return(pdfPath); }
public IActionResult WordToPdfPage(WordToPdf wordToPdf) { // önce connect olacağız var factory = new ConnectionFactory(); factory.Uri = new Uri(_configuration["ConnectionStrings:RabbitMQ"]); using (var connection = factory.CreateConnection()) // 1) bağlantı oluşturdum. { using (var channel = connection.CreateModel()) // 2) kanal oluşturudum { channel.ExchangeDeclare("convert-exchange", ExchangeType.Direct, true, false, null); // 3) exchange oluşturdum(durable: true, (fiziksel olarak kaydedilsin. restart olduğunda silinmesin.) aoutdelete false. arguman ise null) channel.QueueDeclare(queue: "File", durable: true, exclusive: false, autoDelete: false); // 4) kuyruk oluşturdum. => göndermiş olduğum dosyaların kuyrukta tutulmasını istiyorum. (exclusive: false=> birden fazla bağlantı kuyruğu kulllanabilsin channel.QueueBind("File", "convert-exchange", "WordToPdf"); // 5) kuyruk ile exchange i bind edecem (mesajımın kaybolmasını istemiyorum.) WordToPdf = routingKey /*benim artık modele ihtiyacım var. complex tip / sınıf göndercem. ben bu sınıfta, word dosyası, email adresi ve dosyanın adını göndercem. * eğer kullancı benim sistemimdeki word dosyasını kullandıysa, ben kullanıcıya email atmam gerek. işte oradaki dosya ismini de almam gerek * ismi neyse o isimde oluşmuş bir pdf dosyası göndermem gerek. bu yüzden bir class daha oluşturuyorum... o yüzden message classı=> şair burada ne dedi anlamadım. ? */ // wordToPdf=> kullanıcının gönderdiği pdf dosyasının içindeki class. MessageWordToPdf => kullanıcıya mesaj gönderdiğimiz classs MessageWordToPdf messageWordToPdf = new MessageWordToPdf(); using (MemoryStream memoryStream = new MemoryStream()) // bu word dosyasını memoryde tutacam { wordToPdf.WordFile.CopyTo(memoryStream); // hafızaya kopyaladım messageWordToPdf.WordByte = memoryStream.ToArray(); // metoduma gelen wordToPdf dosyasını memory kopyalıyoruz. sonra memory nesnesini dolayısıyla onu array'e çevirip, mesajı göndereceğim sınıfa atıyoruz. } messageWordToPdf.Email = wordToPdf.Email; messageWordToPdf.FileName = Path.GetFileNameWithoutExtension(wordToPdf.WordFile.FileName); // file name'i alacaz (uzantısı olmadan dosya adını alıyoruz.) -- wordToPdf.WordFile.FileName => kullanıcıdan aldığım dosyanın file adi. // complex tipleri serilaze etmem gerek string serializeMessage = JsonConvert.SerializeObject(messageWordToPdf); // sonra bunu byte a çevircem byte[] byteMessage = Encoding.UTF8.GetBytes(serializeMessage); // mesajin sabit bicimde gitmesi icin ilk olarak, kuyruğu sabitlemem gerek. durabile i true yaparak bunu yaparım. ikincisi de property'inin persistance'ını true ya set edecem var properties = channel.CreateBasicProperties(); properties.Persistent = true; channel.BasicPublish(exchange: "convert-exchange", routingKey: "WordToPdf", basicProperties: properties, body: byteMessage); // burada da artık gönderiyoruz. ViewBag.result = "Word dosyanız, pdf dosyasına dönüştürüldükten sonra, size email olarak gönderilecektir."; return(View()); } } return(View()); }
public IActionResult WordToPdfPage(WordToPdf wordToPDF) { var factory = new ConnectionFactory(); factory.Uri = new Uri(configuration["ConnectionStrings:RabbitMQConnString"]); using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.ExchangeDeclare("convert-exchange", ExchangeType.Direct, true, false, null); channel.QueueDeclare(queue: "File", durable: true, exclusive: false, autoDelete: false, arguments: null); channel.QueueBind("File", "convert-exchange", "WordToPdf"); MessageWordToPdf messageWordToPdf = new MessageWordToPdf(); using (MemoryStream ms = new MemoryStream()) { wordToPDF.WordFile.CopyTo(ms); messageWordToPdf.WordByte = ms.ToArray(); } messageWordToPdf.Email = wordToPDF.Email; messageWordToPdf.FileName = Path.GetFileNameWithoutExtension(wordToPDF.WordFile.FileName); string serializeMessage = JsonConvert.SerializeObject(messageWordToPdf); byte[] ByteMessage = Encoding.UTF8.GetBytes(serializeMessage); var properties = channel.CreateBasicProperties(); properties.Persistent = true; channel.BasicPublish("convert-exchange", routingKey: "WordToPdf", basicProperties: properties, body: ByteMessage); ViewBag.result = "After your Word file is converted to PDF file, it will be sent to you by email."; return(View()); } } }
public IActionResult WordToPdfPage(WordToPdf wordToPdf) { var factory = new ConnectionFactory(); factory.Uri = new Uri(_configuration["ConnectionStrings:RabbitMQCloudString"]); using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.ExchangeDeclare("convertExchange", ExchangeType.Direct, true, false, null); channel.QueueDeclare(queue: "File", durable: true, exclusive: false, autoDelete: false, arguments: null); channel.QueueBind(queue: "File", exchange: "convertExchange", routingKey: "WordToPdf"); MessagWordToPdf message = new MessagWordToPdf(); using (MemoryStream ms = new MemoryStream()) { wordToPdf.WordFile.CopyTo(ms); message.WordByte = ms.ToArray(); } message.Email = wordToPdf.Email; message.FileName = Path.GetFileNameWithoutExtension(wordToPdf.WordFile.FileName); string serializeMessage = JsonConvert.SerializeObject(message); byte[] byteMessage = Encoding.UTF8.GetBytes(serializeMessage); var properties = channel.CreateBasicProperties(); properties.Persistent = true; channel.BasicPublish(exchange: "convertExchange", routingKey: "WordToPdf", basicProperties: properties, body: byteMessage); ViewBag.result = "Dosyanız işleme alınmıştır. İşlem bittiğinde dosyanız email ile gönderilecektir."; return(View()); } } }
public IActionResult WordtoPdfPage(WordToPdf wordToPdf) { return(null); }