예제 #1
0
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            var ig = new btwc.IndulgenceGeneratoriTextSharp(new FileSystemStorage());

            try
            {
                var indulgence = new Indulgence()
                                     {
                                         Id = 1,
                                         Confession = Text,
                                         Name = "Andrew",
                                         AmountDonated = 200,
                                         CharityName = "test charity",
                                         DateConfessed = DateTime.Now
                                     };

                ig.Generate(indulgence,
                    Path.Combine(Environment.CurrentDirectory, "fonts"),
                    Path.Combine(Environment.CurrentDirectory, "content"),
                    "parchment3",
                    "1.pdf","1_1.png","1_2.png","1_3.png","1_4.png");
            } catch( Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            sw.Stop();
            Console.WriteLine(string.Format("Took {0}", sw.Elapsed));
        }
예제 #2
0
        public async Task Send(Indulgence indulgence, string indulgenceFilePath)
        {
            MailMessage message = new MailMessage();

            message.From = new MailAddress(ConfigurationManager.AppSettings["emailFromAddress"], "IndulgeMe.cc");
            message.To.Add(new MailAddress(indulgence.DonorEmailAddress, indulgence.Name));

            var    templateDoc = XDocument.Load(HostingEnvironment.MapPath("~/content/emailTemplates/indulgenceEmail.xml"));
            string subject     = templateDoc.Element("email").Element("subject").Value;
            string textBody    = templateDoc.Element("email").Element("body").Element("text").Value;
            string htmlBody    = templateDoc.Element("email").Element("body").Element("html").Value;

            subject = subject
                      .Replace("@DonorName", indulgence.Name)
                      .Replace("@CharityName", indulgence.CharityName);
            textBody = textBody
                       .Replace("@DonorName", indulgence.Name)
                       .Replace("@CharityName", indulgence.CharityName);
            htmlBody = htmlBody
                       .Replace("@DonorName", indulgence.Name)
                       .Replace("@CharityName", indulgence.CharityName);

            message.Subject = subject;
            message.Body    = textBody;
            message.Attachments.Add(new Attachment(indulgenceFilePath));
            SmtpClient smtp = new SmtpClient();

            smtp.Port        = int.Parse(ConfigurationManager.AppSettings["smtpPort"]);
            smtp.Host        = ConfigurationManager.AppSettings["smtpServer"];
            smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpUsername"],
                                                                ConfigurationManager.AppSettings["smtpPassword"]);
            smtp.EnableSsl = true;
            smtp.Send(message);
        }
        public async Task Send(Indulgence indulgence, string indulgenceFilePath)
        {
            MailMessage message = new MailMessage();
            message.From = new MailAddress(ConfigurationManager.AppSettings["emailFromAddress"], "IndulgeMe.cc");
            message.To.Add(new MailAddress(indulgence.DonorEmailAddress, indulgence.Name));

            var templateDoc = XDocument.Load(HostingEnvironment.MapPath("~/content/emailTemplates/indulgenceEmail.xml"));
            string subject = templateDoc.Element("email").Element("subject").Value;
            string textBody = templateDoc.Element("email").Element("body").Element("text").Value;
            string htmlBody = templateDoc.Element("email").Element("body").Element("html").Value;
            subject = subject
                .Replace("@DonorName", indulgence.Name)
                .Replace("@CharityName", indulgence.CharityName);
            textBody = textBody
                .Replace("@DonorName", indulgence.Name)
                .Replace("@CharityName", indulgence.CharityName);
            htmlBody = htmlBody
                .Replace("@DonorName", indulgence.Name)
                .Replace("@CharityName", indulgence.CharityName);

            message.Subject = subject;
            message.Body = textBody;
            message.Attachments.Add(new Attachment(indulgenceFilePath));
            SmtpClient smtp = new SmtpClient();
            smtp.Port = int.Parse(ConfigurationManager.AppSettings["smtpPort"]);
            smtp.Host = ConfigurationManager.AppSettings["smtpServer"];
            smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpUsername"],
                                                                ConfigurationManager.AppSettings["smtpPassword"]);
            smtp.EnableSsl = true;
            smtp.Send(message);
        }
예제 #4
0
 public void GenerateIndulgence(Indulgence indulgence, string fontsDirectory, string contentDirectory)
 {
     string pdfFilename = string.Format("{0}{1}.pdf", ConfigurationManager.AppSettings["IndulgencePdfRelativePath"], indulgence.Guid);
     string imageThumbnailFileName_1 = string.Format("{0}{1}_1.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid);
     string imageThumbnailFileName_2 = string.Format("{0}{1}_2.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid);
     string imageThumbnailFileName_3 = string.Format("{0}{1}_3.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid);
     string imageThumbnailFileName_4 = string.Format("{0}{1}_4.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid);
     _indulgenceGenerator.Generate(indulgence, fontsDirectory, contentDirectory, indulgence.BackgroundImageName,
         pdfFilename, imageThumbnailFileName_1, imageThumbnailFileName_2, imageThumbnailFileName_3, imageThumbnailFileName_4);
 }
예제 #5
0
        public void GenerateIndulgence(Indulgence indulgence, string fontsDirectory, string contentDirectory)
        {
            string pdfFilename = string.Format("{0}{1}.pdf", ConfigurationManager.AppSettings["IndulgencePdfRelativePath"], indulgence.Guid);
            string imageThumbnailFileName_1 = string.Format("{0}{1}_1.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid);
            string imageThumbnailFileName_2 = string.Format("{0}{1}_2.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid);
            string imageThumbnailFileName_3 = string.Format("{0}{1}_3.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid);
            string imageThumbnailFileName_4 = string.Format("{0}{1}_4.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid);

            _indulgenceGenerator.Generate(indulgence, fontsDirectory, contentDirectory, indulgence.BackgroundImageName,
                                          pdfFilename, imageThumbnailFileName_1, imageThumbnailFileName_2, imageThumbnailFileName_3, imageThumbnailFileName_4);
        }
        public async Task Send(Indulgence indulgence, string indulgenceFilePath)
        {
            service =
                new AmazonSimpleEmailServiceClient(
                    ConfigurationManager.AppSettings["awsAccessKeyId"],
                    ConfigurationManager.AppSettings["awsAccessSecret"]);

            SendEmailRequest request = new SendEmailRequest();
            request.Destination = BuildDestination();
            request.Message=BuildMessage(indulgence);
            request.Source="*****@*****.**";

            var response = service.SendEmail(request);
        }
 public void Send(Indulgence indulgence, string indulgenceFilePath)
 {
     MvcApplication.EmailFacade.AddEmailToQueue(
         new string[] { indulgence.DonorEmailAddress },
         "IndulgenceCreated",
         new Dictionary<string, string>()
             {
                 {"DonorName", indulgence.Name},
                 {"CharityName", indulgence.CharityName},
                 {"IndulgenceId", indulgence.Id},
                 {"ServerAuthority", "http://" + HttpContext.Current.Request.Url.Authority}
             },
         new FileInfo[]{new FileInfo(indulgenceFilePath)});
 }
예제 #8
0
 public Indulgence CreateIndulgenceForSin(string guid)
 {
     var sin = _db.Where(o => o is Sin).Select(o => o as Sin).SingleOrDefault(s => s.Guid == Guid.Parse(guid));
     var ind = new Indulgence()
     {
         Confession = sin.Content.Truncate(250),
         DateConfessed = DateTime.Now,
         IsBlessed = false,
         IsConfession = false,
         Sin = sin
     };
     _db.Add(ind);
     return ind;
 }
예제 #9
0
        public void Add(Indulgence indulgence)
        {
            if (!Directory.Exists(_outboxDirectory))
                Directory.CreateDirectory(_outboxDirectory);

            string filename = Path.Combine(_outboxDirectory, string.Format("{0}.xml", Guid.NewGuid()));
            using (var outStream = File.Create(filename))
            {
                XmlWriter xw = XmlWriter.Create(outStream);
                XmlSerializer serializer = new XmlSerializer(typeof(Indulgence));
                serializer.Serialize(xw, indulgence);
                xw.Flush();
                xw.Close();
            }
        }
        public async Task Send(Indulgence indulgence, string indulgenceFilePath)
        {
            service =
                new AmazonSimpleEmailServiceClient(
                    ConfigurationManager.AppSettings["awsAccessKeyId"],
                    ConfigurationManager.AppSettings["awsAccessSecret"]);

            SendEmailRequest request = new SendEmailRequest();

            request.Destination = BuildDestination();
            request.Message     = BuildMessage(indulgence);
            request.Source      = "*****@*****.**";

            var response = service.SendEmail(request);
        }
예제 #11
0
        public Indulgence CreateIndulgenceForSin(string guid)
        {
            var sin = _db.Where(o => o is Sin).Select(o => o as Sin).SingleOrDefault(s => s.Guid == Guid.Parse(guid));
            var ind = new Indulgence()
            {
                Confession    = sin.Content.Truncate(250),
                DateConfessed = DateTime.Now,
                IsBlessed     = false,
                IsConfession  = false,
                Sin           = sin
            };

            _db.Add(ind);
            return(ind);
        }
예제 #12
0
 public ActionResult Absolve(int id)
 {
     var sin = MvcApplication.CurrentSession.Load<Sin>("sins/"+id.ToString());
     var con = new Indulgence()
     {
         Confession = sin.Content.Truncate(250),
         DateConfessed = DateTime.Now,
         IsBlessed = false,
         IsConfession = false,
         SinId = sin.Id
     };
     MvcApplication.CurrentSession.Store(con);
     MvcApplication.CurrentSession.SaveChanges();
     ViewData["cid"] = con.Id.IdValue();
     return View("Absolve", con);
 }
예제 #13
0
        public void Add(Indulgence indulgence)
        {
            if (!Directory.Exists(_outboxDirectory))
            {
                Directory.CreateDirectory(_outboxDirectory);
            }

            string filename = Path.Combine(_outboxDirectory, string.Format("{0}.xml", Guid.NewGuid()));

            using (var outStream = File.Create(filename))
            {
                XmlWriter     xw         = XmlWriter.Create(outStream);
                XmlSerializer serializer = new XmlSerializer(typeof(Indulgence));
                serializer.Serialize(xw, indulgence);
                xw.Flush();
                xw.Close();
            }
        }
        private Message BuildMessage(Indulgence indulgence)
        {
            var    templateDoc = XDocument.Load(HostingEnvironment.MapPath("~/content/emailTemplates/indulgenceEmail.xml"));
            string subjectText = templateDoc.Element("email").Element("subject").Value;
            string textBody    = templateDoc.Element("email").Element("body").Element("text").Value;
            string htmlBody    = templateDoc.Element("email").Element("body").Element("html").Value;

            subjectText = subjectText
                          .Replace("@DonorName", indulgence.Name)
                          .Replace("@CharityName", indulgence.CharityName);
            textBody = textBody
                       .Replace("@DonorName", indulgence.Name)
                       .Replace("@CharityName", indulgence.CharityName);
            htmlBody = htmlBody
                       .Replace("@DonorName", indulgence.Name)
                       .Replace("@CharityName", indulgence.CharityName);

            Content subject = new Content();

            subject.Charset = "utf-8";
            subject.Data    = subjectText;

            Content html = new Content();

            html.Charset = "UTF-8";
            html.Data    = htmlBody;

            Content text = new Content();

            text.Charset = "UTF-8";
            text.Data    = textBody;

            Body body = new Body();

            body.Html = html;
            body.Text = text;

            Message message = new Message();

            message.Body    = body;
            message.Subject = subject;

            return(message);
        }
        public async Task Send(Indulgence indulgence, string indulgenceFilePath)
        {
                dynamic sg = new SendGrid.SendGridAPIClient(_sendGridApiKey);
                var fromAddress = ConfigurationManager.AppSettings["SendGridFromAddress"];
                var fromName = ConfigurationManager.AppSettings["SendGridFromName"];
                var indulgenceLink = string.Format("{0}/indulgence/pdf/{1}",
                                    ConfigurationManager.AppSettings["WebsiteHostName"], indulgence.Guid);
                string data = @"{
'content': [
    {
      'type': 'text/html', 
      'value': '<html><p>Hello good person,</p><p>Please accept this *genuine plenary indulgence. Be sure to present it when you are received in purgatory.</p><p><a href=\'" + indulgenceLink + @"\'>Click here for the PDF version</a></p><p>Send this to your friends, gloat about it, and encourage them to perform good acts too!</p><p><small>*not endorsed by the Catholic church</small></p></html>'
    }
  ],
'from': {
    'email': '"+ fromAddress+ @"', 
    'name': '" + fromName + @"'
  },
'personalizations': 
[
    {
        'to': [{
          'email': '" + indulgence.DonorEmailAddress + @"', 
          'name': '" + (string.IsNullOrWhiteSpace(indulgence.DonorEmailAddress) ? "" : indulgence.DonorEmailAddress) + @"'
        }]
    }
], 
  'reply_to': {
    'email': '" + fromAddress + @"', 
    'name': '" + fromName + @"'
  }, 
  'subject': 'Bless you! Please accept your indulgence'
}";

                Object json = JsonConvert.DeserializeObject<Object>(data);
                data = json.ToString();
                dynamic response = await sg.client.mail.send.post(requestBody: data);

                _log.InfoFormat("sent an email to " + indulgence.DonorEmailAddress);
                _log.InfoFormat("response code: {0}, result: {1}, headers: {2}",
                    response.StatusCode, response.Body.ReadAsStringAsync().Result, response.Headers.ToString());
        }
예제 #16
0
        public ActionResult BeginConfession(string confession)
        {
            // store the confession as a sin
            Indulgence indulgence = null;
            var sin = new Sin() { Content = confession, Source = "JC", Guid=Guid.NewGuid() };

            indulgence = new Indulgence()
            {
                Confession = confession.Truncate(150),
                DateConfessed = DateTime.Now,
                IsBlessed = false,
                IsConfession = true,
                Sin = sin,
                Tweeted = false,
                Name = "Anonymous",
                Guid=Guid.NewGuid(),
                BackgroundImageName = "parchment3"
            };
            _indulgeMeService.SaveIndulgence(indulgence);

            return RedirectToAction("Confess", new { guid = indulgence.Guid });
        }
        private Message BuildMessage(Indulgence indulgence)
        {
            var templateDoc = XDocument.Load(HostingEnvironment.MapPath("~/content/emailTemplates/indulgenceEmail.xml"));
            string subjectText = templateDoc.Element("email").Element("subject").Value;
            string textBody = templateDoc.Element("email").Element("body").Element("text").Value;
            string htmlBody = templateDoc.Element("email").Element("body").Element("html").Value;
            subjectText = subjectText
                .Replace("@DonorName", indulgence.Name)
                .Replace("@CharityName", indulgence.CharityName);
            textBody = textBody
                .Replace("@DonorName", indulgence.Name)
                .Replace("@CharityName", indulgence.CharityName);
            htmlBody = htmlBody
                .Replace("@DonorName", indulgence.Name)
                .Replace("@CharityName", indulgence.CharityName);

            Content subject = new Content();
            subject.Charset = "utf-8";
            subject.Data = subjectText;

            Content html = new Content();
            html.Charset="UTF-8";
            html.Data= htmlBody;

            Content text = new Content();
            text.Charset="UTF-8";
            text.Data=textBody;

            Body body = new Body();
            body.Html=html;
            body.Text=text;

            Message message = new Message();
            message.Body=body;
            message.Subject=subject;

            return message;
        }
예제 #18
0
        private static void SendTweet(Indulgence indulgence)
        {
            logger.DebugFormat("tweet {0}", indulgence.Confession);

            string status = "";
            status = string.Format("Bless you {0}, your sin has been absolved http://{1}/indulgences/{2}", indulgence.Name,
                                   ConfigurationManager.AppSettings["WebsiteUrlAuthority"], indulgence.Id);

            try
            {
                /*FluentTwitter
                    .CreateRequest()
                    .AuthenticateWith(consumerKey, consumerSecret, token, tokenSecret)
                    .Statuses()
                    .Update(status)
                    .AsJson()
                    .Request();*/
            }
            catch (Exception ex)
            {
                logger.Warn("Could not send tweet", ex);
            }
        }
예제 #19
0
 public void Tweet(Indulgence indulgence)
 {
     _tweeter.Tweet(indulgence);
 }
예제 #20
0
 public void SaveIndulgence(Indulgence indulgence)
 {
     _db.Add(indulgence);
 }
예제 #21
0
 public byte[] GetIndulgencePdf(Indulgence indulgence)
 {
     string pdfFilename = string.Format("{0}{1}.pdf", ConfigurationManager.AppSettings["IndulgencePdfRelativePath"], indulgence.Guid);
     return _fileStorage.Get(pdfFilename);
 }
예제 #22
0
 public byte[] GetIndulgenceImage(Indulgence indulgence, int size)
 {
     string imageFileName = string.Format("{0}{1}_{2}.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid, size);
     return _fileStorage.Get(imageFileName);
 }
        public Indulgence CreateIndulgenceForSin(string guid)
        {
            var sin = _session.CreateCriteria<Sin>()
                .Add(Restrictions.Eq("Guid", Guid.Parse(guid)))
                .UniqueResult<Sin>();

            var ind = new Indulgence()
            {
                Confession = sin.Content.Substring(0, sin.Content.Length <= 250 ? sin.Content.Length : 250),
                DateConfessed = DateTime.Now,
                IsBlessed = false,
                IsConfession = false,
                Sin = sin
            };
            _session.Save(ind);
            _session.Flush();
            return ind;
        }
 public void SaveIndulgence(Indulgence indulgence)
 {
     _session.Save(indulgence);
     _session.Save(indulgence.Sin);
     _session.Flush();
 }
        public void Generate(Indulgence indulgence, string fontsDirectory, string contentDirectory, string bkFilename,
            string pdfFilename, string imageThumbnailFileName_1, string imageThumbnailFileName_2,
            string imageThumbnailFileName_3, string imageThumbnailFileName_4)
        {
            string thumb1Filename = imageThumbnailFileName_1;
            string thumb2Filename = imageThumbnailFileName_2;
            string thumb3Filename = imageThumbnailFileName_3;
            string thumb4Filename = imageThumbnailFileName_4;

            Rectangle background = PageSize.LETTER.Rotate();
            background.BackgroundColor = new BaseColor(0, 0, 0, 0);
            Document doc = new Document(PageSize.LETTER.Rotate(), 20, 20, 0, 0); // 70, 70, 130, 70

            byte[] pdfData = null;
            using (var ms = new System.IO.MemoryStream())
            {
                var pdfWriter = PdfWriter.GetInstance(doc, ms);
                pdfWriter.PageEvent = new ParchmentPageEventHelper(_storage, contentDirectory, bkFilename);

                BaseFont uechiGothicBase = BaseFont.CreateFont(System.IO.Path.Combine(fontsDirectory, "UECHIGOT.ttf"),
                    BaseFont.CP1252, BaseFont.EMBEDDED);
                BaseFont trajanProBase =
                    BaseFont.CreateFont(System.IO.Path.Combine(fontsDirectory, "TrajanPro-Regular.otf"), BaseFont.CP1252,
                        BaseFont.EMBEDDED);
                Font uechiGothic = new Font(uechiGothicBase, 150, iTextSharp.text.Font.NORMAL, new BaseColor(139, 0, 0));

                Font trajanProConfession = new Font(trajanProBase, 45, iTextSharp.text.Font.BOLDITALIC,
                    new BaseColor(139, 0, 0));

                Font trajanProBoldSmall = new Font(trajanProBase, 24, Font.BOLD, new BaseColor(139, 54, 38));
                Font trajanProAttribution = new Font(trajanProBase, 24, iTextSharp.text.Font.NORMAL,
                    new BaseColor(139, 54, 38));

                doc.Open();

                var t = new PdfPTable(1);
                t.WidthPercentage = 100;
                var c = new PdfPCell();
                c.VerticalAlignment = Element.ALIGN_MIDDLE;
                c.MinimumHeight = doc.PageSize.Height - (doc.BottomMargin + doc.TopMargin);

                // confession
                Phrase firstLetterPhrase = new Phrase(indulgence.Confession.Substring(0, 1).ToUpper(), uechiGothic);
                Phrase confessionPhrase = new Phrase(indulgence.Confession.Substring(1), trajanProConfession);
                var confessionParagraph = new Paragraph(firstLetterPhrase);
                confessionParagraph.Add(confessionPhrase);
                confessionParagraph.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
                confessionParagraph.Leading = 45;

                // attribution
                List<Phrase> phrases = new List<Phrase>();
                phrases.Add(new Phrase("On this ", trajanProAttribution));
                phrases.Add(new Phrase(TextUtils.DayOfMonth(indulgence.DateConfessed), trajanProBoldSmall));
                phrases.Add(new Phrase(" day of ", trajanProAttribution));
                phrases.Add(new Phrase(string.Format("{0:MMMM}", indulgence.DateConfessed), trajanProBoldSmall));
                phrases.Add(new Phrase(" in the year of our Lord ", trajanProAttribution));
                phrases.Add(new Phrase(indulgence.DateConfessed.Year.ToString(), trajanProBoldSmall));
                phrases.Add(new Phrase(", ", trajanProAttribution));
                var attributionName = indulgence.Name;
                if (string.IsNullOrWhiteSpace(attributionName))
                {
                    attributionName = "An Anonymous Believer";
                }
                phrases.Add(new Phrase(attributionName, trajanProBoldSmall));
                phrases.Add(new Phrase(" selflessly gave the sum of ", trajanProAttribution));
                phrases.Add(new Phrase(string.Format("{0:c}", indulgence.AmountDonated), trajanProBoldSmall));
                phrases.Add(new Phrase(" to the deserving organisation ", trajanProAttribution));
                phrases.Add(new Phrase(indulgence.CharityName, trajanProBoldSmall));
                phrases.Add(new Phrase(" and received this plenary indulgence", trajanProAttribution));

                var attribution = new Paragraph();
                confessionParagraph.Add(Environment.NewLine);
                foreach (var phrase in phrases)
                    confessionParagraph.Add(phrase);
                attribution.Leading = 24;
                /*attribution.Insert(0, attributionName);
            attribution.Add(attributionDonation);
            attribution.Add(attributionTo);
            attribution.Add(attributionCharity);*/
                attribution.SpacingBefore = 30;
                c.AddElement(confessionParagraph);
                t.AddCell(c);
                doc.Add(t);

                doc.Close();
                pdfData = ms.ToArray();
            }

            _storage.Store(pdfFilename, pdfData, true);

            System.Drawing.Image img = null;
            using (MemoryStream pdfStream = new MemoryStream(pdfData))
            using (MemoryStream pngStream = new MemoryStream())
            {
                GhostscriptVersionInfo gvi =
                    new GhostscriptVersionInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"gsdll32.dll"));
                using (var rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer())
                {
                    rasterizer.Open(pdfStream, gvi, true);
                    rasterizer.EPSClip = false;
                    img = rasterizer.GetPage(96, 96, 1);
                    img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    img.Save(pngStream, ImageFormat.Png);
                    _storage.Store(thumb1Filename, pngStream.ToArray(), true);
                }
            }

            float ratio = (float)img.Height/(float)img.Width;
            SaveThumbnail(img, new SizeF(800, 800*ratio), thumb2Filename);
            SaveThumbnail(img, new SizeF(300, 300*ratio), thumb3Filename);
            SaveThumbnail(img, new SizeF(150, 150*ratio), thumb4Filename);

            // TODO: generate thumbnails as byte arrays and store to IFileStorage
        }
예제 #26
0
 public void SaveIndulgence(Indulgence indulgence)
 {
     _db.Add(indulgence);
 }
 public void GenerateIndulgence(Indulgence indulgence, string fontsDirectory, string contentDirectory)
 {
     _indulgenceGenerator.Generate(indulgence,
         fontsDirectory,
         contentDirectory,
         indulgence.BackgroundImageName,
         string.Format("{0}{1}.pdf", ConfigurationManager.AppSettings["IndulgencePdfRelativePath"],indulgence.Guid),
         string.Format("{0}{1}_1.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"],indulgence.Guid),
         string.Format("{0}{1}_2.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid),
         string.Format("{0}{1}_3.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid),
         string.Format("{0}{1}_4.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid));
 }
예제 #28
0
        public void EmailTest()
        {
            var indulgence = new Indulgence()
                                 {
                                     Name="andrew myhre",
                                     CharityName="test charity",
                                     DonorEmailAddress="*****@*****.**"
                                 };

            indulgenceEmailer.Send(indulgence, @"C:\workspace\git\BlessTheWeb\BlessTheWeb\Content\indulgences\6145.pdf");
        }
예제 #29
0
        public byte[] GetIndulgencePdf(Indulgence indulgence)
        {
            string pdfFilename = string.Format("{0}{1}.pdf", ConfigurationManager.AppSettings["IndulgencePdfRelativePath"], indulgence.Guid);

            return(_fileStorage.Get(pdfFilename));
        }
예제 #30
0
        public void Generate(Indulgence indulgence, string fontsDirectory, string contentDirectory, string bkFilename,
                             string pdfFilename, string imageThumbnailFileName_1, string imageThumbnailFileName_2,
                             string imageThumbnailFileName_3, string imageThumbnailFileName_4)
        {
            string thumb1Filename = imageThumbnailFileName_1;
            string thumb2Filename = imageThumbnailFileName_2;
            string thumb3Filename = imageThumbnailFileName_3;
            string thumb4Filename = imageThumbnailFileName_4;

            Rectangle background = PageSize.LETTER.Rotate();

            background.BackgroundColor = new BaseColor(0, 0, 0, 0);
            Document doc = new Document(PageSize.LETTER.Rotate(), 20, 20, 0, 0); // 70, 70, 130, 70

            byte[] pdfData = null;
            using (var ms = new System.IO.MemoryStream())
            {
                var pdfWriter = PdfWriter.GetInstance(doc, ms);
                pdfWriter.PageEvent = new ParchmentPageEventHelper(_storage, contentDirectory, bkFilename);

                BaseFont uechiGothicBase = BaseFont.CreateFont(System.IO.Path.Combine(fontsDirectory, "UECHIGOT.ttf"),
                                                               BaseFont.CP1252, BaseFont.EMBEDDED);
                BaseFont trajanProBase =
                    BaseFont.CreateFont(System.IO.Path.Combine(fontsDirectory, "TrajanPro-Regular.otf"), BaseFont.CP1252,
                                        BaseFont.EMBEDDED);
                Font uechiGothic = new Font(uechiGothicBase, 150, iTextSharp.text.Font.NORMAL, new BaseColor(139, 0, 0));

                Font trajanProConfession = new Font(trajanProBase, 45, iTextSharp.text.Font.BOLDITALIC,
                                                    new BaseColor(139, 0, 0));

                Font trajanProBoldSmall   = new Font(trajanProBase, 24, Font.BOLD, new BaseColor(139, 54, 38));
                Font trajanProAttribution = new Font(trajanProBase, 24, iTextSharp.text.Font.NORMAL,
                                                     new BaseColor(139, 54, 38));

                doc.Open();

                var t = new PdfPTable(1);
                t.WidthPercentage = 100;
                var c = new PdfPCell();
                c.VerticalAlignment = Element.ALIGN_MIDDLE;
                c.MinimumHeight     = doc.PageSize.Height - (doc.BottomMargin + doc.TopMargin);


                // confession
                Phrase firstLetterPhrase   = new Phrase(indulgence.Confession.Substring(0, 1).ToUpper(), uechiGothic);
                Phrase confessionPhrase    = new Phrase(indulgence.Confession.Substring(1), trajanProConfession);
                var    confessionParagraph = new Paragraph(firstLetterPhrase);
                confessionParagraph.Add(confessionPhrase);
                confessionParagraph.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
                confessionParagraph.Leading   = 45;


                // attribution
                List <Phrase> phrases = new List <Phrase>();
                phrases.Add(new Phrase("On this ", trajanProAttribution));
                phrases.Add(new Phrase(TextUtils.DayOfMonth(indulgence.DateConfessed), trajanProBoldSmall));
                phrases.Add(new Phrase(" day of ", trajanProAttribution));
                phrases.Add(new Phrase(string.Format("{0:MMMM}", indulgence.DateConfessed), trajanProBoldSmall));
                phrases.Add(new Phrase(" in the year of our Lord ", trajanProAttribution));
                phrases.Add(new Phrase(indulgence.DateConfessed.Year.ToString(), trajanProBoldSmall));
                phrases.Add(new Phrase(", ", trajanProAttribution));
                var attributionName = indulgence.Name;
                if (string.IsNullOrWhiteSpace(attributionName))
                {
                    attributionName = "An Anonymous Believer";
                }
                phrases.Add(new Phrase(attributionName, trajanProBoldSmall));
                phrases.Add(new Phrase(" selflessly gave the sum of ", trajanProAttribution));
                phrases.Add(new Phrase(string.Format("{0:c}", indulgence.AmountDonated), trajanProBoldSmall));
                phrases.Add(new Phrase(" to the deserving organisation ", trajanProAttribution));
                phrases.Add(new Phrase(indulgence.CharityName, trajanProBoldSmall));
                phrases.Add(new Phrase(" and received this plenary indulgence", trajanProAttribution));

                var attribution = new Paragraph();
                confessionParagraph.Add(Environment.NewLine);
                foreach (var phrase in phrases)
                {
                    confessionParagraph.Add(phrase);
                }
                attribution.Leading = 24;

                /*attribution.Insert(0, attributionName);
                 * attribution.Add(attributionDonation);
                 * attribution.Add(attributionTo);
                 * attribution.Add(attributionCharity);*/
                attribution.SpacingBefore = 30;
                c.AddElement(confessionParagraph);
                t.AddCell(c);
                doc.Add(t);

                doc.Close();
                pdfData = ms.ToArray();
            }

            _storage.Store(pdfFilename, pdfData, true);

            System.Drawing.Image img = null;
            using (MemoryStream pdfStream = new MemoryStream(pdfData))
                using (MemoryStream pngStream = new MemoryStream())
                {
                    GhostscriptVersionInfo gvi =
                        new GhostscriptVersionInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"gsdll32.dll"));
                    using (var rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer())
                    {
                        rasterizer.Open(pdfStream, gvi, true);
                        rasterizer.EPSClip = false;
                        img = rasterizer.GetPage(96, 96, 1);
                        img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        img.Save(pngStream, ImageFormat.Png);
                        _storage.Store(thumb1Filename, pngStream.ToArray(), true);
                    }
                }

            float ratio = (float)img.Height / (float)img.Width;

            SaveThumbnail(img, new SizeF(800, 800 * ratio), thumb2Filename);
            SaveThumbnail(img, new SizeF(300, 300 * ratio), thumb3Filename);
            SaveThumbnail(img, new SizeF(150, 150 * ratio), thumb4Filename);

            // TODO: generate thumbnails as byte arrays and store to IFileStorage
        }
예제 #31
0
 public void Tweet(Indulgence indulgence)
 {
     _tweeter.Tweet(indulgence);
 }
예제 #32
0
        public ActionResult Index(string confession)
        {
            // store the confession as a sin
            var sin = new Sin() { Content = confession, Source = "JC" };
            MvcApplication.CurrentSession.Store(sin);

            Indulgence con = new Indulgence()
            {
                Confession = confession.Truncate(150),
                DateConfessed = DateTime.Now,
                IsBlessed = false,
                IsConfession = true,
                SinId = sin.Id,
                Tweeted=false,
                Name="Anonymous"
            };
            MvcApplication.CurrentSession.Store(con);

            MvcApplication.CurrentSession.SaveChanges();

            return RedirectToAction("Confess", new {id=con.Id.IdValue()});
        }
예제 #33
0
        public byte[] GetIndulgenceImage(Indulgence indulgence, int size)
        {
            string imageFileName = string.Format("{0}{1}_{2}.png", ConfigurationManager.AppSettings["IndulgenceThumbnailRelativePath"], indulgence.Guid, size);

            return(_fileStorage.Get(imageFileName));
        }