Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection;
- namespace CSharp_Example_2
- {
- ///<summary>
- /// Summary description for Class1.
- ///</summary>
- classClass1
- {
- ///<summary>
- /// The main entry point for the application.
- ///</summary>
- [STAThread]
- staticvoid Main(string[] args)
- {
- // Instantiate a ProvidexX.Script object and initialize with the path to MAS90\Home
- using (DispatchObject pvx = new DispatchObject("ProvideX.Script"))
- {
- // Replace the text "*PATH TO MAS90\HOME*" with the correct MAS90\Home path in the line below
- pvx.InvokeMethod("Init", @"C:\_WORKING\90W420-0625\MAS90\Home");
- // Instantiate a new Session object and initialize the session
- // by setting the user, company, date and module
- using (DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session")) )
- {
- oSS.InvokeMethod("nLogon");
- oSS.InvokeMethod("nSetCompany", "ABC");
- oSS.InvokeMethod("nSetDate", "A/R", "05312006");
- oSS.InvokeMethod("nSetModule", "A/R");
- // Get the Task ID for the AR_Customer_ui program
- int TaskID = (int) oSS.InvokeMethod("nLookupTask", "SO_SalesOrder_ui");
- oSS.InvokeMethod("nSetProgram", TaskID);
- using (DispatchObject so_order = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_SalesOrder_bus", oSS.GetObject())))
- DispatchObject lines = new DispatchObject(so_order.GetProperty("oLines"));
- {
- // Setup the parameter list to be passed as reference to the GetResultSets method
- object [] getResultSetParams=newobject[] {"CustomerName$","CustomerNo$","","","","",""};
- // Call the GetResultSets to return the list of Customer numbers and names
- ar_cust_svc.InvokeMethodByRef("nGetResultSets",getResultSetParams);
- // The ProvideX SEP character is referenced by character number 352 within C#
- // Split the customer names into string array and list them in a console window
- string [] names = getResultSetParams[2].ToString().Split(System.Convert.ToChar(352));
- for (int x = 1; x < names.Length-1; x++) System.Console.WriteLine("Name " + x.ToString() + ": " + names[x]);
- }
- }
- }
- }
- }
- }
- public class DispatchObject: IDisposable {
- protected object m_object = null;
- private BindingFlags m_flgMethod = BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.InvokeMethod;
- private BindingFlags m_flgGetProperty = BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.GetProperty;
- private BindingFlags m_flgSetProperty = BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.SetProperty;
- protected DispatchObject() {}
- public DispatchObject(string sProgId) {
- m_object = Activator.CreateInstance(Type.GetTypeFromProgID(sProgId, true));
- }
- public DispatchObject(string sProgId, string sServer) {
- m_object = Activator.CreateInstance(Type.GetTypeFromProgID(sProgId, sServer, true));
- }
- public DispatchObject(Guid guid) {
- m_object = Activator.CreateInstance(Type.GetTypeFromCLSID(guid, true));
- }
- public DispatchObject(Guid guid, string sServer) {
- m_object = Activator.CreateInstance(Type.GetTypeFromCLSID(guid, sServer, true));
- }
- public DispatchObject(object o) {
- m_object = o;
- }
- ~DispatchObject() {
- Dispose();
- }
- public object InvokeMethodByRef(string sMethodName, object[] aryParams) {
- ParameterModifier[] pmods = new ParameterModifier[] {
- GetParameterModifier(aryParams.Length, true)
- };
- return m_object.GetType().InvokeMember(sMethodName, m_flgMethod, null, m_object, aryParams, pmods, null, null);
- }
- public object InvokeMethod(string sMethodName, params object[] aryParams) {
- return m_object.GetType().InvokeMember(sMethodName, m_flgMethod, null, m_object, aryParams);
- }
- public object InvokeMethod(string sMethodName, object[] aryParams, ParameterModifier[] pmods) {
- return m_object.GetType().InvokeMember(sMethodName, m_flgMethod, null, m_object, aryParams, pmods, null, null);
- }
- public object GetProperty(string sPropertyName) {
- return m_object.GetType().InvokeMember(sPropertyName, m_flgGetProperty, null, m_object, null);
- }
- public object SetProperty(string sPropertyName, object oValue) {
- return m_object.GetType().InvokeMember(sPropertyName, m_flgSetProperty, null, m_object, new object[] {
- oValue
- });
- }
- public object GetObject() {
- return m_object;
- }
- virtual public void Dispose() {
- if (m_object != null) {
- System.Runtime.InteropServices.Marshal.ReleaseComObject(m_object);
- m_object = null;
- GC.SuppressFinalize(this);
- }
- }
- public static ParameterModifier GetParameterModifier(int parameterCount, bool initialValue) {
- ParameterModifier mod = new ParameterModifier(parameterCount);
- for (int x = 0; x < parameterCount; x++) mod[x] = initialValue;
- return mod;
- }
Add Comment
Please, Sign In to add comment