Pages

Tuesday, January 24, 2012

Company Visualizer is updated

I have updated the company visualizer, fixing the issue I had about database lookup.

Orginal post.

Tuesday, January 17, 2012

Test target in unit tests

When you set the SysTestTargetAttribute in a unit test case class, you should take care in assuring the validity of the attribute. There are no warnings or errors if you point to an element that does not exist.

If you run unit tests with code coverage, your test will be unresponsive for longer than expected. This is because the code coverage is calculated against the entire AOT if the element from SysTestTargetAttribute doesn't exist.

Click here, for the MSDN section on AX 2012 unit tests.

Wednesday, January 11, 2012

FTP with C#

A couple of links with information on how to work with a FTP server from C#:


I have used this information to write a specific FTP client class in a Visual Studio assembly in AX.

AIF: Execute messages on demand

Sometimes when you try to debug problems with an AIF message, you'd like to just execute it rather than wait for the batch server to pick it up.

This job can do just that. It requires the GUID of the message and a call to \Classes\AifInboundProcessingService\processAsUser:
static void debugAIF(Args _args)
{
    AifMessageId    messageId = str2guid("8D2D6B9C-B0A9-48FA-B58E-0CAAD415E65B");

    AifInboundProcessingService::processAsUser([messageID]);
}

Spelling issue with the LogisticsAddresssCity table

If you need to use the LogisticsAddresssCity table, the editor's intellisense feature will quickly enough offer you the LogisticsAddressCity option.

But beware; this is the extended data type LogisticsAddressCity, which the icon and the tooltip correctly enough indicates.

The table though has the addressing part of its name spelled with three s'es: LogisticsAddresssCity. So you'll find that quite a long way further down in the intellisense dropdown.

That nearly made me insane yesterday, until my eyes crossed the third s of the table name.

Sample file import with StreamReader

Here is one example of how you can import files with .NET's StreamReader:
static void ImportWithStreamReader(Args _args)
{
    Filename                filename = @'C:\Temp\importme.txt';           
    System.IO.StreamReader  reader;
    System.String           line;
    InteropPermission       interopPermission;
   
    interopPermission = new InteropPermission(InteropKind::ClrInterop);
    interopPermission.assert();

    reader = new System.IO.StreamReader(filename, 
                                       System.Text.Encoding::get_UTF8());

    line = reader.ReadLine();

    while (!System.String::IsNullOrEmpty(line))
    {
        // Do something with line

        line = reader.ReadLine();
    }

    reader.Close();
    reader.Dispose();
}
If you can work with the file as on big chunk of text you can get away with just reading once, using the ReadToEnd method.

Read more about StreamReader on MSDN.