Using Custom .dll's with Innovator

100% of people found this useful
Using Custom .dll's with Innovator

Filed under: [Edit Tags]

One of the things that makes Innovator so flexible is the ability to all your own code internally and externally.

Internal code is good for small code snippets and relatively simple or at least restricted methods. The ability to add complete classes via a .dll can be a very powerful tool.

Following is a description of how to create a .dll tool using Visual Studio Express for C#.

Server Side class libraries:

This is an example of a simple class in c#.

First the BOM class:

using System;

using System.Collections.Generic;

 

namespace MyNamespace

{

    public class BOM

    {

private Dictionary<string, BOMItem> m_bomItems = new Dictionary<string, BOMItem>();

 

        public BOM(){}

 

        public BOM(Dictionary<string, BOMItem> bom) {  m_bomItems = bom; }

 

        ~BOM(){}

 

        public bool addBomItem( BOMItem bomItem, out string errorText )

        {

            // attempt to find the BOMItem in the dictionary

            // the item should not be in there twice

            BOMItem bomOut = new BOMItem();

            if (m_bomItems.TryGetValue(bomItem.getItemNumber(), out bomOut) == true)

            {

                errorText = "Duplicate Item Number " + bomItem.getItemNumber( );

                return false;

            }

            else

            {

                m_bomItems.Add(bomItem.getItemNumber(), bomItem);

                errorText = "Success";

                return true;

            }

        }

 

        public BOMItem getBOMItem(string itemNumber)

        {

            BOMItem tmpBOM = new BOMItem();

            if (m_bomItems.TryGetValue(itemNumber, out tmpBOM) == true)

            {

                return tmpBOM;

            }

            else

            {

                return null;

            }

        }

 

 

    }

 

}

 

Then the BOMItem class:

using System;

using System.Collections.Generic;

 

namespace MyNamespace

{

    public class BOMItem

    {

        public BOMItem(string itemNumber, string description, int qty)

        {

            m_itemNumber = itemNumber;

            m_description = description;

            m_qty = qty;

        }

 

        public BOMItem() { }

 

        ~BOMItem() { }

 

        public string getItemNumber() { return m_itemNumber; }

 

        public string getDescription() { return m_description; }

 

        public int getQty() { return m_qty; }

 

public bool isItemNumber(string itemNumber) {return   (m_itemNumber.Equals(itemNumber)); }

 

        public bool isQty(int qty) { return (m_qty == qty); }

 

public bool isDescription(string description) { return (m_description.Equals(description)); }

 

        public bool equals(BOMItem bomItem)

        {

            bool result = true;

            result = result & isItemNumber(bomItem.getItemNumber());

            result = result & isQty(bomItem.getQty());

            result = result & isDescription(bomItem.getDescription());

            return result;

        }

 

        private string m_itemNumber;

        private string m_description;

        private int m_qty;

    }

}

 

These classes create a BOM and a BOM Item which I could re-use in any method inside Innovator.

Compile the classes into a .dll class library. (There is a lot of documentation on the web to advise how to do this in Visual Studio Express. Google "Add dll template to Visual Studio express" to see how to do this. If you have the full Visual Studio there will already be a template installed.

IMPORTANT NOTE: The class library must be strongly named so that it can be installed in the Global Assembly Cache (GAC). If it isn't strongly named the gacutil.exe tool will not install the .dll. If the .dll is not installed in the GAC Innovator will not find it.  FURTHER NOTE: I'm not sure if this is a Vista/Windows 7 security feature. I am operating on Windows 7 and found this was the only way to install the dll.

This is the method code in a server side method in Innovator:

Innovator inn = this.getInnovator();

 

Matrix.BOM bom = new Matrix.BOM();

Matrix.BOMItem bomItem = new Matrix.BOMItem("12345","An interesting description", 5);

string errorText;

if (!bom.addBomItem(bomItem, out errorText))

{

    errorText = errorText + "Add BOM Item failed <'BR'> ";          

}

 

    errorText += (bomItem.getDescription());

    errorText += (bomItem.getItemNumber());

    errorText += (bomItem.getQty());

 

Matrix.BOMItem bomItem2 = new Matrix.BOMItem("12345", "An interesting   description", 5);

    if (bomItem.equals(bomItem2))

    {

        errorText += ("Bom items are equal");

    }

    else

    {

        errorText += ("Bom items are not equal");

    }

 

 

Matrix.BOMItem bomItem3 = new Matrix.BOMItem("12346", "An interesting description", 5);

    if (bomItem.equals(bomItem3))

    {

        errorText += ("Bom items are equal");

    }

    else

    {

        errorText += ("Bom items are not equal");

    }

 

 

return inn.newResult(errorText);

In order to use this method code we need to install the .dll in the Innovator code tree and edit the method-config.xml file to include a reference to the dll.

I copied the dll into:

c:\Aras\Innovator\Innovator\Server\bin\mydll

 

I tried installing the dll directly in the /bin folder and found that adding another dll file to this directory caused an unusual error in Innovator. It would not load the "databases" into the login screen which in turn stopped you from logging on.

I put the dll file into a sub directory, mydll in this case put an entry into "method-config.xml" like:

<MethodConfig>

  <ReferencedAssemblies>

    <name>System.dll</name>

    <name>System.XML.dll</name>

    <name>System.Web.dll</name>

    <name>System.Data.dll</name>

    <name>$(binpath)/IOM.dll</name>

    <name>$(binpath)/InnovatorCore.dll</name>

    <name>$(binpath)/CoreCS.dll</name>

    <name>$(binpath)/SPConnector.dll</name>

    <name>$(binpath)/mydll/BOMTools.dll</name>

  </ReferencedAssemblies>

 "method-config.xml" is located in Aras\Innovator\Innovator\server\

Then I installed the file into the GAC using "gacutil.exe /i bomtools.dll"

 The GAC tool can be found in:

Program Files\Microsoft .NET\SDK\v2.0\Bin\gacutil.exe

Just in case it is not part of your path (and it probably isn't).

 Code example and instructions provided by Brian Pye. Information is based on my investigations into using custom classes in Innovator.

Recent Comments

By: Sagi Tikotski Posted on Sun, Jan 2 2011 3:31 AM

Brian,

Great post. Will this way of using code externally allow you to also debug the code via Visual Studio (using the "non express" version of the tool)?

If you could also debug this code in real-time - It would truly save a lot of time developing with Innovator.

Sagi

By: Brian Pye Posted on Wed, Feb 9 2011 12:45 AM

Sagi,

I haven't done this myself but it should be the same process as debugging any .dll. You need to know the process context that the .dll is running under. This is probably the .exe that runs IIS.

So open VS and go to attach process. Find the process for IIS and you should be able to debug into your dll.

The dll should probably need to have debug information anyway so you will need to build a debug version and register it.

Brian.

By: drnorthcott Posted on Mon, Apr 25 2011 11:03 PM

Having a problem with it. I get an error:

Details in 7 temporary files C:\Program Files\Aras\Innovator\Innovator\Server\dll\p4wthlbn Line number -26, Error Number: CS0009, Metadata file 'c:\Program Files\Aras\Innovator\Innovator\Server\bin\Npgsql\Mono.Security.dll' could not be opened -- 'Access is denied.' Details in 7 temporary files C:\Program Files\Aras\Innovator\Innovator\Server\dll\p4wthlbn Line number -26, Error Number: CS0009, Metadata file 'c:\Program Files\Aras\Innovator\Innovator\Server\bin\Npgsql\Mono.Security.dll' could not be opened -- 'Access is denied.'

I realized that it was simply a security issue. Right click the added dll's and see what security permissions exist. For me there are "TERMINAL SERVER USER", "Power Users", "SYSTEM" etc. Most of these have full control or at least Modify permissions. Copy an existing Innovator file into your subdirectory, highlight all the files, right click, properties and go tot he security tab. You will get a warning saying the permissions are different and click "Yes" to reset all permissions (based on the permisisons of the parent directories, files etc).

This cured it.

By: Dieter Neuhaeusler Posted on Tue, Jun 14 2011 8:58 AM

Brian,

I tried to run your example "custom dll BOM". Declared the dll as strongly named, used gacutil to register and modified the "method-config.xml".

How can I use the dll in the method editor? Is it necessary to set a using statement?

Thanks.