Guest User

Untitled

a guest
Jan 13th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3.  
  4. namespace CSharp_Example_2
  5. {
  6.  
  7. ///<summary>
  8. /// Summary description for Class1.
  9. ///</summary>
  10.  
  11. classClass1
  12. {
  13.  
  14. ///<summary>
  15. /// The main entry point for the application.
  16. ///</summary>
  17.  
  18. [STAThread]
  19. staticvoid Main(string[] args)
  20. {
  21.  
  22. // Instantiate a ProvidexX.Script object and initialize with the path to MAS90\Home
  23. using (DispatchObject pvx = new DispatchObject("ProvideX.Script"))
  24. {
  25.  
  26. // Replace the text "*PATH TO MAS90\HOME*" with the correct MAS90\Home path in the line below
  27. pvx.InvokeMethod("Init", @"C:\_WORKING\90W420-0625\MAS90\Home");
  28.  
  29. // Instantiate a new Session object and initialize the session
  30. // by setting the user, company, date and module
  31.  
  32. using (DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session")) )
  33. {
  34.  
  35. oSS.InvokeMethod("nLogon");
  36. oSS.InvokeMethod("nSetCompany", "ABC");
  37. oSS.InvokeMethod("nSetDate", "A/R", "05312006");
  38. oSS.InvokeMethod("nSetModule", "A/R");
  39.  
  40. // Get the Task ID for the AR_Customer_ui program
  41. int TaskID = (int) oSS.InvokeMethod("nLookupTask", "SO_SalesOrder_ui");
  42. oSS.InvokeMethod("nSetProgram", TaskID);
  43.  
  44. using (DispatchObject so_order = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_SalesOrder_bus", oSS.GetObject())))
  45. DispatchObject lines = new DispatchObject(so_order.GetProperty("oLines"));
  46. {
  47.  
  48. // Setup the parameter list to be passed as reference to the GetResultSets method
  49. object [] getResultSetParams=newobject[] {"CustomerName$","CustomerNo$","","","","",""};
  50.  
  51. // Call the GetResultSets to return the list of Customer numbers and names
  52. ar_cust_svc.InvokeMethodByRef("nGetResultSets",getResultSetParams);
  53.  
  54. // The ProvideX SEP character is referenced by character number 352 within C#
  55. // Split the customer names into string array and list them in a console window
  56. string [] names = getResultSetParams[2].ToString().Split(System.Convert.ToChar(352));
  57. for (int x = 1; x < names.Length-1; x++) System.Console.WriteLine("Name " + x.ToString() + ": " + names[x]);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64.  
  65.  
  66. public class DispatchObject: IDisposable {
  67. protected object m_object = null;
  68.  
  69. private BindingFlags m_flgMethod = BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.InvokeMethod;
  70. private BindingFlags m_flgGetProperty = BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.GetProperty;
  71. private BindingFlags m_flgSetProperty = BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.SetProperty;
  72.  
  73. protected DispatchObject() {}
  74.  
  75. public DispatchObject(string sProgId) {
  76. m_object = Activator.CreateInstance(Type.GetTypeFromProgID(sProgId, true));
  77. }
  78.  
  79. public DispatchObject(string sProgId, string sServer) {
  80. m_object = Activator.CreateInstance(Type.GetTypeFromProgID(sProgId, sServer, true));
  81. }
  82.  
  83. public DispatchObject(Guid guid) {
  84. m_object = Activator.CreateInstance(Type.GetTypeFromCLSID(guid, true));
  85. }
  86.  
  87. public DispatchObject(Guid guid, string sServer) {
  88. m_object = Activator.CreateInstance(Type.GetTypeFromCLSID(guid, sServer, true));
  89. }
  90.  
  91. public DispatchObject(object o) {
  92. m_object = o;
  93. }
  94.  
  95. ~DispatchObject() {
  96. Dispose();
  97. }
  98.  
  99. public object InvokeMethodByRef(string sMethodName, object[] aryParams) {
  100. ParameterModifier[] pmods = new ParameterModifier[] {
  101. GetParameterModifier(aryParams.Length, true)
  102. };
  103. return m_object.GetType().InvokeMember(sMethodName, m_flgMethod, null, m_object, aryParams, pmods, null, null);
  104. }
  105.  
  106. public object InvokeMethod(string sMethodName, params object[] aryParams) {
  107. return m_object.GetType().InvokeMember(sMethodName, m_flgMethod, null, m_object, aryParams);
  108. }
  109.  
  110. public object InvokeMethod(string sMethodName, object[] aryParams, ParameterModifier[] pmods) {
  111. return m_object.GetType().InvokeMember(sMethodName, m_flgMethod, null, m_object, aryParams, pmods, null, null);
  112. }
  113.  
  114. public object GetProperty(string sPropertyName) {
  115. return m_object.GetType().InvokeMember(sPropertyName, m_flgGetProperty, null, m_object, null);
  116. }
  117.  
  118. public object SetProperty(string sPropertyName, object oValue) {
  119. return m_object.GetType().InvokeMember(sPropertyName, m_flgSetProperty, null, m_object, new object[] {
  120. oValue
  121. });
  122. }
  123.  
  124. public object GetObject() {
  125. return m_object;
  126. }
  127.  
  128. virtual public void Dispose() {
  129. if (m_object != null) {
  130. System.Runtime.InteropServices.Marshal.ReleaseComObject(m_object);
  131. m_object = null;
  132. GC.SuppressFinalize(this);
  133. }
  134. }
  135.  
  136. public static ParameterModifier GetParameterModifier(int parameterCount, bool initialValue) {
  137. ParameterModifier mod = new ParameterModifier(parameterCount);
  138. for (int x = 0; x < parameterCount; x++) mod[x] = initialValue;
  139. return mod;
  140. }
Add Comment
Please, Sign In to add comment