Sep
13
2011

EPDM: Using IEdmDictionary5 for Configuration

I normally use config (xml) files for my EPDM add-in configuration, however, there are a couple of issues with them.

  1. One needs to remember to add the configuration file when adding the add-in.
  2. Security is at risk as passwords are readable by anyone who knows where to look for them if they are stored in the configuration file. In the past I have included an encryption utility to get around this but it’s another step to take.

With this in mind I began to think of another method of storing add-in settings and decided upon IEdmDictionary5. The IEdmDictionary5 interface provides methods to store key-value pairs in the vault database.  The advantage of using the database is that it can be updated at anytime and all a user needs to do to see the new configuration is log out and log back in again. There is no configuration file to change.

So how does one configure and edit a dictionary?

EPDM Dictionary Editor

I wrote this small app to edit dictionaries in the vault.

DictionaryEditor

It’s pretty simple. Login to the vault, enter your dictionary name, and press load. It will load up the stored values. To save them, press save.

The ‘From File’ button will allow you to select your .dll containing your configuration class. Once you’ve selected the file, choose the appropriate class from the drop down menu and press the
’Get properties’ button to load the classes properties into the grid.

Using Reflection to Access Properties

The bonus of using a configuration class is that one can use reflection to set and get settings pretty easily.

public class Configuration
  {
      /// 
      /// The username to connect to the OpenERP database with.
      /// 
      public string OpenERPUsername { get; set; }
      /// 
      /// The password to connect to the OpenERP database with.
      /// 
      public string OpenERPPassword { get; set; }
      /// 
      /// The OpenERP database to connect to
      /// 
      public string OpenERPDatabase { get; set; }
      /// 
      /// The OpenERP host/server hosting the database. IP or DNS name.
      /// 
      public string OpenERPHost { get; set; }
      /// 
      /// The OpenERP host/server port.
      ///         
      public int OpenERPHostPort { get; set; }

      public bool LoadConfiguration(EdmLib.IEdmVault5 vault)
      {
          // load the assembly name from this dll
          Assembly assy = Assembly.GetExecutingAssembly();       
          string assemblyName = assy.GetName().Name;
          EdmLib.IEdmDictionary5 dictionary = vault.GetDictionary(assemblyName, false);

          if (dictionary != null)
          {
              //get all the properties of the configuration class
              PropertyInfo[] props = this.GetType().GetProperties();
              foreach (var property in props)
              {
                  string value;
                  try
                  {
                      if (dictionary.StringGetAt(property.Name, out value))
                          property.SetValue(this, Convert.ChangeType(value, property.PropertyType), null);
                  }
                  catch (Exception ex)
                  {
                      System.Windows.Forms.MessageBox.Show(
                          String.Format("There was an error setting the property {0}.\r\n\r\n{1}",
                          property.Name, ex.Message), "Property Error!",
                          System.Windows.Forms.MessageBoxButtons.OK, 
                          System.Windows.Forms.MessageBoxIcon.Exclamation);
                      return false;
                  }
              }
              return true;
          }
          return false;
      }
  }

Now all one needs to load up the configuration are a couple of lines of code:

Configuration config = new Configuration();
bool configLoaded = config.LoadConfiguration(vault);

This should be straight forward and hopefully someone finds it useful!

EPDMDictionaryStore.zip (75.07 kb)

Jun
16
2011

EPDM: Add and update xTuple item

Here is a little addin that will add and update items in xTuple. I won't post much about it and I won't support it as I am not using xTuple any longer. I just figured someone out there might be able to use it.

You'll need to edit the config file if you do use it. (Use it at your own risk.)

EPDMxTupleAddin.rar (826.71 kb)

Feb
17
2011

EPDM: Print to PDF Task Addin

At the request of a few people, I have created an add-in for EPDM that prints files to PDF. The addin sends the file to a PDF printer (Bullzip PDF), prints it, adds it to the vault, and checks it in. The beauty of the addin is that it should work with any application. (Besides SolidWorks because of the way it handles print.)

Installation instructions:

  • Using the administration tool, right click on Add-ins and select new add-in.
  • Browse to the directory containing the add-in you wish to add and select all the files relevant to the add-in. In this case, EPDM.Utils.dll, EPDMPrintToPDFTaskAddin.dll, and Interop.EdmLib.dll.
  • Right click on Tasks in the administration tool and select 'New Task'.
  • Select EPDMPrintToPDFTaskAddin in the Add-in combobox.
  • Select the computers that will support the task. If you haven't set up Task Host Configuration, select Task Host Configuration from the EPDM icon in the notification area. Once done, press the Refresh List button in the addin setup page. Press next.
  • Enter your Bullzip PDF Printer name and enter the path to save the PDFs in.
  • Press OK.
  • Now, either setup your workflow to add the task to a transition, or right click on a file and select Print to Bullzip PDF.
  • That's it!

Give it a try. If you find it useful, please consider sending a small donation.

Update

The add-in now allows one to save PDFs outside the vault.

EPDMPrintToPDF_ver40.zip (90.47 kb)

RecentPosts