another technical blog...technically

Monday, April 2, 2018

A Blue Prism project with custom DLLs: 4 dummies

It seems this blog post was found really interesting from lot of you, but i also read a lot of comments about how can you set up a project and use DLL with BP, so i will show you a practical and really simple example.
Here below the code of the DLL i will use, just two classes:
  1. Log Helper: write something in the event viewer (could be useful for bug hunting)
  2. Program: the typical entry point for every .NET console application
LogHelper.cs
using System;
using System.Diagnostics;

namespace BP.ExternalDll.Example
{
    public class LogHelper
    {
        private readonly string _log;
        private readonly string _source;

        public LogHelper(string source, string log)
        {
            _source = source;
            _log = log;
        }
        
        public void LogWarning(string message)
        {
            try
            {
                CreateEventSource();
                EventLog.WriteEntry(_source, message, EventLogEntryType.Warning);
            }
            catch (Exception)
            {
                // ignored
                // If you're here, it means you cannot write on event registry
            }
        }
        
        private void CreateEventSource()
        {
            if (!EventLog.SourceExists(_source))
            {
                EventLog.CreateEventSource(_source, _log);
            }
        }
    }
}
Program.cs
namespace BP.ExternalDll.Example
{
    public class Program
    {
        public static void Log()
        {
            string currentDirectory = System.Environment.CurrentDirectory;
            LogHelper _helper = new LogHelper("BP.ExternalDll.Example", "Test library");
            _helper.LogWarning(currentDirectory);
        }

        static void Main(string[] args)
        {
            Log();
        }
    }
}
So, compile everything and place your brand new DLL in this folder: C:\Program Files\Blue Prism Limited\Blue Prism Automate .
Don't try to put the file in other folders in your PC or organize the BP folder with subfolders: it will not work and don't argue with me that BP offers this functionality, IT DOESN'T WORK.
I said: IT DOESN'T WORK
I've figured out with Antonio Durante how to overcome this problem but I think i will try this in the next future.
In the code block you just have to write:
Program.Log()
and you will start to find some new rows in your event viewer. It's clear that this is just a little example, you can complicate the things as you wish.
My advice is to create always a BusinessDelegate class that holds all the methods you want to expose and create a single VBO action for every method in the BP, this will enhance testability and maintenance. That's all folks!


written in: Milano MI, Italia

2 comments:

  1. How custom classes can be passed to other stages in Blueprism?

    ReplyDelete
    Replies
    1. Hi Anil, this is a good point.
      I think you need to hide the class complexity and create a stateless helper to manipulate your classes.
      BP should not be aware of classes.

      Best regards

      Delete

Because of a lot of SPAM about courses, I need to moderate all comments here.
I ensure you that I will answer whenever possible (if you are not a spammer).

Me, myself and I

My Photo
I'm just another IT guy sharing his knowledge with all of you out there.
Wanna know more?