Hi,
With my another addition to the series of blog’s, this time I am trying to leverage the .NET potential with Jedox. In this post I will be writing a custom .NET dll, and utilizing it in the Jedox Macro.
Solution:
Step 1: Create a “Class Library” C# project in your Visual Studio, remember to switch to the .NET version to 3.5 as the PHP likes it more, than version 4 and beyond. (Also remember, when you fire up your Visual Studio, Run it as Administrator)
Step 2: For you project generate a signing key which is require for you dll to be put into GAC (Global Assembly Cache, a .NET store for global library referencing This is the place where PHP will be looking for your dll)
Step 3: Navigate to your “AssemblyInfo.cs” file in your project, and change the following line, making your assembly as “ComVisible”.
// Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(true)]
Step 4: Now you are ready to jot down your .NET functionality, in your class file.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DotNetToJedox { public class JedoxInDotNet { public string GetData(string message) { return "Message:" + message; } } }
Step 5: Fire your “Command Prompt” as an admin, and run the following command:
C:\>gacutil -i “<<Path to your dll>>\DotNetToJedox.dll”
Note: In case if you command prompt suggest that it cant find gacutil, just add the relevant refrence account to your OS, for the path:
C:\Program Files\Microsoft SDKs\Windows\v6.0A
The following post can help you further on that:
http://stackoverflow.com/questions/3397479/where-is-gacutil-exe
The above will add your dll in your machine GAC, which is now ready for your PHP/Jedox installation to utilize.
You can check the physical assembly being present in GAC by navigating to the following path and confirming:
C:\Windows\assembly
Step 6: Now its time to write some PHP Macro for Jedox to utilize our dll, So the code in one of the spreadsheets is as follows:
function test_dotnet(){ $sampleClass = new DOTNET("DotNetToJedox, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9fd42dd22c7fef0d, processorArchitecture=MSIL", "DotNetToJedox.JedoxInDotNet"); return __msgbox($sampleClass->GetData('Get me the message !!') , 'Dot Net To Jedox'); }
And the result is :
Note: This mechanism will work on single machine as GAC is system wide only. So if you need a .NET library functionality for you application, it has to be GAC deployed on the server where Jedox is installed.
Hope it helps !!
Downloads: