Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Which C# project should I use for a certain requirement?

I’ve got a request from a stakeholder who wants us to automate the following procedure.

  1. Go to the CMS website (In-house application)

  2. Take a picture of the report.

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

  3. Send an email to stakeholders with the reports attached.

Note: This procedure must be repeated on a daily basis.

And I’m not sure which project to choose for the above need; at the moment, all I can think of is a Console Application, but I’m not sure much about it.

Any assistance would be much appreciated.

Code For Screenshot – Selenium C#

  public class ScreenShotRepository
{
    public static void TakeScreenShot(IWebDriver Driver, string filename, List<string> text = null)
    {
        var bytesArr = Driver.TakeScreenshot(new VerticalCombineDecorator(new ScreenshotMaker()));
        var screenshotImage = (System.Drawing.Image)((new ImageConverter()).ConvertFrom(bytesArr));

        WriteToPDF(new List<System.Drawing.Image>() { screenshotImage }, filename, text);
    }

    public static void WriteToPDF(List<System.Drawing.Image> screenshots, string filename, List<string> text)
    {
        var fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None);
        var document = new Document(new iTextSharp.text.Rectangle(0, 0, screenshots[0].Width, screenshots[0].Height), 0, 0, 0, 0);

        var writer = PdfWriter.GetInstance(document, fileStream);

        document.Open();

        var content = writer.DirectContent;
        var font = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

        for (int i = 0; i < screenshots.Count; i++)
        {
            var image = iTextSharp.text.Image.GetInstance(screenshots[i], screenshots[i].RawFormat);

            document.Add(image);

            WriteText(content, font, text);

            if (i + 1 != screenshots.Count)
                document.NewPage();
        }
        document.Close();
        writer.Close();
    }

    public static void WriteText(PdfContentByte content, BaseFont font, List<string> text)
    {
        content.BeginText();
        content.SetColorFill(BaseColor.GREEN);
        content.SetFontAndSize(font, 40);

        for (int j = 0; j < text.Count; j++)
            content.ShowTextAligned(Element.ALIGN_LEFT, text[j].ToString(), 50, 50 + 50 * j, 0);

        content.EndText();
    }
}

>Solution :

You could make this a Windows Service, because of the daily call requirement.

However, the simplest way is indeed a console application that you schedule to run using your operating systems task scheduler.

And as far as the requirements go, why can’t the reporting system output a PDF? Taking a screenshot of another software is already a really makeshift solution if it were third-party, taking screenshots of your own reporting software just says whoever programs the inhouse CMS system is… not up to the task if there is a requirement to automate it outside of their domain.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading