Sage.Dispatch 1.7.0

dotnet add package Sage.Dispatch --version 1.7.0
NuGet\Install-Package Sage.Dispatch -Version 1.7.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sage.Dispatch" Version="1.7.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sage.Dispatch --version 1.7.0
#r "nuget: Sage.Dispatch, 1.7.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sage.Dispatch as a Cake Addin
#addin nuget:?package=Sage.Dispatch&version=1.7.0

// Install Sage.Dispatch as a Cake Tool
#tool nuget:?package=Sage.Dispatch&version=1.7.0

Sage.Dispatch

New for version 1.7.0

The following applies to ProvideX class based instances exposed through COM; e.g. returned from ProvideX.Script's NewObject() method.

Out strings

Previous handling of out string arguments required the string to be defined before use, and to have its value set to an empty string.

var companies = string.Empty;

session.nGetCompanyList(ref companies);

This can now be simplified by using out strings.

session.nGetCompanyList(out string companies);
Assertion checks

Normal error checking for a method result would look similar to the following.

const int Success = 1;

if ((int)session.nSetUser("invalid", "none") != Success) throw new ApplicationException($"Failed to set user. {session.sLastErrorMsg}");

While correct, it requires more code to be written to check for, and handle any error conditions. To simplify this, two named assertion arguments can be used to perform the error checking for you.

  • The expected named argument indicates that the method result must match the value.
  • The unexpected named argument indicates that the method result should not match the value.
const int Failure = 0;
const int Success = 1;

/* If the method result does not match the expected value an exception will be thrown */
session.nSetUser("invalid", "none", expected: Success);
/* Exception message on failure: The user logon or password does not match. */

/* If the method result matches the unexpected value an exception will be thrown */
session.nSetCompany("FOO", unexpected: Failure);
/* Exception message on failure: Company FOO is not on file. */
Full example

using Sage.Dispatch;
using System;
using System.Diagnostics;

namespace TestSageDispatch
{
   class Program
   {
       [STAThread]
       static void Main(string[] args)
       {
           const int Success = 1;
           const int Failure = 0;

           try
           {
               using (dynamic script = new ComDynamic("ProvideX.Script"))
               {
                   script.Init(@"C:\Sage\Sage 100\MAS90\Home");
                   script.Execute("SET_PARAM 'NE'=0");

                   using (dynamic session = script.NewObject("SY_Session"))
                   {
                       session.nSetUser("all", "", expected: Success);
                       session.nSetCompany("ABC", expected: Success);
                       session.nSetDate("S/O", DateTime.Today.ToString("yyyyMMdd"), expected: Success);
                       session.nSetModule("S/O", expected: Success);

                       int taskId = session.nLookupTask("SO_Invoice_ui", unexpected: 0);

                       using (dynamic security = session.oSetProgram(taskId, "SO_Invoice_ui", unexpected: 0)) { }

                       using (dynamic invoice = script.NewObject("SO_Invoice_bus", session))
                       {
                           var batchEnabled = (invoice.nBatchEnabled != 0);

                           if (batchEnabled)
                           {
                               invoice.nSelectNewBatch(out string batchNo, "N", "BOI " + DateTime.Today.ToString("MM/dd/yyyy"), expected: Success);

                               Trace.WriteLine($"Batch number : {batchNo}");
                           }

                           invoice.nGetNextInvoiceNo(out string invoiceNo, expected: Success);

                           invoice.nSetKey(invoiceNo, unexpected: Failure);
                           invoice.nSetValue("ARDivisionNo$", "01");
                           invoice.nSetValue("CustomerNo$", "ABF");

                           using (dynamic lines = invoice.oLines)
                           {
                               lines.nAddLine(unexpected: Failure);
                               lines.nSetValue("ItemCode$", "1001-HON-H252", expected: Success);
                               lines.nSetValue("QuantityOrdered", 1, expected: Success);
                               lines.nWrite(expected: Success);
                           }

                           invoice.nWrite(expected: Success);

                           Trace.WriteLine($"New invoice {invoiceNo} created...");
                       }

                       session.nCleanup(expected: null);
                   }
               }
           }
           catch (ComDynamicException exception)
           {
               Trace.WriteLine($"Error invoking {(exception.IsProperty ? "property" : "method")} {exception.MemberName}: {exception.Message}");
           }
       }
   }
}
Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.7.0 428 12/12/2022
1.5.0 409 6/30/2022
1.4.0 412 6/30/2022

New for version 1.7.0

The following applies to ProvideX class based instances exposed through COM; e.g. returned from ProvideX.Script's NewObject() method.

- Simplified handling of out strings.
- Assertion checking for method calls.